cmLocalGenerator.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <iosfwd>
  6. #include <map>
  7. #include <memory>
  8. #include <set>
  9. #include <string>
  10. #include <unordered_map>
  11. #include <vector>
  12. #include <cm3p/kwiml/int.h>
  13. #include "cmCustomCommandTypes.h"
  14. #include "cmListFileCache.h"
  15. #include "cmMessageType.h"
  16. #include "cmOutputConverter.h"
  17. #include "cmPolicies.h"
  18. #include "cmProperty.h"
  19. #include "cmStateSnapshot.h"
  20. class cmCompiledGeneratorExpression;
  21. class cmComputeLinkInformation;
  22. class cmCustomCommand;
  23. class cmCustomCommandGenerator;
  24. class cmCustomCommandLines;
  25. class cmGeneratorTarget;
  26. class cmGlobalGenerator;
  27. class cmImplicitDependsList;
  28. class cmLinkLineComputer;
  29. class cmMakefile;
  30. class cmRulePlaceholderExpander;
  31. class cmSourceFile;
  32. class cmState;
  33. class cmTarget;
  34. class cmake;
  35. /** Flag if byproducts shall also be considered. */
  36. enum class cmSourceOutputKind
  37. {
  38. OutputOnly,
  39. OutputOrByproduct
  40. };
  41. /** What scanner to use for dependencies lookup. */
  42. enum class cmDependencyScannerKind
  43. {
  44. CMake,
  45. Compiler
  46. };
  47. /** Target and source file which have a specific output. */
  48. struct cmSourcesWithOutput
  49. {
  50. /** Target with byproduct. */
  51. cmTarget* Target = nullptr;
  52. /** Source file with output or byproduct. */
  53. cmSourceFile* Source = nullptr;
  54. bool SourceIsByproduct = false;
  55. };
  56. /** \class cmLocalGenerator
  57. * \brief Create required build files for a directory.
  58. *
  59. * Subclasses of this abstract class generate makefiles, DSP, etc for various
  60. * platforms. This class should never be constructed directly. A
  61. * GlobalGenerator will create it and invoke the appropriate commands on it.
  62. */
  63. class cmLocalGenerator : public cmOutputConverter
  64. {
  65. public:
  66. cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile);
  67. virtual ~cmLocalGenerator();
  68. /**
  69. * Generate the makefile for this directory.
  70. */
  71. virtual void Generate() {}
  72. virtual void ComputeHomeRelativeOutputPath() {}
  73. /**
  74. * Calls TraceVSDependencies() on all targets of this generator.
  75. */
  76. void TraceDependencies() const;
  77. virtual void AddHelperCommands() {}
  78. /**
  79. * Generate the install rules files in this directory.
  80. */
  81. void GenerateInstallRules();
  82. /**
  83. * Generate the test files for tests.
  84. */
  85. void GenerateTestFiles();
  86. /**
  87. * Generate a manifest of target files that will be built.
  88. */
  89. void ComputeTargetManifest();
  90. bool ComputeTargetCompileFeatures();
  91. bool IsRootMakefile() const;
  92. //! Get the makefile for this generator
  93. cmMakefile* GetMakefile() { return this->Makefile; }
  94. //! Get the makefile for this generator, const version
  95. const cmMakefile* GetMakefile() const { return this->Makefile; }
  96. //! Get the GlobalGenerator this is associated with
  97. cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; }
  98. const cmGlobalGenerator* GetGlobalGenerator() const
  99. {
  100. return this->GlobalGenerator;
  101. }
  102. virtual cmRulePlaceholderExpander* CreateRulePlaceholderExpander() const;
  103. std::string GetLinkLibsCMP0065(std::string const& linkLanguage,
  104. cmGeneratorTarget& tgt) const;
  105. cmState* GetState() const;
  106. cmStateSnapshot GetStateSnapshot() const;
  107. void AddArchitectureFlags(std::string& flags,
  108. cmGeneratorTarget const* target,
  109. const std::string& lang, const std::string& config,
  110. const std::string& filterArch = std::string());
  111. void AddLanguageFlags(std::string& flags, cmGeneratorTarget const* target,
  112. const std::string& lang, const std::string& config);
  113. void AddLanguageFlagsForLinking(std::string& flags,
  114. cmGeneratorTarget const* target,
  115. const std::string& lang,
  116. const std::string& config);
  117. void AddCMP0018Flags(std::string& flags, cmGeneratorTarget const* target,
  118. std::string const& lang, const std::string& config);
  119. void AddVisibilityPresetFlags(std::string& flags,
  120. cmGeneratorTarget const* target,
  121. const std::string& lang);
  122. void AddConfigVariableFlags(std::string& flags, const std::string& var,
  123. const std::string& config);
  124. void AddCompilerRequirementFlag(std::string& flags,
  125. cmGeneratorTarget const* target,
  126. const std::string& lang,
  127. const std::string& config);
  128. //! Append flags to a string.
  129. virtual void AppendFlags(std::string& flags,
  130. const std::string& newFlags) const;
  131. virtual void AppendFlags(std::string& flags,
  132. const std::vector<BT<std::string>>& newFlags) const;
  133. virtual void AppendFlagEscape(std::string& flags,
  134. const std::string& rawFlag) const;
  135. void AddISPCDependencies(cmGeneratorTarget* target);
  136. void AddPchDependencies(cmGeneratorTarget* target);
  137. void AddUnityBuild(cmGeneratorTarget* target);
  138. void AppendIPOLinkerFlags(std::string& flags, cmGeneratorTarget* target,
  139. const std::string& config,
  140. const std::string& lang);
  141. void AppendPositionIndependentLinkerFlags(std::string& flags,
  142. cmGeneratorTarget* target,
  143. const std::string& config,
  144. const std::string& lang);
  145. //! Get the include flags for the current makefile and language
  146. std::string GetIncludeFlags(const std::vector<std::string>& includes,
  147. cmGeneratorTarget* target,
  148. const std::string& lang,
  149. bool forceFullPaths = false,
  150. bool forResponseFile = false,
  151. const std::string& config = "");
  152. using GeneratorTargetVector =
  153. std::vector<std::unique_ptr<cmGeneratorTarget>>;
  154. const GeneratorTargetVector& GetGeneratorTargets() const
  155. {
  156. return this->GeneratorTargets;
  157. }
  158. void AddGeneratorTarget(std::unique_ptr<cmGeneratorTarget> gt);
  159. void AddImportedGeneratorTarget(cmGeneratorTarget* gt);
  160. void AddOwnedImportedGeneratorTarget(std::unique_ptr<cmGeneratorTarget> gt);
  161. cmGeneratorTarget* FindLocalNonAliasGeneratorTarget(
  162. const std::string& name) const;
  163. cmGeneratorTarget* FindGeneratorTargetToUse(const std::string& name) const;
  164. /**
  165. * Process a list of include directories
  166. */
  167. void AppendIncludeDirectories(std::vector<std::string>& includes,
  168. std::string const& includes_list,
  169. const cmSourceFile& sourceFile) const;
  170. void AppendIncludeDirectories(std::vector<std::string>& includes,
  171. const std::vector<std::string>& includes_vec,
  172. const cmSourceFile& sourceFile) const;
  173. /**
  174. * Encode a list of preprocessor definitions for the compiler
  175. * command line.
  176. */
  177. void AppendDefines(std::set<std::string>& defines,
  178. std::string const& defines_list) const;
  179. void AppendDefines(std::set<BT<std::string>>& defines,
  180. std::string const& defines_list) const;
  181. void AppendDefines(std::set<BT<std::string>>& defines,
  182. const std::vector<BT<std::string>>& defines_vec) const;
  183. /**
  184. * Encode a list of compile options for the compiler
  185. * command line.
  186. */
  187. void AppendCompileOptions(std::string& options,
  188. std::string const& options_list,
  189. const char* regex = nullptr) const;
  190. void AppendCompileOptions(std::string& options,
  191. const std::vector<std::string>& options_vec,
  192. const char* regex = nullptr) const;
  193. void AppendCompileOptions(std::vector<BT<std::string>>& options,
  194. const std::vector<BT<std::string>>& options_vec,
  195. const char* regex = nullptr) const;
  196. /**
  197. * Join a set of defines into a definesString with a space separator.
  198. */
  199. void JoinDefines(const std::set<std::string>& defines,
  200. std::string& definesString, const std::string& lang);
  201. /** Lookup and append options associated with a particular feature. */
  202. void AppendFeatureOptions(std::string& flags, const std::string& lang,
  203. const char* feature);
  204. cmProp GetFeature(const std::string& feature, const std::string& config);
  205. /** \brief Get absolute path to dependency \a name
  206. *
  207. * Translate a dependency as given in CMake code to the name to
  208. * appear in a generated build file.
  209. * - If \a name is a utility target, returns false.
  210. * - If \a name is a CMake target, it will be transformed to the real output
  211. * location of that target for the given configuration.
  212. * - If \a name is the full path to a file, it will be returned.
  213. * - Otherwise \a name is treated as a relative path with respect to
  214. * the source directory of this generator. This should only be
  215. * used for dependencies of custom commands.
  216. */
  217. bool GetRealDependency(const std::string& name, const std::string& config,
  218. std::string& dep);
  219. virtual std::string ConvertToIncludeReference(
  220. std::string const& path,
  221. cmOutputConverter::OutputFormat format = cmOutputConverter::SHELL,
  222. bool forceFullPaths = false);
  223. /** Called from command-line hook to clear dependencies. */
  224. virtual void ClearDependencies(cmMakefile* /* mf */, bool /* verbose */) {}
  225. /** Called from command-line hook to update dependencies. */
  226. virtual bool UpdateDependencies(const std::string& /* tgtInfo */,
  227. bool /*verbose*/, bool /*color*/)
  228. {
  229. return true;
  230. }
  231. /** @brief Get the include directories for the current makefile and language
  232. * and optional the compiler implicit include directories.
  233. *
  234. * @arg stripImplicitDirs Strip all directories found in
  235. * CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES from the result.
  236. * @arg appendAllImplicitDirs Append all directories found in
  237. * CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES to the result.
  238. */
  239. std::vector<BT<std::string>> GetIncludeDirectoriesImplicit(
  240. cmGeneratorTarget const* target, std::string const& lang = "C",
  241. std::string const& config = "", bool stripImplicitDirs = true,
  242. bool appendAllImplicitDirs = false) const;
  243. /** @brief Get the include directories for the current makefile and language
  244. * and optional the compiler implicit include directories.
  245. *
  246. * @arg dirs Directories are appended to this list
  247. */
  248. void GetIncludeDirectoriesImplicit(std::vector<std::string>& dirs,
  249. cmGeneratorTarget const* target,
  250. const std::string& lang = "C",
  251. const std::string& config = "",
  252. bool stripImplicitDirs = true,
  253. bool appendAllImplicitDirs = false) const;
  254. /** @brief Get the include directories for the current makefile and language.
  255. * @arg dirs Include directories are appended to this list
  256. */
  257. void GetIncludeDirectories(std::vector<std::string>& dirs,
  258. cmGeneratorTarget const* target,
  259. const std::string& lang = "C",
  260. const std::string& config = "") const;
  261. /** @brief Get the include directories for the current makefile and language.
  262. * @return The include directory list
  263. */
  264. std::vector<BT<std::string>> GetIncludeDirectories(
  265. cmGeneratorTarget const* target, std::string const& lang = "C",
  266. std::string const& config = "") const;
  267. void AddCompileOptions(std::string& flags, cmGeneratorTarget* target,
  268. const std::string& lang, const std::string& config);
  269. void AddCompileOptions(std::vector<BT<std::string>>& flags,
  270. cmGeneratorTarget* target, const std::string& lang,
  271. const std::string& config);
  272. /**
  273. * Add a custom PRE_BUILD, PRE_LINK, or POST_BUILD command to a target.
  274. */
  275. cmTarget* AddCustomCommandToTarget(
  276. const std::string& target, const std::vector<std::string>& byproducts,
  277. const std::vector<std::string>& depends,
  278. const cmCustomCommandLines& commandLines, cmCustomCommandType type,
  279. const char* comment, const char* workingDir, bool escapeOldStyle = true,
  280. bool uses_terminal = false, const std::string& depfile = "",
  281. const std::string& job_pool = "", bool command_expand_lists = false,
  282. cmObjectLibraryCommands objLibCommands = cmObjectLibraryCommands::Reject,
  283. bool stdPipesUTF8 = false);
  284. /**
  285. * Add a custom command to a source file.
  286. */
  287. cmSourceFile* AddCustomCommandToOutput(
  288. const std::string& output, const std::vector<std::string>& depends,
  289. const std::string& main_dependency,
  290. const cmCustomCommandLines& commandLines, const char* comment,
  291. const char* workingDir, bool replace = false, bool escapeOldStyle = true,
  292. bool uses_terminal = false, bool command_expand_lists = false,
  293. const std::string& depfile = "", const std::string& job_pool = "",
  294. bool stdPipesUTF8 = false);
  295. cmSourceFile* AddCustomCommandToOutput(
  296. const std::vector<std::string>& outputs,
  297. const std::vector<std::string>& byproducts,
  298. const std::vector<std::string>& depends,
  299. const std::string& main_dependency,
  300. const cmImplicitDependsList& implicit_depends,
  301. const cmCustomCommandLines& commandLines, const char* comment,
  302. const char* workingDir, bool replace = false, bool escapeOldStyle = true,
  303. bool uses_terminal = false, bool command_expand_lists = false,
  304. const std::string& depfile = "", const std::string& job_pool = "",
  305. bool stdPipesUTF8 = false);
  306. /**
  307. * Add a utility to the build. A utility target is a command that is run
  308. * every time the target is built.
  309. */
  310. cmTarget* AddUtilityCommand(
  311. const std::string& utilityName, bool excludeFromAll,
  312. const char* workingDir, const std::vector<std::string>& byproducts,
  313. const std::vector<std::string>& depends,
  314. const cmCustomCommandLines& commandLines, bool escapeOldStyle = true,
  315. const char* comment = nullptr, bool uses_terminal = false,
  316. bool command_expand_lists = false, const std::string& job_pool = "",
  317. bool stdPipesUTF8 = false);
  318. virtual std::vector<cmCustomCommandGenerator> MakeCustomCommandGenerators(
  319. cmCustomCommand const& cc, std::string const& config);
  320. std::vector<std::string> ExpandCustomCommandOutputPaths(
  321. cmCompiledGeneratorExpression const& cge, std::string const& config);
  322. std::vector<std::string> ExpandCustomCommandOutputGenex(
  323. std::string const& o, cmListFileBacktrace const& bt);
  324. /**
  325. * Add target byproducts.
  326. */
  327. void AddTargetByproducts(cmTarget* target,
  328. const std::vector<std::string>& byproducts,
  329. cmListFileBacktrace const& bt,
  330. cmCommandOrigin origin);
  331. enum class OutputRole
  332. {
  333. Primary,
  334. Byproduct,
  335. };
  336. /**
  337. * Add source file outputs.
  338. */
  339. void AddSourceOutputs(cmSourceFile* source,
  340. std::vector<std::string> const& outputs,
  341. OutputRole role, cmListFileBacktrace const& bt,
  342. cmCommandOrigin origin);
  343. /**
  344. * Return the target if the provided source name is a byproduct of a utility
  345. * target or a PRE_BUILD, PRE_LINK, or POST_BUILD command.
  346. * Return the source file which has the provided source name as output.
  347. */
  348. cmSourcesWithOutput GetSourcesWithOutput(const std::string& name) const;
  349. /**
  350. * Is there a source file that has the provided source name as an output?
  351. * If so then return it.
  352. */
  353. cmSourceFile* GetSourceFileWithOutput(
  354. const std::string& name,
  355. cmSourceOutputKind kind = cmSourceOutputKind::OutputOnly) const;
  356. std::string GetProjectName() const;
  357. /** Compute the language used to compile the given source file. */
  358. std::string GetSourceFileLanguage(const cmSourceFile& source);
  359. // Fill the vector with the target names for the object files,
  360. // preprocessed files and assembly files.
  361. void GetIndividualFileTargets(std::vector<std::string>&) {}
  362. /**
  363. * Get the relative path from the generator output directory to a
  364. * per-target support directory.
  365. */
  366. virtual std::string GetTargetDirectory(
  367. cmGeneratorTarget const* target) const;
  368. /**
  369. * Get the level of backwards compatibility requested by the project
  370. * in this directory. This is the value of the CMake variable
  371. * CMAKE_BACKWARDS_COMPATIBILITY whose format is
  372. * "major.minor[.patch]". The returned integer is encoded as
  373. *
  374. * CMake_VERSION_ENCODE(major, minor, patch)
  375. *
  376. * and is monotonically increasing with the CMake version.
  377. */
  378. KWIML_INT_uint64_t GetBackwardsCompatibility();
  379. /**
  380. * Test whether compatibility is set to a given version or lower.
  381. */
  382. bool NeedBackwardsCompatibility_2_4();
  383. cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const;
  384. cmake* GetCMakeInstance() const;
  385. std::string const& GetSourceDirectory() const;
  386. std::string const& GetBinaryDirectory() const;
  387. std::string const& GetCurrentBinaryDirectory() const;
  388. std::string const& GetCurrentSourceDirectory() const;
  389. /**
  390. * Convert the given remote path to a relative path with respect to
  391. * the given local path. Both paths must use forward slashes and not
  392. * already be escaped or quoted.
  393. * The conversion is skipped if the paths are not both in the source
  394. * or both in the binary tree.
  395. */
  396. std::string MaybeConvertToRelativePath(std::string const& local_path,
  397. std::string const& remote_path) const;
  398. /**
  399. * Generate a macOS application bundle Info.plist file.
  400. */
  401. void GenerateAppleInfoPList(cmGeneratorTarget* target,
  402. const std::string& targetName,
  403. const std::string& fname);
  404. /**
  405. * Generate a macOS framework Info.plist file.
  406. */
  407. void GenerateFrameworkInfoPList(cmGeneratorTarget* target,
  408. const std::string& targetName,
  409. const std::string& fname);
  410. /** Construct a comment for a custom command. */
  411. std::string ConstructComment(cmCustomCommandGenerator const& ccg,
  412. const char* default_comment = "") const;
  413. // Compute object file names.
  414. std::string GetObjectFileNameWithoutTarget(
  415. const cmSourceFile& source, std::string const& dir_max,
  416. bool* hasSourceExtension = nullptr,
  417. char const* customOutputExtension = nullptr);
  418. /** Fill out the static linker flags for the given target. */
  419. void GetStaticLibraryFlags(std::string& flags, std::string const& config,
  420. std::string const& linkLanguage,
  421. cmGeneratorTarget* target);
  422. std::vector<BT<std::string>> GetStaticLibraryFlags(
  423. std::string const& config, std::string const& linkLanguage,
  424. cmGeneratorTarget* target);
  425. /** Fill out these strings for the given target. Libraries to link,
  426. * flags, and linkflags. */
  427. void GetDeviceLinkFlags(cmLinkLineComputer* linkLineComputer,
  428. const std::string& config, std::string& linkLibs,
  429. std::string& linkFlags, std::string& frameworkPath,
  430. std::string& linkPath, cmGeneratorTarget* target);
  431. void GetTargetFlags(cmLinkLineComputer* linkLineComputer,
  432. const std::string& config, std::string& linkLibs,
  433. std::string& flags, std::string& linkFlags,
  434. std::string& frameworkPath, std::string& linkPath,
  435. cmGeneratorTarget* target);
  436. void GetTargetFlags(
  437. cmLinkLineComputer* linkLineComputer, const std::string& config,
  438. std::vector<BT<std::string>>& linkLibs, std::string& flags,
  439. std::vector<BT<std::string>>& linkFlags, std::string& frameworkPath,
  440. std::vector<BT<std::string>>& linkPath, cmGeneratorTarget* target);
  441. void GetTargetDefines(cmGeneratorTarget const* target,
  442. std::string const& config, std::string const& lang,
  443. std::set<std::string>& defines) const;
  444. std::set<BT<std::string>> GetTargetDefines(cmGeneratorTarget const* target,
  445. std::string const& config,
  446. std::string const& lang) const;
  447. void GetTargetCompileFlags(cmGeneratorTarget* target,
  448. std::string const& config,
  449. std::string const& lang, std::string& flags,
  450. std::string const& arch);
  451. std::vector<BT<std::string>> GetTargetCompileFlags(
  452. cmGeneratorTarget* target, std::string const& config,
  453. std::string const& lang, std::string const& arch = std::string());
  454. std::string GetFrameworkFlags(std::string const& l,
  455. std::string const& config,
  456. cmGeneratorTarget* target);
  457. virtual std::string GetTargetFortranFlags(cmGeneratorTarget const* target,
  458. std::string const& config);
  459. virtual void ComputeObjectFilenames(
  460. std::map<cmSourceFile const*, std::string>& mapping,
  461. cmGeneratorTarget const* gt = nullptr);
  462. bool IsWindowsShell() const;
  463. bool IsWatcomWMake() const;
  464. bool IsMinGWMake() const;
  465. bool IsNMake() const;
  466. bool IsNinjaMulti() const;
  467. void IssueMessage(MessageType t, std::string const& text) const;
  468. void CreateEvaluationFileOutputs();
  469. void CreateEvaluationFileOutputs(const std::string& config);
  470. void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
  471. cmProp GetRuleLauncher(cmGeneratorTarget* target, const std::string& prop);
  472. protected:
  473. //! put all the libraries for a target on into the given stream
  474. void OutputLinkLibraries(cmComputeLinkInformation* pcli,
  475. cmLinkLineComputer* linkLineComputer,
  476. std::string& linkLibraries,
  477. std::string& frameworkPath, std::string& linkPath);
  478. void OutputLinkLibraries(cmComputeLinkInformation* pcli,
  479. cmLinkLineComputer* linkLineComputer,
  480. std::vector<BT<std::string>>& linkLibraries,
  481. std::string& frameworkPath,
  482. std::vector<BT<std::string>>& linkPath);
  483. // Handle old-style install rules stored in the targets.
  484. void GenerateTargetInstallRules(
  485. std::ostream& os, const std::string& config,
  486. std::vector<std::string> const& configurationTypes);
  487. std::string& CreateSafeUniqueObjectFileName(const std::string& sin,
  488. std::string const& dir_max);
  489. /** Check whether the native build system supports the given
  490. definition. Issues a warning. */
  491. virtual bool CheckDefinition(std::string const& define) const;
  492. cmMakefile* Makefile;
  493. cmStateSnapshot StateSnapshot;
  494. cmListFileBacktrace DirectoryBacktrace;
  495. cmGlobalGenerator* GlobalGenerator;
  496. std::map<std::string, std::string> UniqueObjectNamesMap;
  497. std::string::size_type ObjectPathMax;
  498. std::set<std::string> ObjectMaxPathViolations;
  499. std::set<std::string> EnvCPATH;
  500. using GeneratorTargetMap =
  501. std::unordered_map<std::string, cmGeneratorTarget*>;
  502. GeneratorTargetMap GeneratorTargetSearchIndex;
  503. GeneratorTargetVector GeneratorTargets;
  504. std::set<cmGeneratorTarget const*> WarnCMP0063;
  505. GeneratorTargetMap ImportedGeneratorTargets;
  506. GeneratorTargetVector OwnedImportedGeneratorTargets;
  507. std::map<std::string, std::string> AliasTargets;
  508. std::map<std::string, std::string> Compilers;
  509. std::map<std::string, std::string> VariableMappings;
  510. std::string CompilerSysroot;
  511. std::string LinkerSysroot;
  512. std::unordered_map<std::string, std::string> AppleArchSysroots;
  513. bool EmitUniversalBinaryFlags;
  514. KWIML_INT_uint64_t BackwardsCompatibility;
  515. bool BackwardsCompatibilityFinal;
  516. private:
  517. /**
  518. * See LinearGetSourceFileWithOutput for background information
  519. */
  520. cmTarget* LinearGetTargetWithOutput(const std::string& name) const;
  521. /**
  522. * Generalized old version of GetSourceFileWithOutput kept for
  523. * backward-compatibility. It implements a linear search and supports
  524. * relative file paths. It is used as a fall back by GetSourceFileWithOutput
  525. * and GetSourcesWithOutput.
  526. */
  527. cmSourceFile* LinearGetSourceFileWithOutput(const std::string& name,
  528. cmSourceOutputKind kind,
  529. bool& byproduct) const;
  530. struct SourceEntry
  531. {
  532. cmSourcesWithOutput Sources;
  533. };
  534. // A map for fast output to input look up.
  535. using OutputToSourceMap = std::unordered_map<std::string, SourceEntry>;
  536. OutputToSourceMap OutputToSource;
  537. void UpdateOutputToSourceMap(std::string const& byproduct, cmTarget* target,
  538. cmListFileBacktrace const& bt,
  539. cmCommandOrigin origin);
  540. void UpdateOutputToSourceMap(std::string const& output, cmSourceFile* source,
  541. OutputRole role, cmListFileBacktrace const& bt,
  542. cmCommandOrigin origin);
  543. void AddSharedFlags(std::string& flags, const std::string& lang,
  544. bool shared);
  545. bool GetShouldUseOldFlags(bool shared, const std::string& lang) const;
  546. void AddPositionIndependentFlags(std::string& flags, std::string const& l,
  547. int targetType);
  548. void ComputeObjectMaxPath();
  549. bool AllAppleArchSysrootsAreTheSame(const std::vector<std::string>& archs,
  550. const char* sysroot);
  551. void CopyPchCompilePdb(const std::string& config, cmGeneratorTarget* target,
  552. const std::string& ReuseFrom,
  553. cmGeneratorTarget* reuseTarget,
  554. std::vector<std::string> const& extensions);
  555. };
  556. #if !defined(CMAKE_BOOTSTRAP)
  557. bool cmLocalGeneratorCheckObjectName(std::string& objName,
  558. std::string::size_type dir_len,
  559. std::string::size_type max_total_len);
  560. #endif
  561. namespace detail {
  562. void AddCustomCommandToTarget(cmLocalGenerator& lg,
  563. const cmListFileBacktrace& lfbt,
  564. cmCommandOrigin origin, cmTarget* target,
  565. const std::vector<std::string>& byproducts,
  566. const std::vector<std::string>& depends,
  567. const cmCustomCommandLines& commandLines,
  568. cmCustomCommandType type, const char* comment,
  569. const char* workingDir, bool escapeOldStyle,
  570. bool uses_terminal, const std::string& depfile,
  571. const std::string& job_pool,
  572. bool command_expand_lists, bool stdPipesUTF8);
  573. cmSourceFile* AddCustomCommandToOutput(
  574. cmLocalGenerator& lg, const cmListFileBacktrace& lfbt,
  575. cmCommandOrigin origin, const std::vector<std::string>& outputs,
  576. const std::vector<std::string>& byproducts,
  577. const std::vector<std::string>& depends, const std::string& main_dependency,
  578. const cmImplicitDependsList& implicit_depends,
  579. const cmCustomCommandLines& commandLines, const char* comment,
  580. const char* workingDir, bool replace, bool escapeOldStyle,
  581. bool uses_terminal, bool command_expand_lists, const std::string& depfile,
  582. const std::string& job_pool, bool stdPipesUTF8);
  583. void AppendCustomCommandToOutput(cmLocalGenerator& lg,
  584. const cmListFileBacktrace& lfbt,
  585. const std::string& output,
  586. const std::vector<std::string>& depends,
  587. const cmImplicitDependsList& implicit_depends,
  588. const cmCustomCommandLines& commandLines);
  589. void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt,
  590. cmCommandOrigin origin, cmTarget* target,
  591. std::string const& force, const char* workingDir,
  592. const std::vector<std::string>& byproducts,
  593. const std::vector<std::string>& depends,
  594. const cmCustomCommandLines& commandLines,
  595. bool escapeOldStyle, const char* comment,
  596. bool uses_terminal, bool command_expand_lists,
  597. const std::string& job_pool, bool stdPipesUTF8);
  598. std::vector<std::string> ComputeISPCObjectSuffixes(cmGeneratorTarget* target);
  599. std::vector<std::string> ComputeISPCExtraObjects(
  600. std::string const& objectName, std::string const& buildDirectory,
  601. std::vector<std::string> const& ispcSuffixes);
  602. }