1
0

cmLocalGenerator.h 28 KB

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