cmGlobalGenerator.h 25 KB

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