cmLocalGenerator.h 30 KB

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