CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmGlobalGenerator.h
blob1ca02d9a8f66f5715847b8f9f09748a4b277e16e
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
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <cstddef>
8 #include <iosfwd>
9 #include <map>
10 #include <memory>
11 #include <set>
12 #include <string>
13 #include <unordered_map>
14 #include <unordered_set>
15 #include <utility>
16 #include <vector>
18 #include <cm/optional>
19 #include <cmext/algorithm>
20 #include <cmext/string_view>
22 #include "cmBuildOptions.h"
23 #include "cmCustomCommandLines.h"
24 #include "cmDuration.h"
25 #include "cmExportSet.h"
26 #include "cmLocalGenerator.h"
27 #include "cmStateSnapshot.h"
28 #include "cmStringAlgorithms.h"
29 #include "cmSystemTools.h"
30 #include "cmTarget.h"
31 #include "cmTargetDepend.h"
32 #include "cmValue.h"
34 #if !defined(CMAKE_BOOTSTRAP)
35 # include <cm3p/json/value.h>
37 # include "cmFileLockPool.h"
38 #endif
40 #define CMAKE_DIRECTORY_ID_SEP "::@"
42 enum class cmDepfileFormat;
43 enum class codecvt_Encoding;
45 class cmDirectoryId;
46 class cmExportBuildFileGenerator;
47 class cmExternalMakefileProjectGenerator;
48 class cmGeneratorTarget;
49 class cmInstallRuntimeDependencySet;
50 class cmLinkLineComputer;
51 class cmMakefile;
52 class cmOutputConverter;
53 class cmQtAutoGenGlobalInitializer;
54 class cmSourceFile;
55 class cmState;
56 class cmStateDirectory;
57 class cmake;
59 namespace detail {
60 inline void AppendStrs(std::vector<std::string>&)
63 template <typename T, typename... Ts>
64 inline void AppendStrs(std::vector<std::string>& command, T&& s, Ts&&... ts)
66 command.emplace_back(std::forward<T>(s));
67 AppendStrs(command, std::forward<Ts>(ts)...);
70 struct GeneratedMakeCommand
72 // Add each argument as a separate element to the vector
73 template <typename... T>
74 void Add(T&&... args)
76 // iterate the args and append each one
77 AppendStrs(this->PrimaryCommand, std::forward<T>(args)...);
80 // Add each value in the iterators as a separate element to the vector
81 void Add(std::vector<std::string>::const_iterator start,
82 std::vector<std::string>::const_iterator end)
84 cm::append(this->PrimaryCommand, start, end);
87 std::string Printable() const { return cmJoin(this->PrimaryCommand, " "); }
88 std::string QuotedPrintable() const;
90 std::vector<std::string> PrimaryCommand;
91 bool RequiresOutputForward = false;
95 /** \class cmGlobalGenerator
96 * \brief Responsible for overseeing the generation process for the entire tree
98 * Subclasses of this class generate makefiles for various
99 * platforms.
101 class cmGlobalGenerator
103 public:
104 using LocalGeneratorVector = std::vector<std::unique_ptr<cmLocalGenerator>>;
106 //! Free any memory allocated with the GlobalGenerator
107 cmGlobalGenerator(cmake* cm);
108 virtual ~cmGlobalGenerator();
110 virtual std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
111 cmMakefile* mf);
113 //! Get the name for this generator
114 virtual std::string GetName() const { return "Generic"; }
116 /** Check whether the given name matches the current generator. */
117 virtual bool MatchesGeneratorName(const std::string& name) const
119 return this->GetName() == name;
122 /** Get encoding used by generator for makefile files */
123 virtual codecvt_Encoding GetMakefileEncoding() const;
125 #if !defined(CMAKE_BOOTSTRAP)
126 /** Get a JSON object describing the generator. */
127 virtual Json::Value GetJson() const;
128 #endif
130 /** Tell the generator about the target system. */
131 virtual bool SetSystemName(std::string const&, cmMakefile*) { return true; }
133 /** Set the generator-specific instance. Returns true if supported. */
134 virtual bool SetGeneratorInstance(std::string const& i, cmMakefile* mf);
136 /** Set the generator-specific platform name. Returns true if platform
137 is supported and false otherwise. */
138 virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf);
140 /** Set the generator-specific toolset name. Returns true if toolset
141 is supported and false otherwise. */
142 virtual bool SetGeneratorToolset(std::string const& ts, bool build,
143 cmMakefile* mf);
145 /** Read any other cache entries needed for cmake --build. */
146 virtual bool ReadCacheEntriesForBuild(const cmState& /*state*/)
148 return true;
152 * Create LocalGenerators and process the CMakeLists files. This does not
153 * actually produce any makefiles, DSPs, etc.
155 virtual void Configure();
157 virtual bool InspectConfigTypeVariables() { return true; }
159 enum class CxxModuleSupportQuery
161 // Support is expected at the call site.
162 Expected,
163 // The call site is querying for support and handles problems by itself.
164 Inspect,
166 virtual bool CheckCxxModuleSupport(CxxModuleSupportQuery /*query*/)
168 return false;
171 virtual bool IsGNUMakeJobServerAware() const { return false; }
173 bool Compute();
174 virtual void AddExtraIDETargets() {}
176 enum TargetTypes
178 AllTargets,
179 ImportedOnly
182 void CreateImportedGenerationObjects(
183 cmMakefile* mf, std::vector<std::string> const& targets,
184 std::vector<cmGeneratorTarget const*>& exports);
185 void CreateGenerationObjects(TargetTypes targetTypes = AllTargets);
188 * Generate the all required files for building this project/tree. This
189 * basically creates a series of LocalGenerators for each directory and
190 * requests that they Generate.
192 virtual void Generate();
194 virtual std::unique_ptr<cmLinkLineComputer> CreateLinkLineComputer(
195 cmOutputConverter* outputConverter,
196 cmStateDirectory const& stateDir) const;
198 std::unique_ptr<cmLinkLineComputer> CreateMSVC60LinkLineComputer(
199 cmOutputConverter* outputConverter,
200 cmStateDirectory const& stateDir) const;
203 * Set/Get and Clear the enabled languages.
205 void SetLanguageEnabled(const std::string&, cmMakefile* mf);
206 bool GetLanguageEnabled(const std::string&) const;
207 void ClearEnabledLanguages();
208 void GetEnabledLanguages(std::vector<std::string>& lang) const;
210 * Try to determine system information such as shared library
211 * extension, pthreads, byte order etc.
213 virtual void EnableLanguage(std::vector<std::string> const& languages,
214 cmMakefile*, bool optional);
217 * Resolve the CMAKE_<lang>_COMPILER setting for the given language.
218 * Intended to be called from EnableLanguage.
220 void ResolveLanguageCompiler(const std::string& lang, cmMakefile* mf,
221 bool optional) const;
224 * Try to determine system information, get it from another generator
226 void EnableLanguagesFromGenerator(cmGlobalGenerator* gen, cmMakefile* mf);
229 * Try running cmake and building a file. This is used for dynamically
230 * loaded commands, not as part of the usual build process.
232 int TryCompile(int jobs, const std::string& srcdir,
233 const std::string& bindir, const std::string& projectName,
234 const std::string& targetName, bool fast, std::string& output,
235 cmMakefile* mf);
238 * Build a file given the following information. This is a more direct call
239 * that is used by both CTest and TryCompile. If target name is NULL or
240 * empty then all is assumed. clean indicates if a "make clean" should be
241 * done first.
243 int Build(
244 int jobs, const std::string& srcdir, const std::string& bindir,
245 const std::string& projectName,
246 std::vector<std::string> const& targetNames, std::ostream& ostr,
247 const std::string& makeProgram, const std::string& config,
248 const cmBuildOptions& buildOptions, bool verbose, cmDuration timeout,
249 cmSystemTools::OutputOption outputflag = cmSystemTools::OUTPUT_NONE,
250 std::vector<std::string> const& nativeOptions =
251 std::vector<std::string>());
254 * Open a generated IDE project given the following information.
256 virtual bool Open(const std::string& bindir, const std::string& projectName,
257 bool dryRun);
259 struct GeneratedMakeCommand final : public detail::GeneratedMakeCommand
263 virtual std::vector<GeneratedMakeCommand> GenerateBuildCommand(
264 const std::string& makeProgram, const std::string& projectName,
265 const std::string& projectDir, std::vector<std::string> const& targetNames,
266 const std::string& config, int jobs, bool verbose,
267 const cmBuildOptions& buildOptions = cmBuildOptions(),
268 std::vector<std::string> const& makeOptions = std::vector<std::string>());
270 virtual void PrintBuildCommandAdvice(std::ostream& os, int jobs) const;
273 * Generate a "cmake --build" call for a given target, config and parallel
274 * level.
276 std::string GenerateCMakeBuildCommand(const std::string& target,
277 const std::string& config,
278 const std::string& parallel,
279 const std::string& native,
280 bool ignoreErrors);
282 //! Get the CMake instance
283 cmake* GetCMakeInstance() const { return this->CMakeInstance; }
285 void SetConfiguredFilesPath(cmGlobalGenerator* gen);
286 const std::vector<std::unique_ptr<cmMakefile>>& GetMakefiles() const
288 return this->Makefiles;
290 const LocalGeneratorVector& GetLocalGenerators() const
292 return this->LocalGenerators;
295 std::vector<cmGeneratorTarget*> GetLocalGeneratorTargetsInOrder(
296 cmLocalGenerator* lg) const;
298 cmMakefile* GetCurrentMakefile() const
300 return this->CurrentConfigureMakefile;
303 void SetCurrentMakefile(cmMakefile* mf)
305 this->CurrentConfigureMakefile = mf;
308 void AddMakefile(std::unique_ptr<cmMakefile> mf);
310 //! Set an generator for an "external makefile based project"
311 void SetExternalMakefileProjectGenerator(
312 std::unique_ptr<cmExternalMakefileProjectGenerator> extraGenerator);
314 std::string GetExtraGeneratorName() const;
316 void AddInstallComponent(const std::string& component);
318 /** Mark the (absolute path to a) file as generated. */
319 void MarkAsGeneratedFile(const std::string& filepath);
320 /** Determine if the absolute filepath belongs to a generated file. */
321 bool IsGeneratedFile(const std::string& filepath);
323 const std::set<std::string>* GetInstallComponents() const
325 return &this->InstallComponents;
328 cmExportSetMap& GetExportSets() { return this->ExportSets; }
330 cmValue GetGlobalSetting(std::string const& name) const;
331 bool GlobalSettingIsOn(std::string const& name) const;
332 std::string GetSafeGlobalSetting(std::string const& name) const;
334 /** Add a file to the manifest of generated targets for a configuration. */
335 void AddToManifest(std::string const& f);
337 void EnableInstallTarget();
339 cmDuration TryCompileTimeout;
341 bool GetForceUnixPaths() const { return this->ForceUnixPaths; }
342 bool GetToolSupportsColor() const { return this->ToolSupportsColor; }
344 //! return the language for the given extension
345 std::string GetLanguageFromExtension(const char* ext) const;
346 //! is an extension to be ignored
347 bool IgnoreFile(const char* ext) const;
348 //! What is the preference for linkers and this language (None or Preferred)
349 int GetLinkerPreference(const std::string& lang) const;
350 //! What is the object file extension for a given source file?
351 std::string GetLanguageOutputExtension(cmSourceFile const&) const;
352 //! What is the object file extension for a given language?
353 std::string GetLanguageOutputExtension(std::string const& lang) const;
355 //! What is the configurations directory variable called?
356 virtual const char* GetCMakeCFGIntDir() const { return "."; }
358 //! expand CFGIntDir for a configuration
359 virtual std::string ExpandCFGIntDir(const std::string& str,
360 const std::string& config) const;
362 /** Get whether the generator should use a script for link commands. */
363 bool GetUseLinkScript() const { return this->UseLinkScript; }
365 /** Get whether the generator should produce special marks on rules
366 producing symbolic (non-file) outputs. */
367 bool GetNeedSymbolicMark() const { return this->NeedSymbolicMark; }
370 * Determine what program to use for building the project.
372 virtual bool FindMakeProgram(cmMakefile*);
374 //! Find a target by name by searching the local generators.
375 cmTarget* FindTarget(const std::string& name,
376 bool excludeAliases = false) const;
378 cmGeneratorTarget* FindGeneratorTarget(const std::string& name) const;
380 void AddAlias(const std::string& name, const std::string& tgtName);
381 bool IsAlias(const std::string& name) const;
383 /** Determine if a name resolves to a framework on disk or a built target
384 that is a framework. */
385 bool NameResolvesToFramework(const std::string& libname) const;
386 /** Split a framework path to the directory and name of the framework as well
387 * as optional suffix.
388 * Returns std::nullopt if the path does not match with framework format
389 * when extendedFormat is true, required format is relaxed (i.e. extension
390 * `.framework' is optional). Used when FRAMEWORK link feature is
391 * specified */
392 struct FrameworkDescriptor
394 FrameworkDescriptor(std::string directory, std::string name)
395 : Directory(std::move(directory))
396 , Name(std::move(name))
399 FrameworkDescriptor(std::string directory, std::string version,
400 std::string name)
401 : Directory(std::move(directory))
402 , Version(std::move(version))
403 , Name(std::move(name))
406 FrameworkDescriptor(std::string directory, std::string version,
407 std::string name, std::string suffix)
408 : Directory(std::move(directory))
409 , Version(std::move(version))
410 , Name(std::move(name))
411 , Suffix(std::move(suffix))
414 std::string GetLinkName() const
416 return this->Suffix.empty() ? this->Name
417 : cmStrCat(this->Name, ',', this->Suffix);
419 std::string GetFullName() const
421 return cmStrCat(this->Name, ".framework/"_s, this->Name, this->Suffix);
423 std::string GetVersionedName() const
425 return this->Version.empty()
426 ? this->GetFullName()
427 : cmStrCat(this->Name, ".framework/Versions/"_s, this->Version, '/',
428 this->Name, this->Suffix);
430 std::string GetFrameworkPath() const
432 return this->Directory.empty()
433 ? cmStrCat(this->Name, ".framework"_s)
434 : cmStrCat(this->Directory, '/', this->Name, ".framework"_s);
436 std::string GetFullPath() const
438 return this->Directory.empty()
439 ? this->GetFullName()
440 : cmStrCat(this->Directory, '/', this->GetFullName());
442 std::string GetVersionedPath() const
444 return this->Directory.empty()
445 ? this->GetVersionedName()
446 : cmStrCat(this->Directory, '/', this->GetVersionedName());
449 const std::string Directory;
450 const std::string Version;
451 const std::string Name;
452 const std::string Suffix;
454 enum class FrameworkFormat
456 Strict,
457 Relaxed,
458 Extended
460 cm::optional<FrameworkDescriptor> SplitFrameworkPath(
461 const std::string& path,
462 FrameworkFormat format = FrameworkFormat::Relaxed) const;
464 cmMakefile* FindMakefile(const std::string& start_dir) const;
465 cmLocalGenerator* FindLocalGenerator(cmDirectoryId const& id) const;
467 /** Append the subdirectory for the given configuration. If anything is
468 appended the given prefix and suffix will be appended around it, which
469 is useful for leading or trailing slashes. */
470 virtual void AppendDirectoryForConfig(const std::string& prefix,
471 const std::string& config,
472 const std::string& suffix,
473 std::string& dir);
475 /** Get the content of a directory. Directory listings are cached
476 and re-loaded from disk only when modified. During the generation
477 step the content will include the target files to be built even if
478 they do not yet exist. */
479 std::set<std::string> const& GetDirectoryContent(std::string const& dir,
480 bool needDisk = true);
482 void IndexTarget(cmTarget* t);
483 void IndexGeneratorTarget(cmGeneratorTarget* gt);
485 // Index the target using a name that is unique to that target
486 // even if other targets have the same name.
487 std::string IndexGeneratorTargetUniquely(cmGeneratorTarget const* gt);
489 static bool IsReservedTarget(std::string const& name);
491 virtual const char* GetAllTargetName() const { return "ALL_BUILD"; }
492 virtual const char* GetInstallTargetName() const { return "INSTALL"; }
493 virtual const char* GetInstallLocalTargetName() const { return nullptr; }
494 virtual const char* GetInstallStripTargetName() const { return nullptr; }
495 virtual const char* GetPreinstallTargetName() const { return nullptr; }
496 virtual const char* GetTestTargetName() const { return "RUN_TESTS"; }
497 virtual const char* GetPackageTargetName() const { return "PACKAGE"; }
498 virtual const char* GetPackageSourceTargetName() const { return nullptr; }
499 virtual const char* GetEditCacheTargetName() const { return nullptr; }
500 virtual const char* GetRebuildCacheTargetName() const { return nullptr; }
501 virtual const char* GetCleanTargetName() const { return nullptr; }
503 // Lookup edit_cache target command preferred by this generator.
504 virtual std::string GetEditCacheCommand() const { return ""; }
506 // Default config to use for cmake --build
507 virtual std::string GetDefaultBuildConfig() const { return "Debug"; }
509 // Class to track a set of dependencies.
510 using TargetDependSet = cmTargetDependSet;
512 // what targets does the specified target depend on directly
513 // via a target_link_libraries or add_dependencies
514 TargetDependSet const& GetTargetDirectDepends(
515 const cmGeneratorTarget* target);
517 // Return true if target 'l' occurs before 'r' in a global ordering
518 // of targets that respects inter-target dependencies.
519 bool TargetOrderIndexLess(cmGeneratorTarget const* l,
520 cmGeneratorTarget const* r) const;
522 const std::map<std::string, std::vector<cmLocalGenerator*>>& GetProjectMap()
523 const
525 return this->ProjectMap;
528 // track files replaced during a Generate
529 void FileReplacedDuringGenerate(const std::string& filename);
530 void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
532 void AddRuleHash(const std::vector<std::string>& outputs,
533 std::string const& content);
535 /** Return whether the given binary directory is unused. */
536 bool BinaryDirectoryIsNew(const std::string& dir)
538 return this->BinaryDirectories.insert(dir).second;
541 /** Return true if the generated build tree may contain multiple builds.
542 i.e. "Can I build Debug and Release in the same tree?" */
543 virtual bool IsMultiConfig() const { return false; }
545 virtual bool IsXcode() const { return false; }
547 virtual bool IsVisualStudio() const { return false; }
549 virtual bool IsVisualStudioAtLeast10() const { return false; }
551 virtual bool IsNinja() const { return false; }
553 /** Return true if we know the exact location of object files for the given
554 cmTarget. If false, store the reason in the given string. This is
555 meaningful only after EnableLanguage has been called. */
556 virtual bool HasKnownObjectFileLocation(cmTarget const&, std::string*) const
558 return true;
561 virtual bool UseFolderProperty() const;
563 virtual bool IsIPOSupported() const { return false; }
565 /** Return whether the generator can import external visual studio project
566 using INCLUDE_EXTERNAL_MSPROJECT */
567 virtual bool IsIncludeExternalMSProjectSupported() const { return false; }
569 /** Return whether the generator should use EFFECTIVE_PLATFORM_NAME. This is
570 relevant for mixed macOS and iOS builds. */
571 virtual bool UseEffectivePlatformName(cmMakefile*) const { return false; }
573 /** Return whether the "Resources" folder prefix should be stripped from
574 MacFolder. */
575 virtual bool ShouldStripResourcePath(cmMakefile*) const;
577 virtual bool SupportsCustomCommandDepfile() const { return false; }
578 virtual cm::optional<cmDepfileFormat> DepfileFormat() const
580 return cm::nullopt;
583 virtual bool SupportsLinkerDependencyFile() const { return false; }
585 std::string GetSharedLibFlagsForLanguage(std::string const& lang) const;
587 /** Generate an <output>.rule file path for a given command output. */
588 virtual std::string GenerateRuleFile(std::string const& output) const;
590 virtual bool SupportsDefaultBuildType() const { return false; }
591 virtual bool SupportsCrossConfigs() const { return false; }
592 virtual bool SupportsDefaultConfigs() const { return false; }
594 static std::string EscapeJSON(const std::string& s);
596 void ProcessEvaluationFiles();
598 std::map<std::string, cmExportBuildFileGenerator*>& GetBuildExportSets()
600 return this->BuildExportSets;
602 void AddBuildExportSet(cmExportBuildFileGenerator* gen);
603 void AddBuildExportExportSet(cmExportBuildFileGenerator* gen);
604 bool IsExportedTargetsFile(const std::string& filename) const;
605 bool GenerateImportFile(const std::string& file);
606 cmExportBuildFileGenerator* GetExportedTargetsFile(
607 const std::string& filename) const;
608 void AddCMP0042WarnTarget(const std::string& target);
609 void AddCMP0068WarnTarget(const std::string& target);
611 virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
613 bool GenerateCPackPropertiesFile();
615 void SetFilenameTargetDepends(
616 cmSourceFile* sf, std::set<cmGeneratorTarget const*> const& tgts);
617 const std::set<const cmGeneratorTarget*>& GetFilenameTargetDepends(
618 cmSourceFile* sf) const;
620 #if !defined(CMAKE_BOOTSTRAP)
621 cmFileLockPool& GetFileLockPool() { return this->FileLockPool; }
622 #endif
624 bool GetConfigureDoneCMP0026() const
626 return this->ConfigureDoneCMP0026AndCMP0024;
629 std::string MakeSilentFlag;
631 size_t RecursionDepth = 0;
633 virtual void GetQtAutoGenConfigs(std::vector<std::string>& configs) const
635 configs.emplace_back("$<CONFIG>");
638 std::string const& GetRealPath(std::string const& dir);
640 std::string NewDeferId();
642 cmInstallRuntimeDependencySet* CreateAnonymousRuntimeDependencySet();
644 cmInstallRuntimeDependencySet* GetNamedRuntimeDependencySet(
645 const std::string& name);
647 enum class StripCommandStyle
649 Default,
650 Apple,
652 StripCommandStyle GetStripCommandStyle(std::string const& strip);
654 virtual std::string& EncodeLiteral(std::string& lit) { return lit; }
656 protected:
657 // for a project collect all its targets by following depend
658 // information, and also collect all the targets
659 void GetTargetSets(TargetDependSet& projectTargets,
660 TargetDependSet& originalTargets, cmLocalGenerator* root,
661 std::vector<cmLocalGenerator*>& generators);
662 bool IsRootOnlyTarget(cmGeneratorTarget* target) const;
663 void AddTargetDepends(const cmGeneratorTarget* target,
664 TargetDependSet& projectTargets);
665 void SetLanguageEnabledFlag(const std::string& l, cmMakefile* mf);
666 void SetLanguageEnabledMaps(const std::string& l, cmMakefile* mf);
667 void FillExtensionToLanguageMap(const std::string& l, cmMakefile* mf);
668 virtual bool CheckLanguages(std::vector<std::string> const& languages,
669 cmMakefile* mf) const;
670 virtual void PrintCompilerAdvice(std::ostream& os, std::string const& lang,
671 cmValue envVar) const;
673 virtual bool ComputeTargetDepends();
675 virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const;
677 bool ApplyCXXStdTargets();
678 bool DiscoverSyntheticTargets();
680 bool AddHeaderSetVerification();
682 void CreateFileGenerateOutputs();
683 bool AddAutomaticSources();
685 std::string SelectMakeProgram(const std::string& makeProgram,
686 const std::string& makeDefault = "") const;
688 // Fill the ProjectMap, this must be called after LocalGenerators
689 // has been populated.
690 void FillProjectMap();
691 void CheckTargetProperties();
692 bool IsExcluded(cmStateSnapshot const& root,
693 cmStateSnapshot const& snp) const;
694 bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen) const;
695 bool IsExcluded(cmLocalGenerator* root,
696 const cmGeneratorTarget* target) const;
697 virtual void InitializeProgressMarks() {}
699 struct GlobalTargetInfo
701 std::string Name;
702 std::string Message;
703 cmCustomCommandLines CommandLines;
704 std::vector<std::string> Depends;
705 std::string WorkingDir;
706 bool UsesTerminal = false;
707 cmTarget::PerConfig PerConfig = cmTarget::PerConfig::Yes;
708 bool StdPipesUTF8 = false;
711 void CreateDefaultGlobalTargets(std::vector<GlobalTargetInfo>& targets);
713 void AddGlobalTarget_Package(std::vector<GlobalTargetInfo>& targets);
714 void AddGlobalTarget_PackageSource(std::vector<GlobalTargetInfo>& targets);
715 void AddGlobalTarget_Test(std::vector<GlobalTargetInfo>& targets);
716 void AddGlobalTarget_EditCache(std::vector<GlobalTargetInfo>& targets) const;
717 void AddGlobalTarget_RebuildCache(
718 std::vector<GlobalTargetInfo>& targets) const;
719 void AddGlobalTarget_Install(std::vector<GlobalTargetInfo>& targets);
720 void CreateGlobalTarget(GlobalTargetInfo const& gti, cmMakefile* mf);
722 std::string FindMakeProgramFile;
723 std::string ConfiguredFilesPath;
724 cmake* CMakeInstance;
725 std::vector<std::unique_ptr<cmMakefile>> Makefiles;
726 LocalGeneratorVector LocalGenerators;
728 #ifndef CMAKE_BOOTSTRAP
729 std::unique_ptr<cmQtAutoGenGlobalInitializer> QtAutoGen;
730 #endif
732 cmMakefile* CurrentConfigureMakefile;
733 // map from project name to vector of local generators in that project
734 std::map<std::string, std::vector<cmLocalGenerator*>> ProjectMap;
736 // Set of named installation components requested by the project.
737 std::set<std::string> InstallComponents;
738 // Sets of named target exports
739 cmExportSetMap ExportSets;
740 std::map<std::string, cmExportBuildFileGenerator*> BuildExportSets;
741 std::map<std::string, cmExportBuildFileGenerator*> BuildExportExportSets;
743 std::map<std::string, std::string> AliasTargets;
745 cmTarget* FindTargetImpl(std::string const& name) const;
747 cmGeneratorTarget* FindGeneratorTargetImpl(std::string const& name) const;
749 std::string GetPredefinedTargetsFolder() const;
751 private:
752 using TargetMap = std::unordered_map<std::string, cmTarget*>;
753 using GeneratorTargetMap =
754 std::unordered_map<std::string, cmGeneratorTarget*>;
755 using MakefileMap = std::unordered_map<std::string, cmMakefile*>;
756 using LocalGeneratorMap = std::unordered_map<std::string, cmLocalGenerator*>;
757 // Map efficiently from target name to cmTarget instance.
758 // Do not use this structure for looping over all targets.
759 // It contains both normal and globally visible imported targets.
760 TargetMap TargetSearchIndex;
761 GeneratorTargetMap GeneratorTargetSearchIndex;
763 // Map efficiently from source directory path to cmMakefile instance.
764 // Do not use this structure for looping over all directories.
765 // It may not contain all of them (see note in IndexMakefile method).
766 MakefileMap MakefileSearchIndex;
768 // Map efficiently from source directory path to cmLocalGenerator instance.
769 // Do not use this structure for looping over all directories.
770 // Its order is not deterministic.
771 LocalGeneratorMap LocalGeneratorSearchIndex;
773 void ComputeTargetOrder();
774 void ComputeTargetOrder(cmGeneratorTarget const* gt, size_t& index);
775 std::map<cmGeneratorTarget const*, size_t> TargetOrderIndex;
777 cmMakefile* TryCompileOuterMakefile;
778 // If you add a new map here, make sure it is copied
779 // in EnableLanguagesFromGenerator
780 std::map<std::string, bool> IgnoreExtensions;
781 std::set<std::string> LanguagesReady; // Ready for try_compile
782 std::set<std::string> LanguagesInProgress;
783 std::map<std::string, std::string> OutputExtensions;
784 std::map<std::string, std::string> LanguageToOutputExtension;
785 std::map<std::string, std::string> ExtensionToLanguage;
786 std::map<std::string, int> LanguageToLinkerPreference;
787 std::map<std::string, std::string> LanguageToOriginalSharedLibFlags;
789 #ifdef __APPLE__
790 std::map<std::string, StripCommandStyle> StripCommandStyleMap;
791 #endif
793 // Deferral id generation.
794 size_t NextDeferId = 0;
796 // Record hashes for rules and outputs.
797 struct RuleHash
799 char Data[32];
801 std::map<std::string, RuleHash> RuleHashes;
802 void CheckRuleHashes();
803 void CheckRuleHashes(std::string const& pfile, std::string const& home);
804 void WriteRuleHashes(std::string const& pfile);
806 void WriteSummary();
807 void WriteSummary(cmGeneratorTarget* target);
808 void FinalizeTargetConfiguration();
810 virtual void ForceLinkerLanguages();
812 void CheckTargetLinkLibraries() const;
813 bool CheckTargetsForMissingSources() const;
814 bool CheckTargetsForType() const;
815 bool CheckTargetsForPchCompilePdb() const;
817 void CreateLocalGenerators();
819 void CheckCompilerIdCompatibility(cmMakefile* mf,
820 std::string const& lang) const;
822 void ComputeBuildFileGenerators();
824 std::unique_ptr<cmExternalMakefileProjectGenerator> ExtraGenerator;
826 // track files replaced during a Generate
827 std::vector<std::string> FilesReplacedDuringGenerate;
829 // Store computed inter-target dependencies.
830 using TargetDependMap = std::map<cmGeneratorTarget const*, TargetDependSet>;
831 TargetDependMap TargetDependencies;
833 friend class cmake;
834 void CreateGeneratorTargets(
835 TargetTypes targetTypes, cmMakefile* mf, cmLocalGenerator* lg,
836 std::map<cmTarget*, cmGeneratorTarget*> const& importedMap);
837 void CreateGeneratorTargets(TargetTypes targetTypes);
839 void ClearGeneratorMembers();
841 bool CheckCMP0037(std::string const& targetName,
842 std::string const& reason) const;
844 void IndexMakefile(cmMakefile* mf);
845 void IndexLocalGenerator(cmLocalGenerator* lg);
847 virtual const char* GetBuildIgnoreErrorsFlag() const { return nullptr; }
849 bool UnsupportedVariableIsDefined(const std::string& name,
850 bool supported) const;
852 // Cache directory content and target files to be built.
853 struct DirectoryContent
855 long LastDiskTime = -1;
856 std::set<std::string> All;
857 std::set<std::string> Generated;
859 std::map<std::string, DirectoryContent> DirectoryContentMap;
861 // Set of binary directories on disk.
862 std::set<std::string> BinaryDirectories;
864 // track targets to issue CMP0042 warning for.
865 std::set<std::string> CMP0042WarnTargets;
866 // track targets to issue CMP0068 warning for.
867 std::set<std::string> CMP0068WarnTargets;
869 mutable std::map<cmSourceFile*, std::set<cmGeneratorTarget const*>>
870 FilenameTargetDepends;
872 std::map<std::string, std::string> RealPaths;
874 std::unordered_set<std::string> GeneratedFiles;
876 std::vector<std::unique_ptr<cmInstallRuntimeDependencySet>>
877 RuntimeDependencySets;
878 std::map<std::string, cmInstallRuntimeDependencySet*>
879 RuntimeDependencySetsByName;
881 #if !defined(CMAKE_BOOTSTRAP)
882 // Pool of file locks
883 cmFileLockPool FileLockPool;
884 #endif
886 protected:
887 float FirstTimeProgress;
888 bool NeedSymbolicMark;
889 bool UseLinkScript;
890 bool ForceUnixPaths;
891 bool ToolSupportsColor;
892 bool InstallTargetEnabled;
893 bool ConfigureDoneCMP0026AndCMP0024;