cmLocalGenerator.h 31 KB

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