cmGlobalGenerator.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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 <unordered_set>
  13. #include <utility>
  14. #include <vector>
  15. #include <cm/optional>
  16. #include <cmext/algorithm>
  17. #include "cm_codecvt.hxx"
  18. #include "cmCustomCommandLines.h"
  19. #include "cmDuration.h"
  20. #include "cmExportSet.h"
  21. #include "cmProperty.h"
  22. #include "cmStateSnapshot.h"
  23. #include "cmStringAlgorithms.h"
  24. #include "cmSystemTools.h"
  25. #include "cmTarget.h"
  26. #include "cmTargetDepend.h"
  27. #include "cmTransformDepfile.h"
  28. #if !defined(CMAKE_BOOTSTRAP)
  29. # include <cm3p/json/value.h>
  30. # include "cmFileLockPool.h"
  31. #endif
  32. #define CMAKE_DIRECTORY_ID_SEP "::@"
  33. class cmDirectoryId;
  34. class cmExportBuildFileGenerator;
  35. class cmExternalMakefileProjectGenerator;
  36. class cmGeneratorTarget;
  37. class cmInstallRuntimeDependencySet;
  38. class cmLinkLineComputer;
  39. class cmLocalGenerator;
  40. class cmMakefile;
  41. class cmOutputConverter;
  42. class cmSourceFile;
  43. class cmState;
  44. class cmStateDirectory;
  45. class cmake;
  46. namespace detail {
  47. inline void AppendStrs(std::vector<std::string>&)
  48. {
  49. }
  50. template <typename T, typename... Ts>
  51. inline void AppendStrs(std::vector<std::string>& command, T&& s, Ts&&... ts)
  52. {
  53. command.emplace_back(std::forward<T>(s));
  54. AppendStrs(command, std::forward<Ts>(ts)...);
  55. }
  56. struct GeneratedMakeCommand
  57. {
  58. // Add each argument as a separate element to the vector
  59. template <typename... T>
  60. void Add(T&&... args)
  61. {
  62. // iterate the args and append each one
  63. AppendStrs(this->PrimaryCommand, std::forward<T>(args)...);
  64. }
  65. // Add each value in the iterators as a separate element to the vector
  66. void Add(std::vector<std::string>::const_iterator start,
  67. std::vector<std::string>::const_iterator end)
  68. {
  69. cm::append(this->PrimaryCommand, start, end);
  70. }
  71. std::string Printable() const { return cmJoin(this->PrimaryCommand, " "); }
  72. std::vector<std::string> PrimaryCommand;
  73. bool RequiresOutputForward = false;
  74. };
  75. }
  76. /** \class cmGlobalGenerator
  77. * \brief Responsible for overseeing the generation process for the entire tree
  78. *
  79. * Subclasses of this class generate makefiles for various
  80. * platforms.
  81. */
  82. class cmGlobalGenerator
  83. {
  84. public:
  85. using LocalGeneratorVector = std::vector<std::unique_ptr<cmLocalGenerator>>;
  86. //! Free any memory allocated with the GlobalGenerator
  87. cmGlobalGenerator(cmake* cm);
  88. virtual ~cmGlobalGenerator();
  89. virtual std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
  90. cmMakefile* mf);
  91. //! Get the name for this generator
  92. virtual std::string GetName() const { return "Generic"; }
  93. /** Check whether the given name matches the current generator. */
  94. virtual bool MatchesGeneratorName(const std::string& name) const
  95. {
  96. return this->GetName() == name;
  97. }
  98. /** Get encoding used by generator for makefile files */
  99. virtual codecvt::Encoding GetMakefileEncoding() const
  100. {
  101. return codecvt::None;
  102. }
  103. #if !defined(CMAKE_BOOTSTRAP)
  104. /** Get a JSON object describing the generator. */
  105. virtual Json::Value GetJson() const;
  106. #endif
  107. /** Tell the generator about the target system. */
  108. virtual bool SetSystemName(std::string const&, cmMakefile*) { return true; }
  109. /** Set the generator-specific instance. Returns true if supported. */
  110. virtual bool SetGeneratorInstance(std::string const& i, cmMakefile* mf);
  111. /** Set the generator-specific platform name. Returns true if platform
  112. is supported and false otherwise. */
  113. virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf);
  114. /** Set the generator-specific toolset name. Returns true if toolset
  115. is supported and false otherwise. */
  116. virtual bool SetGeneratorToolset(std::string const& ts, bool build,
  117. cmMakefile* mf);
  118. /** Read any other cache entries needed for cmake --build. */
  119. virtual bool ReadCacheEntriesForBuild(const cmState& /*state*/)
  120. {
  121. return true;
  122. }
  123. /**
  124. * Create LocalGenerators and process the CMakeLists files. This does not
  125. * actually produce any makefiles, DSPs, etc.
  126. */
  127. virtual void Configure();
  128. bool Compute();
  129. virtual void AddExtraIDETargets() {}
  130. enum TargetTypes
  131. {
  132. AllTargets,
  133. ImportedOnly
  134. };
  135. void CreateImportedGenerationObjects(
  136. cmMakefile* mf, std::vector<std::string> const& targets,
  137. std::vector<cmGeneratorTarget const*>& exports);
  138. void CreateGenerationObjects(TargetTypes targetTypes = AllTargets);
  139. /**
  140. * Generate the all required files for building this project/tree. This
  141. * basically creates a series of LocalGenerators for each directory and
  142. * requests that they Generate.
  143. */
  144. virtual void Generate();
  145. virtual std::unique_ptr<cmLinkLineComputer> CreateLinkLineComputer(
  146. cmOutputConverter* outputConverter,
  147. cmStateDirectory const& stateDir) const;
  148. std::unique_ptr<cmLinkLineComputer> CreateMSVC60LinkLineComputer(
  149. cmOutputConverter* outputConverter,
  150. cmStateDirectory const& stateDir) const;
  151. /**
  152. * Set/Get and Clear the enabled languages.
  153. */
  154. void SetLanguageEnabled(const std::string&, cmMakefile* mf);
  155. bool GetLanguageEnabled(const std::string&) const;
  156. void ClearEnabledLanguages();
  157. void GetEnabledLanguages(std::vector<std::string>& lang) const;
  158. /**
  159. * Try to determine system information such as shared library
  160. * extension, pthreads, byte order etc.
  161. */
  162. virtual void EnableLanguage(std::vector<std::string> const& languages,
  163. cmMakefile*, bool optional);
  164. /**
  165. * Resolve the CMAKE_<lang>_COMPILER setting for the given language.
  166. * Intended to be called from EnableLanguage.
  167. */
  168. void ResolveLanguageCompiler(const std::string& lang, cmMakefile* mf,
  169. bool optional) const;
  170. /**
  171. * Try to determine system information, get it from another generator
  172. */
  173. void EnableLanguagesFromGenerator(cmGlobalGenerator* gen, cmMakefile* mf);
  174. /**
  175. * Try running cmake and building a file. This is used for dynamically
  176. * loaded commands, not as part of the usual build process.
  177. */
  178. int TryCompile(int jobs, const std::string& srcdir,
  179. const std::string& bindir, const std::string& projectName,
  180. const std::string& targetName, bool fast, std::string& output,
  181. cmMakefile* mf);
  182. /**
  183. * Build a file given the following information. This is a more direct call
  184. * that is used by both CTest and TryCompile. If target name is NULL or
  185. * empty then all is assumed. clean indicates if a "make clean" should be
  186. * done first.
  187. */
  188. int Build(
  189. int jobs, const std::string& srcdir, const std::string& bindir,
  190. const std::string& projectName,
  191. std::vector<std::string> const& targetNames, std::string& output,
  192. const std::string& makeProgram, const std::string& config, bool clean,
  193. bool fast, bool verbose, cmDuration timeout,
  194. cmSystemTools::OutputOption outputflag = cmSystemTools::OUTPUT_NONE,
  195. std::vector<std::string> const& nativeOptions =
  196. std::vector<std::string>());
  197. /**
  198. * Open a generated IDE project given the following information.
  199. */
  200. virtual bool Open(const std::string& bindir, const std::string& projectName,
  201. bool dryRun);
  202. struct GeneratedMakeCommand final : public detail::GeneratedMakeCommand
  203. {
  204. };
  205. virtual std::vector<GeneratedMakeCommand> GenerateBuildCommand(
  206. const std::string& makeProgram, const std::string& projectName,
  207. const std::string& projectDir, std::vector<std::string> const& targetNames,
  208. const std::string& config, bool fast, int jobs, bool verbose,
  209. std::vector<std::string> const& makeOptions = std::vector<std::string>());
  210. virtual void PrintBuildCommandAdvice(std::ostream& os, int jobs) const;
  211. /**
  212. * Generate a "cmake --build" call for a given target, config and parallel
  213. * level.
  214. */
  215. std::string GenerateCMakeBuildCommand(const std::string& target,
  216. const std::string& config,
  217. const std::string& parallel,
  218. const std::string& native,
  219. bool ignoreErrors);
  220. //! Get the CMake instance
  221. cmake* GetCMakeInstance() const { return this->CMakeInstance; }
  222. void SetConfiguredFilesPath(cmGlobalGenerator* gen);
  223. const std::vector<std::unique_ptr<cmMakefile>>& GetMakefiles() const
  224. {
  225. return this->Makefiles;
  226. }
  227. const LocalGeneratorVector& GetLocalGenerators() const
  228. {
  229. return this->LocalGenerators;
  230. }
  231. std::vector<cmGeneratorTarget*> GetLocalGeneratorTargetsInOrder(
  232. cmLocalGenerator* lg) const;
  233. cmMakefile* GetCurrentMakefile() const
  234. {
  235. return this->CurrentConfigureMakefile;
  236. }
  237. void SetCurrentMakefile(cmMakefile* mf)
  238. {
  239. this->CurrentConfigureMakefile = mf;
  240. }
  241. void AddMakefile(std::unique_ptr<cmMakefile> mf);
  242. //! Set an generator for an "external makefile based project"
  243. void SetExternalMakefileProjectGenerator(
  244. std::unique_ptr<cmExternalMakefileProjectGenerator> extraGenerator);
  245. std::string GetExtraGeneratorName() const;
  246. void AddInstallComponent(const std::string& component);
  247. /** Mark the (absolute path to a) file as generated. */
  248. void MarkAsGeneratedFile(const std::string& filepath);
  249. /** Determine if the absolute filepath belongs to a generated file. */
  250. bool IsGeneratedFile(const std::string& filepath);
  251. const std::set<std::string>* GetInstallComponents() const
  252. {
  253. return &this->InstallComponents;
  254. }
  255. cmExportSetMap& GetExportSets() { return this->ExportSets; }
  256. cmProp GetGlobalSetting(std::string const& name) const;
  257. bool GlobalSettingIsOn(std::string const& name) const;
  258. std::string GetSafeGlobalSetting(std::string const& name) const;
  259. /** Add a file to the manifest of generated targets for a configuration. */
  260. void AddToManifest(std::string const& f);
  261. void EnableInstallTarget();
  262. cmDuration TryCompileTimeout;
  263. bool GetForceUnixPaths() const { return this->ForceUnixPaths; }
  264. bool GetToolSupportsColor() const { return this->ToolSupportsColor; }
  265. //! return the language for the given extension
  266. std::string GetLanguageFromExtension(const char* ext) const;
  267. //! is an extension to be ignored
  268. bool IgnoreFile(const char* ext) const;
  269. //! What is the preference for linkers and this language (None or Preferred)
  270. int GetLinkerPreference(const std::string& lang) const;
  271. //! What is the object file extension for a given source file?
  272. std::string GetLanguageOutputExtension(cmSourceFile const&) const;
  273. //! What is the configurations directory variable called?
  274. virtual const char* GetCMakeCFGIntDir() const { return "."; }
  275. //! expand CFGIntDir for a configuration
  276. virtual std::string ExpandCFGIntDir(const std::string& str,
  277. const std::string& config) const;
  278. /** Get whether the generator should use a script for link commands. */
  279. bool GetUseLinkScript() const { return this->UseLinkScript; }
  280. /** Get whether the generator should produce special marks on rules
  281. producing symbolic (non-file) outputs. */
  282. bool GetNeedSymbolicMark() const { return this->NeedSymbolicMark; }
  283. /*
  284. * Determine what program to use for building the project.
  285. */
  286. virtual bool FindMakeProgram(cmMakefile*);
  287. //! Find a target by name by searching the local generators.
  288. cmTarget* FindTarget(const std::string& name,
  289. bool excludeAliases = false) const;
  290. cmGeneratorTarget* FindGeneratorTarget(const std::string& name) const;
  291. void AddAlias(const std::string& name, const std::string& tgtName);
  292. bool IsAlias(const std::string& name) const;
  293. /** Determine if a name resolves to a framework on disk or a built target
  294. that is a framework. */
  295. bool NameResolvesToFramework(const std::string& libname) const;
  296. cmMakefile* FindMakefile(const std::string& start_dir) const;
  297. cmLocalGenerator* FindLocalGenerator(cmDirectoryId const& id) const;
  298. /** Append the subdirectory for the given configuration. If anything is
  299. appended the given prefix and suffix will be appended around it, which
  300. is useful for leading or trailing slashes. */
  301. virtual void AppendDirectoryForConfig(const std::string& prefix,
  302. const std::string& config,
  303. const std::string& suffix,
  304. std::string& dir);
  305. /** Get the content of a directory. Directory listings are cached
  306. and re-loaded from disk only when modified. During the generation
  307. step the content will include the target files to be built even if
  308. they do not yet exist. */
  309. std::set<std::string> const& GetDirectoryContent(std::string const& dir,
  310. bool needDisk = true);
  311. void IndexTarget(cmTarget* t);
  312. void IndexGeneratorTarget(cmGeneratorTarget* gt);
  313. // Index the target using a name that is unique to that target
  314. // even if other targets have the same name.
  315. std::string IndexGeneratorTargetUniquely(cmGeneratorTarget const* gt);
  316. static bool IsReservedTarget(std::string const& name);
  317. virtual const char* GetAllTargetName() const { return "ALL_BUILD"; }
  318. virtual const char* GetInstallTargetName() const { return "INSTALL"; }
  319. virtual const char* GetInstallLocalTargetName() const { return nullptr; }
  320. virtual const char* GetInstallStripTargetName() const { return nullptr; }
  321. virtual const char* GetPreinstallTargetName() const { return nullptr; }
  322. virtual const char* GetTestTargetName() const { return "RUN_TESTS"; }
  323. virtual const char* GetPackageTargetName() const { return "PACKAGE"; }
  324. virtual const char* GetPackageSourceTargetName() const { return nullptr; }
  325. virtual const char* GetEditCacheTargetName() const { return nullptr; }
  326. virtual const char* GetRebuildCacheTargetName() const { return nullptr; }
  327. virtual const char* GetCleanTargetName() const { return nullptr; }
  328. // Lookup edit_cache target command preferred by this generator.
  329. virtual std::string GetEditCacheCommand() const { return ""; }
  330. // Default config to use for cmake --build
  331. virtual std::string GetDefaultBuildConfig() const { return "Debug"; }
  332. // Class to track a set of dependencies.
  333. using TargetDependSet = cmTargetDependSet;
  334. // what targets does the specified target depend on directly
  335. // via a target_link_libraries or add_dependencies
  336. TargetDependSet const& GetTargetDirectDepends(
  337. const cmGeneratorTarget* target);
  338. const std::map<std::string, std::vector<cmLocalGenerator*>>& GetProjectMap()
  339. const
  340. {
  341. return this->ProjectMap;
  342. }
  343. // track files replaced during a Generate
  344. void FileReplacedDuringGenerate(const std::string& filename);
  345. void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
  346. void AddRuleHash(const std::vector<std::string>& outputs,
  347. std::string const& content);
  348. /** Return whether the given binary directory is unused. */
  349. bool BinaryDirectoryIsNew(const std::string& dir)
  350. {
  351. return this->BinaryDirectories.insert(dir).second;
  352. }
  353. /** Return true if the generated build tree may contain multiple builds.
  354. i.e. "Can I build Debug and Release in the same tree?" */
  355. virtual bool IsMultiConfig() const { return false; }
  356. virtual bool IsXcode() const { return false; }
  357. virtual bool IsVisualStudio() const { return false; }
  358. virtual bool IsNinja() const { return false; }
  359. /** Return true if we know the exact location of object files.
  360. If false, store the reason in the given string.
  361. This is meaningful only after EnableLanguage has been called. */
  362. virtual bool HasKnownObjectFileLocation(std::string*) const { return true; }
  363. virtual bool UseFolderProperty() const;
  364. virtual bool IsIPOSupported() const { return false; }
  365. /** Return whether the generator can import external visual studio project
  366. using INCLUDE_EXTERNAL_MSPROJECT */
  367. virtual bool IsIncludeExternalMSProjectSupported() const { return false; }
  368. /** Return whether the generator should use EFFECTIVE_PLATFORM_NAME. This is
  369. relevant for mixed macOS and iOS builds. */
  370. virtual bool UseEffectivePlatformName(cmMakefile*) const { return false; }
  371. /** Return whether the "Resources" folder prefix should be stripped from
  372. MacFolder. */
  373. virtual bool ShouldStripResourcePath(cmMakefile*) const;
  374. virtual bool SupportsCustomCommandDepfile() const { return false; }
  375. virtual cm::optional<cmDepfileFormat> DepfileFormat() const
  376. {
  377. return cm::nullopt;
  378. }
  379. std::string GetSharedLibFlagsForLanguage(std::string const& lang) const;
  380. /** Generate an <output>.rule file path for a given command output. */
  381. virtual std::string GenerateRuleFile(std::string const& output) const;
  382. virtual bool SupportsDefaultBuildType() const { return false; }
  383. virtual bool SupportsCrossConfigs() const { return false; }
  384. virtual bool SupportsDefaultConfigs() const { return false; }
  385. static std::string EscapeJSON(const std::string& s);
  386. void ProcessEvaluationFiles();
  387. std::map<std::string, cmExportBuildFileGenerator*>& GetBuildExportSets()
  388. {
  389. return this->BuildExportSets;
  390. }
  391. void AddBuildExportSet(cmExportBuildFileGenerator* gen);
  392. void AddBuildExportExportSet(cmExportBuildFileGenerator* gen);
  393. bool IsExportedTargetsFile(const std::string& filename) const;
  394. bool GenerateImportFile(const std::string& file);
  395. cmExportBuildFileGenerator* GetExportedTargetsFile(
  396. const std::string& filename) const;
  397. void AddCMP0042WarnTarget(const std::string& target);
  398. void AddCMP0068WarnTarget(const std::string& target);
  399. virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
  400. bool GenerateCPackPropertiesFile();
  401. void SetFilenameTargetDepends(
  402. cmSourceFile* sf, std::set<cmGeneratorTarget const*> const& tgts);
  403. const std::set<const cmGeneratorTarget*>& GetFilenameTargetDepends(
  404. cmSourceFile* sf) const;
  405. #if !defined(CMAKE_BOOTSTRAP)
  406. cmFileLockPool& GetFileLockPool() { return this->FileLockPool; }
  407. #endif
  408. bool GetConfigureDoneCMP0026() const
  409. {
  410. return this->ConfigureDoneCMP0026AndCMP0024;
  411. }
  412. std::string MakeSilentFlag;
  413. int RecursionDepth;
  414. virtual void GetQtAutoGenConfigs(std::vector<std::string>& configs) const
  415. {
  416. configs.emplace_back("$<CONFIG>");
  417. }
  418. std::string const& GetRealPath(std::string const& dir);
  419. std::string NewDeferId();
  420. cmInstallRuntimeDependencySet* CreateAnonymousRuntimeDependencySet();
  421. cmInstallRuntimeDependencySet* GetNamedRuntimeDependencySet(
  422. const std::string& name);
  423. protected:
  424. // for a project collect all its targets by following depend
  425. // information, and also collect all the targets
  426. void GetTargetSets(TargetDependSet& projectTargets,
  427. TargetDependSet& originalTargets, cmLocalGenerator* root,
  428. std::vector<cmLocalGenerator*>& generators);
  429. bool IsRootOnlyTarget(cmGeneratorTarget* target) const;
  430. void AddTargetDepends(const cmGeneratorTarget* target,
  431. TargetDependSet& projectTargets);
  432. void SetLanguageEnabledFlag(const std::string& l, cmMakefile* mf);
  433. void SetLanguageEnabledMaps(const std::string& l, cmMakefile* mf);
  434. void FillExtensionToLanguageMap(const std::string& l, cmMakefile* mf);
  435. virtual bool CheckLanguages(std::vector<std::string> const& languages,
  436. cmMakefile* mf) const;
  437. virtual void PrintCompilerAdvice(std::ostream& os, std::string const& lang,
  438. cmProp envVar) const;
  439. virtual bool ComputeTargetDepends();
  440. virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const;
  441. /// @brief Qt AUTOMOC/UIC/RCC target generation
  442. /// @return true on success
  443. bool QtAutoGen();
  444. bool AddAutomaticSources();
  445. std::string SelectMakeProgram(const std::string& makeProgram,
  446. const std::string& makeDefault = "") const;
  447. // Fill the ProjectMap, this must be called after LocalGenerators
  448. // has been populated.
  449. void FillProjectMap();
  450. void CheckTargetProperties();
  451. bool IsExcluded(cmStateSnapshot const& root,
  452. cmStateSnapshot const& snp) const;
  453. bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen) const;
  454. bool IsExcluded(cmLocalGenerator* root,
  455. const cmGeneratorTarget* target) const;
  456. virtual void InitializeProgressMarks() {}
  457. struct GlobalTargetInfo
  458. {
  459. std::string Name;
  460. std::string Message;
  461. cmCustomCommandLines CommandLines;
  462. std::vector<std::string> Depends;
  463. std::string WorkingDir;
  464. bool UsesTerminal = false;
  465. cmTarget::PerConfig PerConfig = cmTarget::PerConfig::Yes;
  466. bool StdPipesUTF8 = false;
  467. };
  468. void CreateDefaultGlobalTargets(std::vector<GlobalTargetInfo>& targets);
  469. void AddGlobalTarget_Package(std::vector<GlobalTargetInfo>& targets);
  470. void AddGlobalTarget_PackageSource(std::vector<GlobalTargetInfo>& targets);
  471. void AddGlobalTarget_Test(std::vector<GlobalTargetInfo>& targets);
  472. void AddGlobalTarget_EditCache(std::vector<GlobalTargetInfo>& targets) const;
  473. void AddGlobalTarget_RebuildCache(
  474. std::vector<GlobalTargetInfo>& targets) const;
  475. void AddGlobalTarget_Install(std::vector<GlobalTargetInfo>& targets);
  476. void CreateGlobalTarget(GlobalTargetInfo const& gti, cmMakefile* mf);
  477. std::string FindMakeProgramFile;
  478. std::string ConfiguredFilesPath;
  479. cmake* CMakeInstance;
  480. std::vector<std::unique_ptr<cmMakefile>> Makefiles;
  481. LocalGeneratorVector LocalGenerators;
  482. cmMakefile* CurrentConfigureMakefile;
  483. // map from project name to vector of local generators in that project
  484. std::map<std::string, std::vector<cmLocalGenerator*>> ProjectMap;
  485. // Set of named installation components requested by the project.
  486. std::set<std::string> InstallComponents;
  487. // Sets of named target exports
  488. cmExportSetMap ExportSets;
  489. std::map<std::string, cmExportBuildFileGenerator*> BuildExportSets;
  490. std::map<std::string, cmExportBuildFileGenerator*> BuildExportExportSets;
  491. std::map<std::string, std::string> AliasTargets;
  492. cmTarget* FindTargetImpl(std::string const& name) const;
  493. cmGeneratorTarget* FindGeneratorTargetImpl(std::string const& name) const;
  494. std::string GetPredefinedTargetsFolder() const;
  495. enum class FindMakeProgramStage
  496. {
  497. Early,
  498. Late,
  499. };
  500. virtual FindMakeProgramStage GetFindMakeProgramStage() const
  501. {
  502. return FindMakeProgramStage::Late;
  503. }
  504. private:
  505. using TargetMap = std::unordered_map<std::string, cmTarget*>;
  506. using GeneratorTargetMap =
  507. std::unordered_map<std::string, cmGeneratorTarget*>;
  508. using MakefileMap = std::unordered_map<std::string, cmMakefile*>;
  509. using LocalGeneratorMap = std::unordered_map<std::string, cmLocalGenerator*>;
  510. // Map efficiently from target name to cmTarget instance.
  511. // Do not use this structure for looping over all targets.
  512. // It contains both normal and globally visible imported targets.
  513. TargetMap TargetSearchIndex;
  514. GeneratorTargetMap GeneratorTargetSearchIndex;
  515. // Map efficiently from source directory path to cmMakefile instance.
  516. // Do not use this structure for looping over all directories.
  517. // It may not contain all of them (see note in IndexMakefile method).
  518. MakefileMap MakefileSearchIndex;
  519. // Map efficiently from source directory path to cmLocalGenerator instance.
  520. // Do not use this structure for looping over all directories.
  521. // Its order is not deterministic.
  522. LocalGeneratorMap LocalGeneratorSearchIndex;
  523. void ComputeTargetOrder();
  524. void ComputeTargetOrder(cmGeneratorTarget const* gt, size_t& index);
  525. std::map<cmGeneratorTarget const*, size_t> TargetOrderIndex;
  526. cmMakefile* TryCompileOuterMakefile;
  527. // If you add a new map here, make sure it is copied
  528. // in EnableLanguagesFromGenerator
  529. std::map<std::string, bool> IgnoreExtensions;
  530. std::set<std::string> LanguagesReady; // Ready for try_compile
  531. std::set<std::string> LanguagesInProgress;
  532. std::map<std::string, std::string> OutputExtensions;
  533. std::map<std::string, std::string> LanguageToOutputExtension;
  534. std::map<std::string, std::string> ExtensionToLanguage;
  535. std::map<std::string, int> LanguageToLinkerPreference;
  536. std::map<std::string, std::string> LanguageToOriginalSharedLibFlags;
  537. // Deferral id generation.
  538. size_t NextDeferId = 0;
  539. // Record hashes for rules and outputs.
  540. struct RuleHash
  541. {
  542. char Data[32];
  543. };
  544. std::map<std::string, RuleHash> RuleHashes;
  545. void CheckRuleHashes();
  546. void CheckRuleHashes(std::string const& pfile, std::string const& home);
  547. void WriteRuleHashes(std::string const& pfile);
  548. void WriteSummary();
  549. void WriteSummary(cmGeneratorTarget* target);
  550. void FinalizeTargetCompileInfo();
  551. virtual void ForceLinkerLanguages();
  552. bool CheckTargetsForMissingSources() const;
  553. bool CheckTargetsForType() const;
  554. bool CheckTargetsForPchCompilePdb() const;
  555. void CreateLocalGenerators();
  556. void CheckCompilerIdCompatibility(cmMakefile* mf,
  557. std::string const& lang) const;
  558. void ComputeBuildFileGenerators();
  559. std::unique_ptr<cmExternalMakefileProjectGenerator> ExtraGenerator;
  560. // track files replaced during a Generate
  561. std::vector<std::string> FilesReplacedDuringGenerate;
  562. // Store computed inter-target dependencies.
  563. using TargetDependMap = std::map<cmGeneratorTarget const*, TargetDependSet>;
  564. TargetDependMap TargetDependencies;
  565. friend class cmake;
  566. void CreateGeneratorTargets(
  567. TargetTypes targetTypes, cmMakefile* mf, cmLocalGenerator* lg,
  568. std::map<cmTarget*, cmGeneratorTarget*> const& importedMap);
  569. void CreateGeneratorTargets(TargetTypes targetTypes);
  570. void ClearGeneratorMembers();
  571. bool CheckCMP0037(std::string const& targetName,
  572. std::string const& reason) const;
  573. void IndexMakefile(cmMakefile* mf);
  574. void IndexLocalGenerator(cmLocalGenerator* lg);
  575. virtual const char* GetBuildIgnoreErrorsFlag() const { return nullptr; }
  576. bool UnsupportedVariableIsDefined(const std::string& name,
  577. bool supported) const;
  578. // Cache directory content and target files to be built.
  579. struct DirectoryContent
  580. {
  581. long LastDiskTime = -1;
  582. std::set<std::string> All;
  583. std::set<std::string> Generated;
  584. };
  585. std::map<std::string, DirectoryContent> DirectoryContentMap;
  586. // Set of binary directories on disk.
  587. std::set<std::string> BinaryDirectories;
  588. // track targets to issue CMP0042 warning for.
  589. std::set<std::string> CMP0042WarnTargets;
  590. // track targets to issue CMP0068 warning for.
  591. std::set<std::string> CMP0068WarnTargets;
  592. mutable std::map<cmSourceFile*, std::set<cmGeneratorTarget const*>>
  593. FilenameTargetDepends;
  594. std::map<std::string, std::string> RealPaths;
  595. std::unordered_set<std::string> GeneratedFiles;
  596. std::vector<std::unique_ptr<cmInstallRuntimeDependencySet>>
  597. RuntimeDependencySets;
  598. std::map<std::string, cmInstallRuntimeDependencySet*>
  599. RuntimeDependencySetsByName;
  600. #if !defined(CMAKE_BOOTSTRAP)
  601. // Pool of file locks
  602. cmFileLockPool FileLockPool;
  603. #endif
  604. protected:
  605. float FirstTimeProgress;
  606. bool NeedSymbolicMark;
  607. bool UseLinkScript;
  608. bool ForceUnixPaths;
  609. bool ToolSupportsColor;
  610. bool InstallTargetEnabled;
  611. bool ConfigureDoneCMP0026AndCMP0024;
  612. };