cmLocalGenerator.h 28 KB

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