cmLocalGenerator.h 30 KB

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