cmLocalGenerator.h 30 KB

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