cmLocalGenerator.h 29 KB

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