cmLocalGenerator.h 30 KB

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