cmLocalGenerator.h 29 KB

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