cmLocalGenerator.h 30 KB

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