cmLocalGenerator.h 28 KB

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