cmLocalGenerator.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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 "cmProperty.h"
  20. #include "cmStateSnapshot.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. //! Get the include flags for the current makefile and language
  148. std::string GetIncludeFlags(const std::vector<std::string>& includes,
  149. cmGeneratorTarget* target,
  150. const std::string& lang,
  151. bool forceFullPaths = false,
  152. bool forResponseFile = false,
  153. const std::string& config = "");
  154. using GeneratorTargetVector =
  155. std::vector<std::unique_ptr<cmGeneratorTarget>>;
  156. const GeneratorTargetVector& GetGeneratorTargets() const
  157. {
  158. return this->GeneratorTargets;
  159. }
  160. void AddGeneratorTarget(std::unique_ptr<cmGeneratorTarget> gt);
  161. void AddImportedGeneratorTarget(cmGeneratorTarget* gt);
  162. void AddOwnedImportedGeneratorTarget(std::unique_ptr<cmGeneratorTarget> gt);
  163. cmGeneratorTarget* FindLocalNonAliasGeneratorTarget(
  164. const std::string& name) const;
  165. cmGeneratorTarget* FindGeneratorTargetToUse(const std::string& name) const;
  166. /**
  167. * Process a list of include directories
  168. */
  169. void AppendIncludeDirectories(std::vector<std::string>& includes,
  170. std::string const& includes_list,
  171. const cmSourceFile& sourceFile) const;
  172. void AppendIncludeDirectories(std::vector<std::string>& includes,
  173. const std::vector<std::string>& includes_vec,
  174. const cmSourceFile& sourceFile) const;
  175. /**
  176. * Encode a list of preprocessor definitions for the compiler
  177. * command line.
  178. */
  179. void AppendDefines(std::set<std::string>& defines,
  180. std::string const& defines_list) const;
  181. void AppendDefines(std::set<BT<std::string>>& defines,
  182. std::string const& defines_list) const;
  183. void AppendDefines(std::set<BT<std::string>>& defines,
  184. const std::vector<BT<std::string>>& defines_vec) const;
  185. /**
  186. * Encode a list of compile options for the compiler
  187. * command line.
  188. */
  189. void AppendCompileOptions(std::string& options,
  190. std::string const& options_list,
  191. const char* regex = nullptr) const;
  192. void AppendCompileOptions(std::string& options,
  193. const std::vector<std::string>& options_vec,
  194. const char* regex = nullptr) const;
  195. void AppendCompileOptions(std::vector<BT<std::string>>& options,
  196. const std::vector<BT<std::string>>& options_vec,
  197. const char* regex = nullptr) const;
  198. /**
  199. * Join a set of defines into a definesString with a space separator.
  200. */
  201. void JoinDefines(const std::set<std::string>& defines,
  202. std::string& definesString, const std::string& lang);
  203. /** Lookup and append options associated with a particular feature. */
  204. void AppendFeatureOptions(std::string& flags, const std::string& lang,
  205. const char* feature);
  206. cmProp GetFeature(const std::string& feature, const std::string& config);
  207. /** \brief Get absolute path to dependency \a name
  208. *
  209. * Translate a dependency as given in CMake code to the name to
  210. * appear in a generated build file.
  211. * - If \a name is a utility target, returns false.
  212. * - If \a name is a CMake target, it will be transformed to the real output
  213. * location of that target for the given configuration.
  214. * - If \a name is the full path to a file, it will be returned.
  215. * - Otherwise \a name is treated as a relative path with respect to
  216. * the source directory of this generator. This should only be
  217. * used for dependencies of custom commands.
  218. */
  219. bool GetRealDependency(const std::string& name, const std::string& config,
  220. std::string& dep);
  221. virtual std::string ConvertToIncludeReference(
  222. std::string const& path,
  223. cmOutputConverter::OutputFormat format = cmOutputConverter::SHELL,
  224. bool forceFullPaths = false);
  225. /** Called from command-line hook to clear dependencies. */
  226. virtual void ClearDependencies(cmMakefile* /* mf */, bool /* verbose */) {}
  227. /** Called from command-line hook to update dependencies. */
  228. virtual bool UpdateDependencies(const std::string& /* tgtInfo */,
  229. bool /*verbose*/, bool /*color*/)
  230. {
  231. return true;
  232. }
  233. /** @brief Get the include directories for the current makefile and language
  234. * and optional the compiler implicit include directories.
  235. *
  236. * @arg stripImplicitDirs Strip all directories found in
  237. * CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES from the result.
  238. * @arg appendAllImplicitDirs Append all directories found in
  239. * CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES to the result.
  240. */
  241. std::vector<BT<std::string>> GetIncludeDirectoriesImplicit(
  242. cmGeneratorTarget const* target, std::string const& lang = "C",
  243. std::string const& config = "", bool stripImplicitDirs = true,
  244. bool appendAllImplicitDirs = false) const;
  245. /** @brief Get the include directories for the current makefile and language
  246. * and optional the compiler implicit include directories.
  247. *
  248. * @arg dirs Directories are appended to this list
  249. */
  250. void GetIncludeDirectoriesImplicit(std::vector<std::string>& dirs,
  251. cmGeneratorTarget const* target,
  252. const std::string& lang = "C",
  253. const std::string& config = "",
  254. bool stripImplicitDirs = true,
  255. bool appendAllImplicitDirs = false) const;
  256. /** @brief Get the include directories for the current makefile and language.
  257. * @arg dirs Include directories are appended to this list
  258. */
  259. void GetIncludeDirectories(std::vector<std::string>& dirs,
  260. cmGeneratorTarget const* target,
  261. const std::string& lang = "C",
  262. const std::string& config = "") const;
  263. /** @brief Get the include directories for the current makefile and language.
  264. * @return The include directory list
  265. */
  266. std::vector<BT<std::string>> GetIncludeDirectories(
  267. cmGeneratorTarget const* target, std::string const& lang = "C",
  268. std::string const& config = "") const;
  269. void AddCompileOptions(std::string& flags, cmGeneratorTarget* target,
  270. const std::string& lang, const std::string& config);
  271. void AddCompileOptions(std::vector<BT<std::string>>& flags,
  272. cmGeneratorTarget* target, const std::string& lang,
  273. const std::string& config);
  274. /**
  275. * Add a custom PRE_BUILD, PRE_LINK, or POST_BUILD command to a target.
  276. */
  277. cmTarget* AddCustomCommandToTarget(
  278. const std::string& target, const std::vector<std::string>& byproducts,
  279. const std::vector<std::string>& depends,
  280. const cmCustomCommandLines& commandLines, cmCustomCommandType type,
  281. const char* comment, const char* workingDir,
  282. cmPolicies::PolicyStatus cmp0116, bool escapeOldStyle = true,
  283. bool uses_terminal = false, const std::string& depfile = "",
  284. const std::string& job_pool = "", bool command_expand_lists = false,
  285. cmObjectLibraryCommands objLibCommands = cmObjectLibraryCommands::Reject,
  286. bool stdPipesUTF8 = false);
  287. /**
  288. * Add a custom command to a source file.
  289. */
  290. cmSourceFile* AddCustomCommandToOutput(
  291. const std::string& output, const std::vector<std::string>& depends,
  292. const std::string& main_dependency,
  293. const cmCustomCommandLines& commandLines, const char* comment,
  294. const char* workingDir, cmPolicies::PolicyStatus cmp0116,
  295. bool replace = false, bool escapeOldStyle = true,
  296. bool uses_terminal = false, bool command_expand_lists = false,
  297. const std::string& depfile = "", const std::string& job_pool = "",
  298. bool stdPipesUTF8 = false);
  299. cmSourceFile* AddCustomCommandToOutput(
  300. const std::vector<std::string>& outputs,
  301. const std::vector<std::string>& byproducts,
  302. const std::vector<std::string>& depends,
  303. const std::string& main_dependency,
  304. const cmImplicitDependsList& implicit_depends,
  305. const cmCustomCommandLines& commandLines, const char* comment,
  306. const char* workingDir, cmPolicies::PolicyStatus cmp0116,
  307. bool replace = false, bool escapeOldStyle = true,
  308. bool uses_terminal = false, bool command_expand_lists = false,
  309. const std::string& depfile = "", const std::string& job_pool = "",
  310. bool stdPipesUTF8 = false);
  311. /**
  312. * Add a utility to the build. A utility target is a command that is run
  313. * every time the target is built.
  314. */
  315. cmTarget* AddUtilityCommand(
  316. const std::string& utilityName, bool excludeFromAll,
  317. const char* workingDir, const std::vector<std::string>& byproducts,
  318. const std::vector<std::string>& depends,
  319. const cmCustomCommandLines& commandLines, cmPolicies::PolicyStatus cmp0116,
  320. bool escapeOldStyle = true, const char* comment = nullptr,
  321. bool uses_terminal = false, bool command_expand_lists = false,
  322. const std::string& job_pool = "", bool stdPipesUTF8 = false);
  323. virtual std::string CreateUtilityOutput(
  324. std::string const& targetName, std::vector<std::string> const& byproducts,
  325. cmListFileBacktrace const& bt);
  326. virtual std::vector<cmCustomCommandGenerator> MakeCustomCommandGenerators(
  327. cmCustomCommand const& cc, std::string const& config);
  328. std::vector<std::string> ExpandCustomCommandOutputPaths(
  329. cmCompiledGeneratorExpression const& cge, std::string const& config);
  330. std::vector<std::string> ExpandCustomCommandOutputGenex(
  331. std::string const& o, cmListFileBacktrace const& bt);
  332. /**
  333. * Add target byproducts.
  334. */
  335. void AddTargetByproducts(cmTarget* target,
  336. const std::vector<std::string>& byproducts,
  337. cmListFileBacktrace const& bt,
  338. cmCommandOrigin origin);
  339. enum class OutputRole
  340. {
  341. Primary,
  342. Byproduct,
  343. };
  344. /**
  345. * Add source file outputs.
  346. */
  347. void AddSourceOutputs(cmSourceFile* source,
  348. std::vector<std::string> const& outputs,
  349. OutputRole role, cmListFileBacktrace const& bt,
  350. cmCommandOrigin origin);
  351. /**
  352. * Return the target if the provided source name is a byproduct of a utility
  353. * target or a PRE_BUILD, PRE_LINK, or POST_BUILD command.
  354. * Return the source file which has the provided source name as output.
  355. */
  356. cmSourcesWithOutput GetSourcesWithOutput(const std::string& name) const;
  357. /**
  358. * Is there a source file that has the provided source name as an output?
  359. * If so then return it.
  360. */
  361. cmSourceFile* GetSourceFileWithOutput(
  362. const std::string& name,
  363. cmSourceOutputKind kind = cmSourceOutputKind::OutputOnly) const;
  364. std::string GetProjectName() const;
  365. /** Compute the language used to compile the given source file. */
  366. std::string GetSourceFileLanguage(const cmSourceFile& source);
  367. // Fill the vector with the target names for the object files,
  368. // preprocessed files and assembly files.
  369. void GetIndividualFileTargets(std::vector<std::string>&) {}
  370. /**
  371. * Get the relative path from the generator output directory to a
  372. * per-target support directory.
  373. */
  374. virtual std::string GetTargetDirectory(
  375. cmGeneratorTarget const* target) const;
  376. /**
  377. * Get the level of backwards compatibility requested by the project
  378. * in this directory. This is the value of the CMake variable
  379. * CMAKE_BACKWARDS_COMPATIBILITY whose format is
  380. * "major.minor[.patch]". The returned integer is encoded as
  381. *
  382. * CMake_VERSION_ENCODE(major, minor, patch)
  383. *
  384. * and is monotonically increasing with the CMake version.
  385. */
  386. KWIML_INT_uint64_t GetBackwardsCompatibility();
  387. /**
  388. * Test whether compatibility is set to a given version or lower.
  389. */
  390. bool NeedBackwardsCompatibility_2_4();
  391. cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const;
  392. cmake* GetCMakeInstance() const;
  393. std::string const& GetSourceDirectory() const;
  394. std::string const& GetBinaryDirectory() const;
  395. std::string const& GetCurrentBinaryDirectory() const;
  396. std::string const& GetCurrentSourceDirectory() const;
  397. /**
  398. * Convert the given remote path to a relative path with respect to
  399. * the given local path. Both paths must use forward slashes and not
  400. * already be escaped or quoted.
  401. * The conversion is skipped if the paths are not both in the source
  402. * or both in the binary tree.
  403. */
  404. std::string MaybeConvertToRelativePath(std::string const& local_path,
  405. std::string const& remote_path) const;
  406. /**
  407. * Generate a macOS application bundle Info.plist file.
  408. */
  409. void GenerateAppleInfoPList(cmGeneratorTarget* target,
  410. const std::string& targetName,
  411. const std::string& fname);
  412. /**
  413. * Generate a macOS framework Info.plist file.
  414. */
  415. void GenerateFrameworkInfoPList(cmGeneratorTarget* target,
  416. const std::string& targetName,
  417. const std::string& fname);
  418. /** Construct a comment for a custom command. */
  419. std::string ConstructComment(cmCustomCommandGenerator const& ccg,
  420. const char* default_comment = "") const;
  421. // Compute object file names.
  422. std::string GetObjectFileNameWithoutTarget(
  423. const cmSourceFile& source, std::string const& dir_max,
  424. bool* hasSourceExtension = nullptr,
  425. char const* customOutputExtension = nullptr);
  426. /** Fill out the static linker flags for the given target. */
  427. void GetStaticLibraryFlags(std::string& flags, std::string const& config,
  428. std::string const& linkLanguage,
  429. cmGeneratorTarget* target);
  430. std::vector<BT<std::string>> GetStaticLibraryFlags(
  431. std::string const& config, std::string const& linkLanguage,
  432. cmGeneratorTarget* target);
  433. /** Fill out these strings for the given target. Libraries to link,
  434. * flags, and linkflags. */
  435. void GetDeviceLinkFlags(cmLinkLineComputer* linkLineComputer,
  436. const std::string& config, std::string& linkLibs,
  437. std::string& linkFlags, std::string& frameworkPath,
  438. std::string& linkPath, cmGeneratorTarget* target);
  439. void GetTargetFlags(cmLinkLineComputer* linkLineComputer,
  440. const std::string& config, std::string& linkLibs,
  441. std::string& flags, std::string& linkFlags,
  442. std::string& frameworkPath, std::string& linkPath,
  443. cmGeneratorTarget* target);
  444. void GetTargetFlags(
  445. cmLinkLineComputer* linkLineComputer, const std::string& config,
  446. std::vector<BT<std::string>>& linkLibs, std::string& flags,
  447. std::vector<BT<std::string>>& linkFlags, std::string& frameworkPath,
  448. std::vector<BT<std::string>>& linkPath, cmGeneratorTarget* target);
  449. void GetTargetDefines(cmGeneratorTarget const* target,
  450. std::string const& config, std::string const& lang,
  451. std::set<std::string>& defines) const;
  452. std::set<BT<std::string>> GetTargetDefines(cmGeneratorTarget const* target,
  453. std::string const& config,
  454. std::string const& lang) const;
  455. void GetTargetCompileFlags(cmGeneratorTarget* target,
  456. std::string const& config,
  457. std::string const& lang, std::string& flags,
  458. std::string const& arch);
  459. std::vector<BT<std::string>> GetTargetCompileFlags(
  460. cmGeneratorTarget* target, std::string const& config,
  461. std::string const& lang, std::string const& arch = std::string());
  462. std::string GetFrameworkFlags(std::string const& l,
  463. std::string const& config,
  464. cmGeneratorTarget* target);
  465. virtual std::string GetTargetFortranFlags(cmGeneratorTarget const* target,
  466. std::string const& config);
  467. virtual void ComputeObjectFilenames(
  468. std::map<cmSourceFile const*, std::string>& mapping,
  469. cmGeneratorTarget const* gt = nullptr);
  470. bool IsWindowsShell() const;
  471. bool IsWatcomWMake() const;
  472. bool IsMinGWMake() const;
  473. bool IsNMake() const;
  474. bool IsNinjaMulti() const;
  475. void IssueMessage(MessageType t, std::string const& text) const;
  476. void CreateEvaluationFileOutputs();
  477. void CreateEvaluationFileOutputs(const std::string& config);
  478. void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
  479. cmProp GetRuleLauncher(cmGeneratorTarget* target, const std::string& prop);
  480. protected:
  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. cmStateSnapshot StateSnapshot;
  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::set<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. const char* 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. void IncludeFileInUnitySources(cmGeneratedFileStream& unity_file,
  565. std::string const& sf_full_path,
  566. cmProp beforeInclude, cmProp afterInclude,
  567. cmProp uniqueIdName) const;
  568. std::vector<std::string> AddUnityFilesModeAuto(
  569. cmGeneratorTarget* target, std::string const& lang,
  570. std::vector<cmSourceFile*> const& filtered_sources, cmProp beforeInclude,
  571. cmProp afterInclude, std::string const& filename_base, size_t batchSize);
  572. std::vector<std::string> AddUnityFilesModeGroup(
  573. cmGeneratorTarget* target, std::string const& lang,
  574. std::vector<cmSourceFile*> const& filtered_sources, cmProp beforeInclude,
  575. cmProp afterInclude, std::string const& filename_base);
  576. };
  577. #if !defined(CMAKE_BOOTSTRAP)
  578. bool cmLocalGeneratorCheckObjectName(std::string& objName,
  579. std::string::size_type dir_len,
  580. std::string::size_type max_total_len);
  581. #endif
  582. namespace detail {
  583. void AddCustomCommandToTarget(cmLocalGenerator& lg,
  584. const cmListFileBacktrace& lfbt,
  585. cmCommandOrigin origin, cmTarget* target,
  586. const std::vector<std::string>& byproducts,
  587. const std::vector<std::string>& depends,
  588. const cmCustomCommandLines& commandLines,
  589. cmCustomCommandType type, const char* comment,
  590. const char* workingDir, bool escapeOldStyle,
  591. bool uses_terminal, const std::string& depfile,
  592. const std::string& job_pool,
  593. bool command_expand_lists, bool stdPipesUTF8,
  594. cmPolicies::PolicyStatus cmp0116);
  595. cmSourceFile* AddCustomCommandToOutput(
  596. cmLocalGenerator& lg, const cmListFileBacktrace& lfbt,
  597. cmCommandOrigin origin, const std::vector<std::string>& outputs,
  598. const std::vector<std::string>& byproducts,
  599. const std::vector<std::string>& depends, const std::string& main_dependency,
  600. const cmImplicitDependsList& implicit_depends,
  601. const cmCustomCommandLines& commandLines, const char* comment,
  602. const char* workingDir, bool replace, bool escapeOldStyle,
  603. bool uses_terminal, bool command_expand_lists, const std::string& depfile,
  604. const std::string& job_pool, bool stdPipesUTF8,
  605. cmPolicies::PolicyStatus cmp0116);
  606. void AppendCustomCommandToOutput(cmLocalGenerator& lg,
  607. const cmListFileBacktrace& lfbt,
  608. const std::string& output,
  609. const std::vector<std::string>& depends,
  610. const cmImplicitDependsList& implicit_depends,
  611. const cmCustomCommandLines& commandLines);
  612. void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt,
  613. cmCommandOrigin origin, cmTarget* target,
  614. const char* workingDir,
  615. const std::vector<std::string>& byproducts,
  616. const std::vector<std::string>& depends,
  617. const cmCustomCommandLines& commandLines,
  618. bool escapeOldStyle, const char* comment,
  619. bool uses_terminal, bool command_expand_lists,
  620. const std::string& job_pool, bool stdPipesUTF8,
  621. cmPolicies::PolicyStatus cmp0116);
  622. std::vector<std::string> ComputeISPCObjectSuffixes(cmGeneratorTarget* target);
  623. std::vector<std::string> ComputeISPCExtraObjects(
  624. std::string const& objectName, std::string const& buildDirectory,
  625. std::vector<std::string> const& ispcSuffixes);
  626. }