cmLocalGenerator.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst 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() const { return this->Makefile; }
  88. //! Get the GlobalGenerator this is associated with
  89. cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; }
  90. cmGlobalGenerator const* GetGlobalGenerator() const
  91. {
  92. return this->GlobalGenerator;
  93. }
  94. virtual std::unique_ptr<cmRulePlaceholderExpander>
  95. CreateRulePlaceholderExpander(
  96. cmBuildStep buildStep = cmBuildStep::Compile) const;
  97. std::string GetExeExportFlags(std::string const& linkLanguage,
  98. cmGeneratorTarget& tgt) const;
  99. cmState* GetState() const;
  100. cmStateSnapshot GetStateSnapshot() const;
  101. void AddArchitectureFlags(std::string& flags,
  102. cmGeneratorTarget const* target,
  103. std::string const& lang, std::string const& config,
  104. std::string const& filterArch = std::string());
  105. void AddLanguageFlags(std::string& flags, cmGeneratorTarget const* target,
  106. cmBuildStep compileOrLink, std::string const& lang,
  107. std::string const& config);
  108. void AddLanguageFlagsForLinking(std::string& flags,
  109. cmGeneratorTarget const* target,
  110. std::string const& lang,
  111. std::string const& config);
  112. void AddFeatureFlags(std::string& flags, cmGeneratorTarget const* target,
  113. std::string const& lang, std::string const& config);
  114. void AddVisibilityPresetFlags(std::string& flags,
  115. cmGeneratorTarget const* target,
  116. std::string const& lang);
  117. void AddConfigVariableFlags(std::string& flags, std::string const& var,
  118. std::string const& config);
  119. // Handle prefixes processing (like LINKER:)
  120. void AddConfigVariableFlags(std::string& flags, std::string const& var,
  121. cmGeneratorTarget const* target,
  122. cmBuildStep compileOrLink,
  123. std::string const& lang,
  124. std::string const& config);
  125. void AddColorDiagnosticsFlags(std::string& flags, std::string const& lang);
  126. //! Append flags to a string.
  127. virtual void AppendFlags(std::string& flags,
  128. std::string const& newFlags) const;
  129. virtual void AppendFlags(std::string& flags,
  130. std::vector<BT<std::string>> const& newFlags) const;
  131. virtual void AppendFlagEscape(std::string& flags,
  132. std::string const& rawFlag) const;
  133. /**
  134. * Append flags after parsing, prefixes processing (like LINKER:) and
  135. * escaping
  136. */
  137. void AppendFlags(std::string& flags, std::string const& newFlags,
  138. std::string const& name, cmGeneratorTarget const* target,
  139. cmBuildStep compileOrLink, std::string const& lang);
  140. void AddISPCDependencies(cmGeneratorTarget* target);
  141. void AddPchDependencies(cmGeneratorTarget* target);
  142. void AddUnityBuild(cmGeneratorTarget* target);
  143. virtual void AddXCConfigSources(cmGeneratorTarget* /* target */) {}
  144. void AppendTargetCreationLinkFlags(std::string& flags,
  145. cmGeneratorTarget const* target,
  146. std::string const& linkLanguage);
  147. void AppendLinkerTypeFlags(std::string& flags, cmGeneratorTarget* target,
  148. std::string const& config,
  149. std::string const& linkLanguage);
  150. void AppendIPOLinkerFlags(std::string& flags, cmGeneratorTarget* target,
  151. std::string const& config,
  152. std::string const& lang);
  153. void AppendPositionIndependentLinkerFlags(std::string& flags,
  154. cmGeneratorTarget* target,
  155. std::string const& config,
  156. std::string const& lang);
  157. void AppendWarningAsErrorLinkerFlags(std::string& flags,
  158. cmGeneratorTarget* target,
  159. std::string const& lang);
  160. void AppendDependencyInfoLinkerFlags(std::string& flags,
  161. cmGeneratorTarget* target,
  162. std::string const& config,
  163. std::string const& lang);
  164. virtual std::string GetLinkDependencyFile(cmGeneratorTarget* target,
  165. std::string const& config) const;
  166. void AppendModuleDefinitionFlag(std::string& flags,
  167. cmGeneratorTarget const* target,
  168. cmLinkLineComputer* linkLineComputer,
  169. std::string const& config,
  170. std::string const& lang);
  171. bool AppendLWYUFlags(std::string& flags, cmGeneratorTarget const* target,
  172. std::string const& lang);
  173. //! Get the include flags for the current makefile and language
  174. std::string GetIncludeFlags(std::vector<std::string> const& includes,
  175. cmGeneratorTarget* target,
  176. std::string const& lang,
  177. std::string const& config,
  178. bool forResponseFile = false);
  179. using GeneratorTargetVector =
  180. std::vector<std::unique_ptr<cmGeneratorTarget>>;
  181. GeneratorTargetVector const& GetGeneratorTargets() const
  182. {
  183. return this->GeneratorTargets;
  184. }
  185. GeneratorTargetVector const& GetOwnedImportedGeneratorTargets() const
  186. {
  187. return this->OwnedImportedGeneratorTargets;
  188. }
  189. void AddGeneratorTarget(std::unique_ptr<cmGeneratorTarget> gt);
  190. void AddImportedGeneratorTarget(cmGeneratorTarget* gt);
  191. void AddOwnedImportedGeneratorTarget(std::unique_ptr<cmGeneratorTarget> gt);
  192. cmGeneratorTarget* FindLocalNonAliasGeneratorTarget(
  193. std::string const& name) const;
  194. cmGeneratorTarget* FindGeneratorTargetToUse(std::string const& name) const;
  195. /**
  196. * Process a list of include directories
  197. */
  198. void AppendIncludeDirectories(std::vector<std::string>& includes,
  199. std::string const& includes_list,
  200. cmSourceFile const& sourceFile) const;
  201. void AppendIncludeDirectories(std::vector<std::string>& includes,
  202. std::vector<std::string> const& includes_vec,
  203. cmSourceFile const& sourceFile) const;
  204. /**
  205. * Encode a list of preprocessor definitions for the compiler
  206. * command line.
  207. */
  208. void AppendDefines(std::set<std::string>& defines,
  209. std::string const& defines_list) const;
  210. void AppendDefines(std::set<BT<std::string>>& defines,
  211. std::string const& defines_list) const;
  212. void AppendDefines(std::set<BT<std::string>>& defines,
  213. std::vector<BT<std::string>> const& defines_vec) const;
  214. /**
  215. * Encode a list of compile options for the compiler
  216. * command line.
  217. */
  218. void AppendCompileOptions(std::string& options,
  219. std::string const& options_list,
  220. char const* regex = nullptr) const;
  221. void AppendCompileOptions(std::string& options,
  222. std::vector<std::string> const& options_vec,
  223. char const* regex = nullptr) const;
  224. void AppendCompileOptions(std::vector<BT<std::string>>& options,
  225. std::vector<BT<std::string>> const& options_vec,
  226. char const* regex = nullptr) const;
  227. /**
  228. * Join a set of defines into a definesString with a space separator.
  229. */
  230. void JoinDefines(std::set<std::string> const& defines,
  231. std::string& definesString, std::string const& lang);
  232. /** Lookup and append options associated with a particular feature. */
  233. void AppendFeatureOptions(std::string& flags, std::string const& lang,
  234. char const* feature);
  235. cmValue GetFeature(std::string const& feature, std::string const& config);
  236. /** \brief Get absolute path to dependency \a name
  237. *
  238. * Translate a dependency as given in CMake code to the name to
  239. * appear in a generated build file.
  240. * - If \a name is a utility target, returns false.
  241. * - If \a name is a CMake target, it will be transformed to the real output
  242. * location of that target for the given configuration.
  243. * - If \a name is the full path to a file, it will be returned.
  244. * - Otherwise \a name is treated as a relative path with respect to
  245. * the source directory of this generator. This should only be
  246. * used for dependencies of custom commands.
  247. */
  248. bool GetRealDependency(std::string const& name, std::string const& config,
  249. std::string& dep);
  250. /** Called from command-line hook to clear dependencies. */
  251. virtual void ClearDependencies(cmMakefile* /* mf */, bool /* verbose */) {}
  252. /** Called from command-line hook to update dependencies. */
  253. virtual bool UpdateDependencies(std::string const& /* tgtInfo */,
  254. bool /*verbose*/, bool /*color*/)
  255. {
  256. return true;
  257. }
  258. /** @brief Get the include directories for the current makefile and language
  259. * and optional the compiler implicit include directories.
  260. *
  261. * @arg stripImplicitDirs Strip all directories found in
  262. * CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES from the result.
  263. * @arg appendAllImplicitDirs Append all directories found in
  264. * CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES to the result.
  265. */
  266. std::vector<BT<std::string>> GetIncludeDirectoriesImplicit(
  267. cmGeneratorTarget const* target, std::string const& lang = "C",
  268. std::string const& config = "", bool stripImplicitDirs = true,
  269. bool appendAllImplicitDirs = false) const;
  270. /** @brief Get the include directories for the current makefile and language
  271. * and optional the compiler implicit include directories.
  272. *
  273. * @arg dirs Directories are appended to this list
  274. */
  275. void GetIncludeDirectoriesImplicit(std::vector<std::string>& dirs,
  276. cmGeneratorTarget const* target,
  277. std::string const& lang = "C",
  278. std::string const& config = "",
  279. bool stripImplicitDirs = true,
  280. bool appendAllImplicitDirs = false) const;
  281. /** @brief Get the include directories for the current makefile and language.
  282. * @arg dirs Include directories are appended to this list
  283. */
  284. void GetIncludeDirectories(std::vector<std::string>& dirs,
  285. cmGeneratorTarget const* target,
  286. std::string const& lang = "C",
  287. std::string const& config = "") const;
  288. /** @brief Get the include directories for the current makefile and language.
  289. * @return The include directory list
  290. */
  291. std::vector<BT<std::string>> GetIncludeDirectories(
  292. cmGeneratorTarget const* target, std::string const& lang = "C",
  293. std::string const& config = "") const;
  294. void AddCompileOptions(std::string& flags, cmGeneratorTarget* target,
  295. std::string const& lang, std::string const& config);
  296. void AddCompileOptions(std::vector<BT<std::string>>& flags,
  297. cmGeneratorTarget* target, std::string const& lang,
  298. std::string const& config);
  299. /**
  300. * Add a custom PRE_BUILD, PRE_LINK, or POST_BUILD command to a target.
  301. */
  302. cmTarget* AddCustomCommandToTarget(
  303. std::string const& target, cmCustomCommandType type,
  304. std::unique_ptr<cmCustomCommand> cc,
  305. cmObjectLibraryCommands objLibCommands = cmObjectLibraryCommands::Reject);
  306. /**
  307. * Add a custom command to a source file.
  308. */
  309. cmSourceFile* AddCustomCommandToOutput(std::unique_ptr<cmCustomCommand> cc,
  310. bool replace = false);
  311. /**
  312. * Add a utility to the build. A utility target is a command that is run
  313. * every time the target is built.
  314. */
  315. cmTarget* AddUtilityCommand(std::string const& utilityName,
  316. bool excludeFromAll,
  317. std::unique_ptr<cmCustomCommand> cc);
  318. virtual std::string CreateUtilityOutput(
  319. std::string const& targetName, std::vector<std::string> const& byproducts,
  320. cmListFileBacktrace const& bt);
  321. virtual std::vector<cmCustomCommandGenerator> MakeCustomCommandGenerators(
  322. cmCustomCommand const& cc, std::string const& config);
  323. std::vector<std::string> ExpandCustomCommandOutputPaths(
  324. cmCompiledGeneratorExpression const& cge, std::string const& config);
  325. std::vector<std::string> ExpandCustomCommandOutputGenex(
  326. std::string const& o, cmListFileBacktrace const& bt);
  327. /**
  328. * Add target byproducts.
  329. */
  330. void AddTargetByproducts(cmTarget* target,
  331. std::vector<std::string> const& byproducts,
  332. cmListFileBacktrace const& bt,
  333. cmCommandOrigin origin);
  334. enum class OutputRole
  335. {
  336. Primary,
  337. Byproduct,
  338. };
  339. /**
  340. * Add source file outputs.
  341. */
  342. void AddSourceOutputs(cmSourceFile* source,
  343. std::vector<std::string> const& outputs,
  344. OutputRole role, cmListFileBacktrace const& bt,
  345. cmCommandOrigin origin);
  346. /**
  347. * Return the target if the provided source name is a byproduct of a utility
  348. * target or a PRE_BUILD, PRE_LINK, or POST_BUILD command.
  349. * Return the source file which has the provided source name as output.
  350. */
  351. cmSourcesWithOutput GetSourcesWithOutput(std::string const& name) const;
  352. /**
  353. * Is there a source file that has the provided source name as an output?
  354. * If so then return it.
  355. */
  356. cmSourceFile* GetSourceFileWithOutput(
  357. std::string const& name,
  358. cmSourceOutputKind kind = cmSourceOutputKind::OutputOnly) const;
  359. std::string GetProjectName() const;
  360. /** Compute the language used to compile the given source file. */
  361. std::string GetSourceFileLanguage(cmSourceFile const& source);
  362. // Fill the vector with the target names for the object files,
  363. // preprocessed files and assembly files.
  364. void GetIndividualFileTargets(std::vector<std::string>&) {}
  365. /**
  366. * Get the relative path from the generator output directory to a
  367. * per-target support directory.
  368. */
  369. virtual std::string GetTargetDirectory(
  370. cmGeneratorTarget const* target) const;
  371. cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const;
  372. cmake* GetCMakeInstance() const;
  373. std::string const& GetSourceDirectory() const;
  374. std::string const& GetBinaryDirectory() const;
  375. std::string const& GetCurrentBinaryDirectory() const;
  376. std::string const& GetCurrentSourceDirectory() const;
  377. virtual std::string GetObjectOutputRoot() const;
  378. virtual bool AlwaysUsesCMFPaths() const;
  379. /**
  380. * Generate a macOS application bundle Info.plist file.
  381. */
  382. void GenerateAppleInfoPList(cmGeneratorTarget* target,
  383. std::string const& targetName,
  384. std::string const& fname);
  385. /**
  386. * Generate a macOS framework Info.plist file.
  387. */
  388. void GenerateFrameworkInfoPList(cmGeneratorTarget* target,
  389. std::string const& targetName,
  390. std::string const& fname);
  391. /** Construct a comment for a custom command. */
  392. std::string ConstructComment(cmCustomCommandGenerator const& ccg,
  393. char const* default_comment = "") const;
  394. // Compute object file names.
  395. std::string GetObjectFileNameWithoutTarget(
  396. cmSourceFile const& 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. std::string const& config, std::string& linkLibs,
  410. std::string& linkFlags, std::string& frameworkPath,
  411. std::string& linkPath, cmGeneratorTarget* target);
  412. void GetTargetFlags(cmLinkLineComputer* linkLineComputer,
  413. std::string const& 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, std::string const& 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(std::string const& config);
  454. void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
  455. std::string GetRuleLauncher(cmGeneratorTarget* target,
  456. std::string const& prop,
  457. std::string const& 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. std::string CreateSafeObjectFileName(std::string const& sin) const;
  465. protected:
  466. // The default implementation converts to a Windows shortpath to
  467. // help older toolchains handle spaces and such. A generator may
  468. // override this to avoid that conversion.
  469. virtual std::string ConvertToIncludeReference(
  470. std::string const& path, cmOutputConverter::OutputFormat format);
  471. //! put all the libraries for a target on into the given stream
  472. void OutputLinkLibraries(cmComputeLinkInformation* pcli,
  473. cmLinkLineComputer* linkLineComputer,
  474. std::string& linkLibraries,
  475. std::string& frameworkPath, std::string& linkPath);
  476. void OutputLinkLibraries(cmComputeLinkInformation* pcli,
  477. cmLinkLineComputer* linkLineComputer,
  478. std::vector<BT<std::string>>& linkLibraries,
  479. std::string& frameworkPath,
  480. std::vector<BT<std::string>>& linkPath);
  481. // Handle old-style install rules stored in the targets.
  482. void GenerateTargetInstallRules(
  483. std::ostream& os, std::string const& config,
  484. std::vector<std::string> const& configurationTypes);
  485. virtual void AddGeneratorSpecificInstallSetup(std::ostream&) {}
  486. std::string& CreateSafeUniqueObjectFileName(std::string const& sin,
  487. std::string const& dir_max);
  488. /** Check whether the native build system supports the given
  489. definition. Issues a warning. */
  490. virtual bool CheckDefinition(std::string const& define) const;
  491. cmMakefile* Makefile;
  492. cmListFileBacktrace DirectoryBacktrace;
  493. cmGlobalGenerator* GlobalGenerator;
  494. std::map<std::string, std::string> UniqueObjectNamesMap;
  495. std::string::size_type ObjectPathMax;
  496. std::set<std::string> ObjectMaxPathViolations;
  497. std::vector<std::string> EnvCPATH;
  498. using GeneratorTargetMap =
  499. std::unordered_map<std::string, cmGeneratorTarget*>;
  500. GeneratorTargetMap GeneratorTargetSearchIndex;
  501. GeneratorTargetVector GeneratorTargets;
  502. GeneratorTargetMap ImportedGeneratorTargets;
  503. GeneratorTargetVector OwnedImportedGeneratorTargets;
  504. std::map<std::string, std::string> AliasTargets;
  505. std::map<std::string, std::string> Compilers;
  506. std::map<std::string, std::string> VariableMappings;
  507. std::string CompilerSysroot;
  508. std::string LinkerSysroot;
  509. std::unordered_map<std::string, std::string> AppleArchSysroots;
  510. bool EmitUniversalBinaryFlags;
  511. private:
  512. /**
  513. * See LinearGetSourceFileWithOutput for background information
  514. */
  515. cmTarget* LinearGetTargetWithOutput(std::string const& name) const;
  516. /**
  517. * Generalized old version of GetSourceFileWithOutput kept for
  518. * backward-compatibility. It implements a linear search and supports
  519. * relative file paths. It is used as a fall back by GetSourceFileWithOutput
  520. * and GetSourcesWithOutput.
  521. */
  522. cmSourceFile* LinearGetSourceFileWithOutput(std::string const& name,
  523. cmSourceOutputKind kind,
  524. bool& byproduct) const;
  525. struct SourceEntry
  526. {
  527. cmSourcesWithOutput Sources;
  528. };
  529. // A map for fast output to input look up.
  530. using OutputToSourceMap = std::unordered_map<std::string, SourceEntry>;
  531. OutputToSourceMap OutputToSource;
  532. void UpdateOutputToSourceMap(std::string const& byproduct, cmTarget* target,
  533. cmListFileBacktrace const& bt,
  534. cmCommandOrigin origin);
  535. void UpdateOutputToSourceMap(std::string const& output, cmSourceFile* source,
  536. OutputRole role, cmListFileBacktrace const& bt,
  537. cmCommandOrigin origin);
  538. void AddPositionIndependentFlags(std::string& flags, std::string const& l,
  539. int targetType);
  540. void ComputeObjectMaxPath();
  541. bool AllAppleArchSysrootsAreTheSame(std::vector<std::string> const& archs,
  542. cmValue sysroot);
  543. void CopyPchCompilePdb(std::string const& config,
  544. std::string const& language,
  545. cmGeneratorTarget* target,
  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. cmListFileBacktrace const& lfbt,
  611. std::string const& output,
  612. std::vector<std::string> const& depends,
  613. cmImplicitDependsList const& implicit_depends,
  614. cmCustomCommandLines const& 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. }