cmLocalGenerator.h 28 KB

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