cmLocalGenerator.h 30 KB

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