cmLocalGenerator.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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 AppendIPOLinkerFlags(std::string& flags, cmGeneratorTarget* target,
  151. const std::string& config,
  152. const std::string& lang);
  153. void AppendPositionIndependentLinkerFlags(std::string& flags,
  154. cmGeneratorTarget* target,
  155. const std::string& config,
  156. const std::string& lang);
  157. void AppendDependencyInfoLinkerFlags(std::string& flags,
  158. cmGeneratorTarget* target,
  159. const std::string& config,
  160. const std::string& lang);
  161. virtual std::string GetLinkDependencyFile(cmGeneratorTarget* target,
  162. const std::string& config) const;
  163. void AppendModuleDefinitionFlag(std::string& flags,
  164. cmGeneratorTarget const* target,
  165. cmLinkLineComputer* linkLineComputer,
  166. std::string const& config);
  167. bool AppendLWYUFlags(std::string& flags, const cmGeneratorTarget* target,
  168. const std::string& lang);
  169. //! Get the include flags for the current makefile and language
  170. std::string GetIncludeFlags(std::vector<std::string> const& includes,
  171. cmGeneratorTarget* target,
  172. std::string const& lang,
  173. std::string const& config,
  174. bool forResponseFile = false);
  175. using GeneratorTargetVector =
  176. std::vector<std::unique_ptr<cmGeneratorTarget>>;
  177. const GeneratorTargetVector& GetGeneratorTargets() const
  178. {
  179. return this->GeneratorTargets;
  180. }
  181. const GeneratorTargetVector& GetOwnedImportedGeneratorTargets() const
  182. {
  183. return this->OwnedImportedGeneratorTargets;
  184. }
  185. void AddGeneratorTarget(std::unique_ptr<cmGeneratorTarget> gt);
  186. void AddImportedGeneratorTarget(cmGeneratorTarget* gt);
  187. void AddOwnedImportedGeneratorTarget(std::unique_ptr<cmGeneratorTarget> gt);
  188. cmGeneratorTarget* FindLocalNonAliasGeneratorTarget(
  189. const std::string& name) const;
  190. cmGeneratorTarget* FindGeneratorTargetToUse(const std::string& name) const;
  191. /**
  192. * Process a list of include directories
  193. */
  194. void AppendIncludeDirectories(std::vector<std::string>& includes,
  195. std::string const& includes_list,
  196. const cmSourceFile& sourceFile) const;
  197. void AppendIncludeDirectories(std::vector<std::string>& includes,
  198. const std::vector<std::string>& includes_vec,
  199. const cmSourceFile& sourceFile) const;
  200. /**
  201. * Encode a list of preprocessor definitions for the compiler
  202. * command line.
  203. */
  204. void AppendDefines(std::set<std::string>& defines,
  205. std::string const& defines_list) const;
  206. void AppendDefines(std::set<BT<std::string>>& defines,
  207. std::string const& defines_list) const;
  208. void AppendDefines(std::set<BT<std::string>>& defines,
  209. const std::vector<BT<std::string>>& defines_vec) const;
  210. /**
  211. * Encode a list of compile options for the compiler
  212. * command line.
  213. */
  214. void AppendCompileOptions(std::string& options,
  215. std::string const& options_list,
  216. const char* regex = nullptr) const;
  217. void AppendCompileOptions(std::string& options,
  218. const std::vector<std::string>& options_vec,
  219. const char* regex = nullptr) const;
  220. void AppendCompileOptions(std::vector<BT<std::string>>& options,
  221. const std::vector<BT<std::string>>& options_vec,
  222. const char* regex = nullptr) const;
  223. /**
  224. * Join a set of defines into a definesString with a space separator.
  225. */
  226. void JoinDefines(const std::set<std::string>& defines,
  227. std::string& definesString, const std::string& lang);
  228. /** Lookup and append options associated with a particular feature. */
  229. void AppendFeatureOptions(std::string& flags, const std::string& lang,
  230. const char* feature);
  231. cmValue GetFeature(const std::string& feature, const std::string& config);
  232. /** \brief Get absolute path to dependency \a name
  233. *
  234. * Translate a dependency as given in CMake code to the name to
  235. * appear in a generated build file.
  236. * - If \a name is a utility target, returns false.
  237. * - If \a name is a CMake target, it will be transformed to the real output
  238. * location of that target for the given configuration.
  239. * - If \a name is the full path to a file, it will be returned.
  240. * - Otherwise \a name is treated as a relative path with respect to
  241. * the source directory of this generator. This should only be
  242. * used for dependencies of custom commands.
  243. */
  244. bool GetRealDependency(const std::string& name, const std::string& config,
  245. std::string& dep);
  246. /** Called from command-line hook to clear dependencies. */
  247. virtual void ClearDependencies(cmMakefile* /* mf */, bool /* verbose */) {}
  248. /** Called from command-line hook to update dependencies. */
  249. virtual bool UpdateDependencies(const std::string& /* tgtInfo */,
  250. bool /*verbose*/, bool /*color*/)
  251. {
  252. return true;
  253. }
  254. /** @brief Get the include directories for the current makefile and language
  255. * and optional the compiler implicit include directories.
  256. *
  257. * @arg stripImplicitDirs Strip all directories found in
  258. * CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES from the result.
  259. * @arg appendAllImplicitDirs Append all directories found in
  260. * CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES to the result.
  261. */
  262. std::vector<BT<std::string>> GetIncludeDirectoriesImplicit(
  263. cmGeneratorTarget const* target, std::string const& lang = "C",
  264. std::string const& config = "", bool stripImplicitDirs = true,
  265. bool appendAllImplicitDirs = false) const;
  266. /** @brief Get the include directories for the current makefile and language
  267. * and optional the compiler implicit include directories.
  268. *
  269. * @arg dirs Directories are appended to this list
  270. */
  271. void GetIncludeDirectoriesImplicit(std::vector<std::string>& dirs,
  272. cmGeneratorTarget const* target,
  273. const std::string& lang = "C",
  274. const std::string& config = "",
  275. bool stripImplicitDirs = true,
  276. bool appendAllImplicitDirs = false) const;
  277. /** @brief Get the include directories for the current makefile and language.
  278. * @arg dirs Include directories are appended to this list
  279. */
  280. void GetIncludeDirectories(std::vector<std::string>& dirs,
  281. cmGeneratorTarget const* target,
  282. const std::string& lang = "C",
  283. const std::string& config = "") const;
  284. /** @brief Get the include directories for the current makefile and language.
  285. * @return The include directory list
  286. */
  287. std::vector<BT<std::string>> GetIncludeDirectories(
  288. cmGeneratorTarget const* target, std::string const& lang = "C",
  289. std::string const& config = "") const;
  290. void AddCompileOptions(std::string& flags, cmGeneratorTarget* target,
  291. const std::string& lang, const std::string& config);
  292. void AddCompileOptions(std::vector<BT<std::string>>& flags,
  293. cmGeneratorTarget* target, const std::string& lang,
  294. const std::string& config);
  295. /**
  296. * Add a custom PRE_BUILD, PRE_LINK, or POST_BUILD command to a target.
  297. */
  298. cmTarget* AddCustomCommandToTarget(
  299. const std::string& target, cmCustomCommandType type,
  300. std::unique_ptr<cmCustomCommand> cc,
  301. cmObjectLibraryCommands objLibCommands = cmObjectLibraryCommands::Reject);
  302. /**
  303. * Add a custom command to a source file.
  304. */
  305. cmSourceFile* AddCustomCommandToOutput(std::unique_ptr<cmCustomCommand> cc,
  306. bool replace = false);
  307. /**
  308. * Add a utility to the build. A utility target is a command that is run
  309. * every time the target is built.
  310. */
  311. cmTarget* AddUtilityCommand(const std::string& utilityName,
  312. bool excludeFromAll,
  313. std::unique_ptr<cmCustomCommand> cc);
  314. virtual std::string CreateUtilityOutput(
  315. std::string const& targetName, std::vector<std::string> const& byproducts,
  316. cmListFileBacktrace const& bt);
  317. virtual std::vector<cmCustomCommandGenerator> MakeCustomCommandGenerators(
  318. cmCustomCommand const& cc, std::string const& config);
  319. std::vector<std::string> ExpandCustomCommandOutputPaths(
  320. cmCompiledGeneratorExpression const& cge, std::string const& config);
  321. std::vector<std::string> ExpandCustomCommandOutputGenex(
  322. std::string const& o, cmListFileBacktrace const& bt);
  323. /**
  324. * Add target byproducts.
  325. */
  326. void AddTargetByproducts(cmTarget* target,
  327. const std::vector<std::string>& byproducts,
  328. cmListFileBacktrace const& bt,
  329. cmCommandOrigin origin);
  330. enum class OutputRole
  331. {
  332. Primary,
  333. Byproduct,
  334. };
  335. /**
  336. * Add source file outputs.
  337. */
  338. void AddSourceOutputs(cmSourceFile* source,
  339. std::vector<std::string> const& outputs,
  340. OutputRole role, cmListFileBacktrace const& bt,
  341. cmCommandOrigin origin);
  342. /**
  343. * Return the target if the provided source name is a byproduct of a utility
  344. * target or a PRE_BUILD, PRE_LINK, or POST_BUILD command.
  345. * Return the source file which has the provided source name as output.
  346. */
  347. cmSourcesWithOutput GetSourcesWithOutput(const std::string& name) const;
  348. /**
  349. * Is there a source file that has the provided source name as an output?
  350. * If so then return it.
  351. */
  352. cmSourceFile* GetSourceFileWithOutput(
  353. const std::string& name,
  354. cmSourceOutputKind kind = cmSourceOutputKind::OutputOnly) const;
  355. std::string GetProjectName() const;
  356. /** Compute the language used to compile the given source file. */
  357. std::string GetSourceFileLanguage(const cmSourceFile& source);
  358. // Fill the vector with the target names for the object files,
  359. // preprocessed files and assembly files.
  360. void GetIndividualFileTargets(std::vector<std::string>&) {}
  361. /**
  362. * Get the relative path from the generator output directory to a
  363. * per-target support directory.
  364. */
  365. virtual std::string GetTargetDirectory(
  366. cmGeneratorTarget const* target) const;
  367. /**
  368. * Get the level of backwards compatibility requested by the project
  369. * in this directory. This is the value of the CMake variable
  370. * CMAKE_BACKWARDS_COMPATIBILITY whose format is
  371. * "major.minor[.patch]". The returned integer is encoded as
  372. *
  373. * CMake_VERSION_ENCODE(major, minor, patch)
  374. *
  375. * and is monotonically increasing with the CMake version.
  376. */
  377. KWIML_INT_uint64_t GetBackwardsCompatibility();
  378. /**
  379. * Test whether compatibility is set to a given version or lower.
  380. */
  381. bool NeedBackwardsCompatibility_2_4();
  382. cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const;
  383. cmake* GetCMakeInstance() const;
  384. std::string const& GetSourceDirectory() const;
  385. std::string const& GetBinaryDirectory() const;
  386. std::string const& GetCurrentBinaryDirectory() const;
  387. std::string const& GetCurrentSourceDirectory() const;
  388. /**
  389. * Generate a macOS application bundle Info.plist file.
  390. */
  391. void GenerateAppleInfoPList(cmGeneratorTarget* target,
  392. const std::string& targetName,
  393. const std::string& fname);
  394. /**
  395. * Generate a macOS framework Info.plist file.
  396. */
  397. void GenerateFrameworkInfoPList(cmGeneratorTarget* target,
  398. const std::string& targetName,
  399. const std::string& fname);
  400. /** Construct a comment for a custom command. */
  401. std::string ConstructComment(cmCustomCommandGenerator const& ccg,
  402. const char* default_comment = "") const;
  403. // Compute object file names.
  404. std::string GetObjectFileNameWithoutTarget(
  405. const cmSourceFile& source, std::string const& dir_max,
  406. bool* hasSourceExtension = nullptr,
  407. char const* customOutputExtension = nullptr);
  408. /** Fill out the static linker flags for the given target. */
  409. void GetStaticLibraryFlags(std::string& flags, std::string const& config,
  410. std::string const& linkLanguage,
  411. cmGeneratorTarget* target);
  412. std::vector<BT<std::string>> GetStaticLibraryFlags(
  413. std::string const& config, std::string const& linkLanguage,
  414. cmGeneratorTarget* target);
  415. /** Fill out these strings for the given target. Libraries to link,
  416. * flags, and linkflags. */
  417. void GetDeviceLinkFlags(cmLinkLineDeviceComputer& linkLineComputer,
  418. const std::string& config, std::string& linkLibs,
  419. std::string& linkFlags, std::string& frameworkPath,
  420. std::string& linkPath, cmGeneratorTarget* target);
  421. void GetTargetFlags(cmLinkLineComputer* linkLineComputer,
  422. const std::string& config, std::string& linkLibs,
  423. std::string& flags, std::string& linkFlags,
  424. std::string& frameworkPath, std::string& linkPath,
  425. cmGeneratorTarget* target);
  426. void GetTargetFlags(
  427. cmLinkLineComputer* linkLineComputer, const std::string& config,
  428. std::vector<BT<std::string>>& linkLibs, std::string& flags,
  429. std::vector<BT<std::string>>& linkFlags, std::string& frameworkPath,
  430. std::vector<BT<std::string>>& linkPath, cmGeneratorTarget* target);
  431. void GetTargetDefines(cmGeneratorTarget const* target,
  432. std::string const& config, std::string const& lang,
  433. std::set<std::string>& defines) const;
  434. std::set<BT<std::string>> GetTargetDefines(cmGeneratorTarget const* target,
  435. std::string const& config,
  436. std::string const& lang) const;
  437. void GetTargetCompileFlags(cmGeneratorTarget* target,
  438. std::string const& config,
  439. std::string const& lang, std::string& flags,
  440. std::string const& arch);
  441. std::vector<BT<std::string>> GetTargetCompileFlags(
  442. cmGeneratorTarget* target, std::string const& config,
  443. std::string const& lang, std::string const& arch = std::string());
  444. std::string GetFrameworkFlags(std::string const& l,
  445. std::string const& config,
  446. cmGeneratorTarget* target);
  447. std::string GetXcFrameworkFlags(std::string const& l,
  448. std::string const& config,
  449. cmGeneratorTarget* target);
  450. virtual std::string GetTargetFortranFlags(cmGeneratorTarget const* target,
  451. std::string const& config);
  452. virtual void ComputeObjectFilenames(
  453. std::map<cmSourceFile const*, std::string>& mapping,
  454. cmGeneratorTarget const* gt = nullptr);
  455. bool IsWindowsShell() const;
  456. bool IsWatcomWMake() const;
  457. bool IsMinGWMake() const;
  458. bool IsNMake() const;
  459. bool IsNinjaMulti() const;
  460. void IssueMessage(MessageType t, std::string const& text) const;
  461. void CreateEvaluationFileOutputs();
  462. void CreateEvaluationFileOutputs(const std::string& config);
  463. void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
  464. std::string GetRuleLauncher(cmGeneratorTarget* target,
  465. const std::string& prop,
  466. const std::string& config);
  467. protected:
  468. // The default implementation converts to a Windows shortpath to
  469. // help older toolchains handle spaces and such. A generator may
  470. // override this to avoid that conversion.
  471. virtual std::string ConvertToIncludeReference(
  472. std::string const& path, cmOutputConverter::OutputFormat format);
  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. virtual void AddGeneratorSpecificInstallSetup(std::ostream&) {}
  488. std::string& CreateSafeUniqueObjectFileName(const std::string& sin,
  489. std::string const& dir_max);
  490. /** Check whether the native build system supports the given
  491. definition. Issues a warning. */
  492. virtual bool CheckDefinition(std::string const& define) const;
  493. cmMakefile* Makefile;
  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::vector<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. cmValue 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. // Returns MSVC_DEBUG_INFORMATION_FORMAT value if CMP0141 is NEW.
  556. cm::optional<std::string> GetMSVCDebugFormatName(
  557. std::string const& config, cmGeneratorTarget const* target);
  558. struct UnityBatchedSource
  559. {
  560. cmSourceFile* Source = nullptr;
  561. std::vector<size_t> Configs;
  562. UnityBatchedSource(cmSourceFile* sf)
  563. : Source(sf)
  564. {
  565. }
  566. };
  567. struct UnitySource
  568. {
  569. std::string Path;
  570. bool PerConfig = false;
  571. UnitySource(std::string path, bool perConfig)
  572. : Path(std::move(path))
  573. , PerConfig(perConfig)
  574. {
  575. }
  576. };
  577. UnitySource WriteUnitySource(
  578. cmGeneratorTarget* target, std::vector<std::string> const& configs,
  579. cmRange<std::vector<UnityBatchedSource>::const_iterator> sources,
  580. cmValue beforeInclude, cmValue afterInclude, std::string filename) const;
  581. void WriteUnitySourceInclude(std::ostream& unity_file,
  582. cm::optional<std::string> const& cond,
  583. std::string const& sf_full_path,
  584. cmValue beforeInclude, cmValue afterInclude,
  585. cmValue uniqueIdName) const;
  586. std::vector<UnitySource> AddUnityFilesModeAuto(
  587. cmGeneratorTarget* target, std::string const& lang,
  588. std::vector<std::string> const& configs,
  589. std::vector<UnityBatchedSource> const& filtered_sources,
  590. cmValue beforeInclude, cmValue afterInclude,
  591. std::string const& filename_base, size_t batchSize);
  592. std::vector<UnitySource> AddUnityFilesModeGroup(
  593. cmGeneratorTarget* target, std::string const& lang,
  594. std::vector<std::string> const& configs,
  595. std::vector<UnityBatchedSource> const& filtered_sources,
  596. cmValue beforeInclude, cmValue afterInclude,
  597. std::string const& filename_base);
  598. };
  599. #if !defined(CMAKE_BOOTSTRAP)
  600. bool cmLocalGeneratorCheckObjectName(std::string& objName,
  601. std::string::size_type dir_len,
  602. std::string::size_type max_total_len);
  603. #endif
  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. }