cmLocalGenerator.h 29 KB

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