123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998 |
- /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
- file Copyright.txt or https://cmake.org/licensing for details. */
- #pragma once
- #include "cmConfigure.h" // IWYU pragma: keep
- #include <cstddef>
- #include <functional>
- #include <map>
- #include <memory>
- #include <set>
- #include <string>
- #include <unordered_set>
- #include <utility>
- #include <vector>
- #include <cm/string_view>
- #include <cmext/string_view>
- #include "cmDocumentationEntry.h" // IWYU pragma: keep
- #include "cmGeneratedFileStream.h"
- #include "cmGlobalGeneratorFactory.h"
- #include "cmInstalledFile.h"
- #include "cmListFileCache.h"
- #include "cmMessageType.h"
- #include "cmState.h"
- #include "cmStateSnapshot.h"
- #include "cmStateTypes.h"
- #include "cmValue.h"
- #if !defined(CMAKE_BOOTSTRAP)
- # include <type_traits>
- # include <cm/optional>
- # include <cm3p/json/value.h>
- # include "cmCMakePresetsGraph.h"
- # include "cmMakefileProfilingData.h"
- #endif
- class cmConfigureLog;
- #ifdef CMake_ENABLE_DEBUGGER
- namespace cmDebugger {
- class cmDebuggerAdapter;
- }
- #endif
- class cmExternalMakefileProjectGeneratorFactory;
- class cmFileAPI;
- class cmInstrumentation;
- class cmFileTimeCache;
- class cmGlobalGenerator;
- class cmMakefile;
- class cmMessenger;
- class cmVariableWatch;
- struct cmBuildOptions;
- struct cmGlobCacheEntry;
- /** \brief Represents a cmake invocation.
- *
- * This class represents a cmake invocation. It is the top level class when
- * running cmake. Most cmake based GUIs should primarily create an instance
- * of this class and communicate with it.
- *
- * The basic process for a GUI is as follows:
- *
- * -# Create a cmake instance
- * -# Set the Home directories, generator, and cmake command. this
- * can be done using the Set methods or by using SetArgs and passing in
- * command line arguments.
- * -# Load the cache by calling LoadCache (duh)
- * -# if you are using command line arguments with -D or -C flags then
- * call SetCacheArgs (or if for some other reason you want to modify the
- * cache), do it now.
- * -# Finally call Configure
- * -# Let the user change values and go back to step 5
- * -# call Generate
- * If your GUI allows the user to change the home directories then
- * you must at a minimum redo steps 2 through 7.
- */
- class cmake
- {
- public:
- enum Role
- {
- RoleInternal, // no commands
- RoleScript, // script commands
- RoleProject // all commands
- };
- enum DiagLevel
- {
- DIAG_IGNORE,
- DIAG_WARN,
- DIAG_ERROR
- };
- /** \brief Describes the working modes of cmake */
- enum WorkingMode
- {
- NORMAL_MODE, ///< Cmake runs to create project files
- /** \brief Script mode (started by using -P).
- *
- * In script mode there is no generator and no cache. Also,
- * languages are not enabled, so add_executable and things do
- * nothing.
- */
- SCRIPT_MODE,
- /** \brief Help mode
- *
- * Used to print help for things that can only be determined after finding
- * the source directory, for example, the list of presets.
- */
- HELP_MODE,
- /** \brief A pkg-config like mode
- *
- * In this mode cmake just searches for a package and prints the results to
- * stdout. This is similar to SCRIPT_MODE, but commands like add_library()
- * work too, since they may be used e.g. in exported target files. Started
- * via --find-package.
- */
- FIND_PACKAGE_MODE
- };
- using TraceFormat = cmTraceEnums::TraceOutputFormat;
- struct GeneratorInfo
- {
- std::string name;
- std::string baseName;
- std::string extraName;
- bool supportsToolset;
- bool supportsPlatform;
- std::vector<std::string> supportedPlatforms;
- std::string defaultPlatform;
- bool isAlias;
- };
- struct FileExtensions
- {
- bool Test(cm::string_view ext) const
- {
- return (this->unordered.find(ext) != this->unordered.end());
- }
- std::vector<std::string> ordered;
- std::unordered_set<cm::string_view> unordered;
- };
- using InstalledFilesMap = std::map<std::string, cmInstalledFile>;
- static int const NO_BUILD_PARALLEL_LEVEL = -1;
- static int const DEFAULT_BUILD_PARALLEL_LEVEL = 0;
- /// Default constructor
- cmake(Role role, cmState::Mode mode,
- cmState::ProjectKind projectKind = cmState::ProjectKind::Normal);
- /// Destructor
- ~cmake();
- cmake(cmake const&) = delete;
- cmake& operator=(cmake const&) = delete;
- #if !defined(CMAKE_BOOTSTRAP)
- Json::Value ReportVersionJson() const;
- Json::Value ReportCapabilitiesJson() const;
- #endif
- std::string ReportCapabilities() const;
- /**
- * Set the home directory from `-S` or from a known location
- * that contains a CMakeLists.txt. Will generate warnings
- * when overriding an existing source directory.
- *
- * | args | src dir| warning |
- * | ----------------- | ------ | -------------- |
- * | `dirA dirA` | dirA | N/A |
- * | `-S dirA -S dirA` | dirA | N/A |
- * | `-S dirA -S dirB` | dirB | Ignoring dirA |
- * | `-S dirA dirB` | dirB | Ignoring dirA |
- * | `dirA -S dirB` | dirB | Ignoring dirA |
- * | `dirA dirB` | dirB | Ignoring dirA |
- */
- void SetHomeDirectoryViaCommandLine(std::string const& path);
- //@{
- /**
- * Set/Get the home directory (or output directory) in the project. The
- * home directory is the top directory of the project. It is the
- * path-to-source cmake was run with.
- */
- void SetHomeDirectory(std::string const& dir);
- std::string const& GetHomeDirectory() const;
- void SetHomeOutputDirectory(std::string const& dir);
- std::string const& GetHomeOutputDirectory() const;
- //@}
- /**
- * Working directory at CMake launch
- */
- std::string const& GetCMakeWorkingDirectory() const
- {
- return this->CMakeWorkingDirectory;
- }
- /**
- * Handle a command line invocation of cmake.
- */
- int Run(std::vector<std::string> const& args)
- {
- return this->Run(args, false);
- }
- int Run(std::vector<std::string> const& args, bool noconfigure);
- /**
- * Run the global generator Generate step.
- */
- int Generate();
- /**
- * Configure the cmMakefiles. This routine will create a GlobalGenerator if
- * one has not already been set. It will then Call Configure on the
- * GlobalGenerator. This in turn will read in an process all the CMakeList
- * files for the tree. It will not produce any actual Makefiles, or
- * workspaces. Generate does that. */
- int Configure();
- int ActualConfigure();
- //! Break up a line like VAR:type="value" into var, type and value
- static bool ParseCacheEntry(std::string const& entry, std::string& var,
- std::string& value,
- cmStateEnums::CacheEntryType& type);
- int LoadCache();
- bool LoadCache(std::string const& path);
- bool LoadCache(std::string const& path, bool internal,
- std::set<std::string>& excludes,
- std::set<std::string>& includes);
- bool SaveCache(std::string const& path);
- bool DeleteCache(std::string const& path);
- void PreLoadCMakeFiles();
- //! Create a GlobalGenerator
- std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator(
- std::string const& name);
- //! Create a GlobalGenerator and set it as our own
- bool CreateAndSetGlobalGenerator(std::string const& name);
- #ifndef CMAKE_BOOTSTRAP
- //! Print list of configure presets
- void PrintPresetList(cmCMakePresetsGraph const& graph) const;
- #endif
- //! Return the global generator assigned to this instance of cmake
- cmGlobalGenerator* GetGlobalGenerator()
- {
- return this->GlobalGenerator.get();
- }
- //! Return the global generator assigned to this instance of cmake, const
- cmGlobalGenerator const* GetGlobalGenerator() const
- {
- return this->GlobalGenerator.get();
- }
- //! Return the full path to where the CMakeCache.txt file should be.
- static std::string FindCacheFile(std::string const& binaryDir);
- //! Return the global generator assigned to this instance of cmake
- void SetGlobalGenerator(std::unique_ptr<cmGlobalGenerator>);
- //! Get the names of the current registered generators
- void GetRegisteredGenerators(std::vector<GeneratorInfo>& generators) const;
- //! Set the name of the selected generator-specific instance.
- void SetGeneratorInstance(std::string const& instance)
- {
- this->GeneratorInstance = instance;
- this->GeneratorInstanceSet = true;
- }
- //! Set the name of the selected generator-specific platform.
- void SetGeneratorPlatform(std::string const& ts)
- {
- this->GeneratorPlatform = ts;
- this->GeneratorPlatformSet = true;
- }
- //! Set the name of the selected generator-specific toolset.
- void SetGeneratorToolset(std::string const& ts)
- {
- this->GeneratorToolset = ts;
- this->GeneratorToolsetSet = true;
- }
- //! Set the name of the graphviz file.
- void SetGraphVizFile(std::string const& ts) { this->GraphVizFile = ts; }
- bool IsAKnownSourceExtension(cm::string_view ext) const
- {
- return this->CLikeSourceFileExtensions.Test(ext) ||
- this->CudaFileExtensions.Test(ext) ||
- this->FortranFileExtensions.Test(ext) ||
- this->HipFileExtensions.Test(ext) || this->ISPCFileExtensions.Test(ext);
- }
- bool IsACLikeSourceExtension(cm::string_view ext) const
- {
- return this->CLikeSourceFileExtensions.Test(ext);
- }
- bool IsAKnownExtension(cm::string_view ext) const
- {
- return this->IsAKnownSourceExtension(ext) || this->IsAHeaderExtension(ext);
- }
- std::vector<std::string> GetAllExtensions() const;
- std::vector<std::string> const& GetHeaderExtensions() const
- {
- return this->HeaderFileExtensions.ordered;
- }
- bool IsAHeaderExtension(cm::string_view ext) const
- {
- return this->HeaderFileExtensions.Test(ext);
- }
- // Strips the extension (if present and known) from a filename
- std::string StripExtension(std::string const& file) const;
- /**
- * Given a variable name, return its value (as a string).
- */
- cmValue GetCacheDefinition(std::string const&) const;
- //! Add an entry into the cache
- void AddCacheEntry(std::string const& key, std::string const& value,
- std::string const& helpString, int type)
- {
- this->AddCacheEntry(key, cmValue{ value }, cmValue{ helpString }, type);
- }
- void AddCacheEntry(std::string const& key, cmValue value,
- std::string const& helpString, int type)
- {
- this->AddCacheEntry(key, value, cmValue{ helpString }, type);
- }
- void AddCacheEntry(std::string const& key, cmValue value, cmValue helpString,
- int type);
- bool DoWriteGlobVerifyTarget() const;
- std::string const& GetGlobVerifyScript() const;
- std::string const& GetGlobVerifyStamp() const;
- void AddGlobCacheEntry(cmGlobCacheEntry const& entry,
- std::string const& variable,
- cmListFileBacktrace const& bt);
- std::vector<cmGlobCacheEntry> GetGlobCacheEntries() const;
- /**
- * Get the system information and write it to the file specified
- */
- int GetSystemInformation(std::vector<std::string>&);
- //! Parse environment variables
- void LoadEnvironmentPresets();
- //! Parse command line arguments
- void SetArgs(std::vector<std::string> const& args);
- //! Is this cmake running as a result of a TRY_COMPILE command
- bool GetIsInTryCompile() const;
- #ifndef CMAKE_BOOTSTRAP
- void SetWarningFromPreset(std::string const& name,
- cm::optional<bool> const& warning,
- cm::optional<bool> const& error);
- void ProcessPresetVariables();
- void PrintPresetVariables();
- void ProcessPresetEnvironment();
- void PrintPresetEnvironment();
- #endif
- //! Parse command line arguments that might set cache values
- bool SetCacheArgs(std::vector<std::string> const&);
- void ProcessCacheArg(std::string const& var, std::string const& value,
- cmStateEnums::CacheEntryType type);
- using ProgressCallbackType = std::function<void(std::string const&, float)>;
- /**
- * Set the function used by GUIs to receive progress updates
- * Function gets passed: message as a const char*, a progress
- * amount ranging from 0 to 1.0 and client data. The progress
- * number provided may be negative in cases where a message is
- * to be displayed without any progress percentage.
- */
- void SetProgressCallback(ProgressCallbackType f);
- //! this is called by generators to update the progress
- void UpdateProgress(std::string const& msg, float prog);
- #if !defined(CMAKE_BOOTSTRAP)
- //! Get the variable watch object
- cmVariableWatch* GetVariableWatch() { return this->VariableWatch.get(); }
- #endif
- std::vector<cmDocumentationEntry> GetGeneratorsDocumentation();
- //! Set/Get a property of this target file
- void SetProperty(std::string const& prop, cmValue value);
- void SetProperty(std::string const& prop, std::nullptr_t)
- {
- this->SetProperty(prop, cmValue{ nullptr });
- }
- void SetProperty(std::string const& prop, std::string const& value)
- {
- this->SetProperty(prop, cmValue(value));
- }
- void AppendProperty(std::string const& prop, std::string const& value,
- bool asString = false);
- cmValue GetProperty(std::string const& prop);
- bool GetPropertyAsBool(std::string const& prop);
- //! Get or create an cmInstalledFile instance and return a pointer to it
- cmInstalledFile* GetOrCreateInstalledFile(cmMakefile* mf,
- std::string const& name);
- cmInstalledFile const* GetInstalledFile(std::string const& name) const;
- InstalledFilesMap const& GetInstalledFiles() const
- {
- return this->InstalledFiles;
- }
- //! Do all the checks before running configure
- int DoPreConfigureChecks();
- void SetWorkingMode(WorkingMode mode) { this->CurrentWorkingMode = mode; }
- WorkingMode GetWorkingMode() { return this->CurrentWorkingMode; }
- //! Debug the try compile stuff by not deleting the files
- bool GetDebugTryCompile() const { return this->DebugTryCompile; }
- void DebugTryCompileOn() { this->DebugTryCompile = true; }
- /**
- * Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
- */
- int AddCMakePaths();
- /**
- * Get the file comparison class
- */
- cmFileTimeCache* GetFileTimeCache() { return this->FileTimeCache.get(); }
- bool WasLogLevelSetViaCLI() const { return this->LogLevelWasSetViaCLI; }
- //! Get the selected log level for `message()` commands during the cmake run.
- Message::LogLevel GetLogLevel() const { return this->MessageLogLevel; }
- void SetLogLevel(Message::LogLevel level) { this->MessageLogLevel = level; }
- static Message::LogLevel StringToLogLevel(cm::string_view levelStr);
- static std::string LogLevelToString(Message::LogLevel level);
- static TraceFormat StringToTraceFormat(std::string const& levelStr);
- bool HasCheckInProgress() const
- {
- return !this->CheckInProgressMessages.empty();
- }
- std::size_t GetCheckInProgressSize() const
- {
- return this->CheckInProgressMessages.size();
- }
- std::string GetTopCheckInProgressMessage()
- {
- auto message = this->CheckInProgressMessages.back();
- this->CheckInProgressMessages.pop_back();
- return message;
- }
- void PushCheckInProgressMessage(std::string message)
- {
- this->CheckInProgressMessages.emplace_back(std::move(message));
- }
- std::vector<std::string> const& GetCheckInProgressMessages() const
- {
- return this->CheckInProgressMessages;
- }
- //! Should `message` command display context.
- bool GetShowLogContext() const { return this->LogContext; }
- void SetShowLogContext(bool b) { this->LogContext = b; }
- //! Do we want debug output during the cmake run.
- bool GetDebugOutput() const { return this->DebugOutput; }
- void SetDebugOutputOn(bool b) { this->DebugOutput = b; }
- //! Do we want debug output from the find commands during the cmake run.
- bool GetDebugFindOutput() const { return this->DebugFindOutput; }
- bool GetDebugFindOutput(std::string const& var) const;
- bool GetDebugFindPkgOutput(std::string const& pkg) const;
- void SetDebugFindOutput(bool b) { this->DebugFindOutput = b; }
- void SetDebugFindOutputPkgs(std::string const& args);
- void SetDebugFindOutputVars(std::string const& args);
- //! Do we want trace output during the cmake run.
- bool GetTrace() const { return this->Trace; }
- void SetTrace(bool b) { this->Trace = b; }
- bool GetTraceExpand() const { return this->TraceExpand; }
- void SetTraceExpand(bool b) { this->TraceExpand = b; }
- TraceFormat GetTraceFormat() const { return this->TraceFormatVar; }
- void SetTraceFormat(TraceFormat f) { this->TraceFormatVar = f; }
- void AddTraceSource(std::string const& file)
- {
- this->TraceOnlyThisSources.push_back(file);
- }
- std::vector<std::string> const& GetTraceSources() const
- {
- return this->TraceOnlyThisSources;
- }
- cmGeneratedFileStream& GetTraceFile()
- {
- if (this->TraceRedirect) {
- return this->TraceRedirect->GetTraceFile();
- }
- return this->TraceFile;
- }
- void SetTraceFile(std::string const& file);
- void PrintTraceFormatVersion();
- #ifndef CMAKE_BOOTSTRAP
- cmConfigureLog* GetConfigureLog() const { return this->ConfigureLog.get(); }
- #endif
- //! Use trace from another ::cmake instance.
- void SetTraceRedirect(cmake* other);
- bool GetWarnUninitialized() const { return this->WarnUninitialized; }
- void SetWarnUninitialized(bool b) { this->WarnUninitialized = b; }
- bool GetWarnUnusedCli() const { return this->WarnUnusedCli; }
- void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b; }
- bool GetCheckSystemVars() const { return this->CheckSystemVars; }
- void SetCheckSystemVars(bool b) { this->CheckSystemVars = b; }
- bool GetIgnoreCompileWarningAsError() const
- {
- return this->IgnoreCompileWarningAsError;
- }
- void SetIgnoreCompileWarningAsError(bool b)
- {
- this->IgnoreCompileWarningAsError = b;
- }
- bool GetIgnoreLinkWarningAsError() const
- {
- return this->IgnoreLinkWarningAsError;
- }
- void SetIgnoreLinkWarningAsError(bool b)
- {
- this->IgnoreLinkWarningAsError = b;
- }
- void MarkCliAsUsed(std::string const& variable);
- /** Get the list of configurations (in upper case) considered to be
- debugging configurations.*/
- std::vector<std::string> GetDebugConfigs();
- void SetCMakeEditCommand(std::string const& s)
- {
- this->CMakeEditCommand = s;
- }
- std::string const& GetCMakeEditCommand() const
- {
- return this->CMakeEditCommand;
- }
- cmMessenger* GetMessenger() const { return this->Messenger.get(); }
- #ifndef CMAKE_BOOTSTRAP
- /// Get the SARIF file path if set manually for this run
- cm::optional<std::string> GetSarifFilePath() const
- {
- return (this->SarifFileOutput ? cm::make_optional(this->SarifFilePath)
- : cm::nullopt);
- }
- #endif
- /**
- * Get the state of the suppression of developer (author) warnings.
- * Returns false, by default, if developer warnings should be shown, true
- * otherwise.
- */
- bool GetSuppressDevWarnings() const;
- /**
- * Set the state of the suppression of developer (author) warnings.
- */
- void SetSuppressDevWarnings(bool v);
- /**
- * Get the state of the suppression of deprecated warnings.
- * Returns false, by default, if deprecated warnings should be shown, true
- * otherwise.
- */
- bool GetSuppressDeprecatedWarnings() const;
- /**
- * Set the state of the suppression of deprecated warnings.
- */
- void SetSuppressDeprecatedWarnings(bool v);
- /**
- * Get the state of treating developer (author) warnings as errors.
- * Returns false, by default, if warnings should not be treated as errors,
- * true otherwise.
- */
- bool GetDevWarningsAsErrors() const;
- /**
- * Set the state of treating developer (author) warnings as errors.
- */
- void SetDevWarningsAsErrors(bool v);
- /**
- * Get the state of treating deprecated warnings as errors.
- * Returns false, by default, if warnings should not be treated as errors,
- * true otherwise.
- */
- bool GetDeprecatedWarningsAsErrors() const;
- /**
- * Set the state of treating developer (author) warnings as errors.
- */
- void SetDeprecatedWarningsAsErrors(bool v);
- /** Display a message to the user. */
- void IssueMessage(
- MessageType t, std::string const& text,
- cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const;
- //! run the --build option
- int Build(int jobs, std::string dir, std::vector<std::string> targets,
- std::string config, std::vector<std::string> nativeOptions,
- cmBuildOptions& buildOptions, bool verbose,
- std::string const& presetName, bool listPresets,
- std::vector<std::string> const& args);
- //! run the --open option
- bool Open(std::string const& dir, bool dryRun);
- //! run the --workflow option
- enum class WorkflowListPresets
- {
- No,
- Yes,
- };
- enum class WorkflowFresh
- {
- No,
- Yes,
- };
- int Workflow(std::string const& presetName, WorkflowListPresets listPresets,
- WorkflowFresh fresh);
- void UnwatchUnusedCli(std::string const& var);
- void WatchUnusedCli(std::string const& var);
- #if !defined(CMAKE_BOOTSTRAP)
- cmFileAPI* GetFileAPI() const { return this->FileAPI.get(); }
- cmInstrumentation* GetInstrumentation() const
- {
- return this->Instrumentation.get();
- }
- #endif
- cmState* GetState() const { return this->State.get(); }
- void SetCurrentSnapshot(cmStateSnapshot const& snapshot)
- {
- this->CurrentSnapshot = snapshot;
- }
- cmStateSnapshot GetCurrentSnapshot() const { return this->CurrentSnapshot; }
- bool GetRegenerateDuringBuild() const { return this->RegenerateDuringBuild; }
- void SetCMakeListName(std::string const& name);
- std::string GetCMakeListFile(std::string const& dir) const;
- #if !defined(CMAKE_BOOTSTRAP)
- cmMakefileProfilingData& GetProfilingOutput();
- bool IsProfilingEnabled() const;
- cm::optional<cmMakefileProfilingData::RAII> CreateProfilingEntry(
- std::string const& category, std::string const& name)
- {
- return this->CreateProfilingEntry(
- category, name, []() -> cm::nullopt_t { return cm::nullopt; });
- }
- template <typename ArgsFunc>
- cm::optional<cmMakefileProfilingData::RAII> CreateProfilingEntry(
- std::string const& category, std::string const& name, ArgsFunc&& argsFunc)
- {
- if (this->IsProfilingEnabled()) {
- return cm::make_optional<cmMakefileProfilingData::RAII>(
- this->GetProfilingOutput(), category, name, argsFunc());
- }
- return cm::nullopt;
- }
- #endif
- #ifdef CMake_ENABLE_DEBUGGER
- bool GetDebuggerOn() const { return this->DebuggerOn; }
- std::string GetDebuggerPipe() const { return this->DebuggerPipe; }
- std::string GetDebuggerDapLogFile() const
- {
- return this->DebuggerDapLogFile;
- }
- void SetDebuggerOn(bool b) { this->DebuggerOn = b; }
- bool StartDebuggerIfEnabled();
- void StopDebuggerIfNeeded(int exitCode);
- std::shared_ptr<cmDebugger::cmDebuggerAdapter> GetDebugAdapter()
- const noexcept
- {
- return this->DebugAdapter;
- }
- #endif
- protected:
- void RunCheckForUnusedVariables();
- int HandleDeleteCacheVariables(std::string const& var);
- using RegisteredGeneratorsVector =
- std::vector<std::unique_ptr<cmGlobalGeneratorFactory>>;
- RegisteredGeneratorsVector Generators;
- using RegisteredExtraGeneratorsVector =
- std::vector<cmExternalMakefileProjectGeneratorFactory*>;
- RegisteredExtraGeneratorsVector ExtraGenerators;
- void AddScriptingCommands() const;
- void AddProjectCommands() const;
- void AddDefaultGenerators();
- void AddDefaultExtraGenerators();
- std::map<std::string, DiagLevel> DiagLevels;
- std::string GeneratorInstance;
- std::string GeneratorPlatform;
- std::string GeneratorToolset;
- bool GeneratorInstanceSet = false;
- bool GeneratorPlatformSet = false;
- bool GeneratorToolsetSet = false;
- //! read in a cmake list file to initialize the cache
- void ReadListFile(std::vector<std::string> const& args,
- std::string const& path);
- bool FindPackage(std::vector<std::string> const& args);
- //! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file.
- /// If it is set, truncate it to 50kb
- void TruncateOutputLog(char const* fname);
- /**
- * Method called to check build system integrity at build time.
- * Returns 1 if CMake should rerun and 0 otherwise.
- */
- int CheckBuildSystem();
- bool SetDirectoriesFromFile(std::string const& arg);
- //! Make sure all commands are what they say they are and there is no
- /// macros.
- void CleanupCommandsAndMacros();
- void GenerateGraphViz(std::string const& fileName) const;
- private:
- std::vector<std::string> cmdArgs;
- std::string CMakeWorkingDirectory;
- ProgressCallbackType ProgressCallback;
- WorkingMode CurrentWorkingMode = NORMAL_MODE;
- bool DebugOutput = false;
- bool DebugFindOutput = false;
- bool Trace = false;
- bool TraceExpand = false;
- TraceFormat TraceFormatVar = TraceFormat::Human;
- cmGeneratedFileStream TraceFile;
- cmake* TraceRedirect = nullptr;
- #ifndef CMAKE_BOOTSTRAP
- std::unique_ptr<cmConfigureLog> ConfigureLog;
- #endif
- bool WarnUninitialized = false;
- bool WarnUnusedCli = true;
- bool CheckSystemVars = false;
- bool IgnoreCompileWarningAsError = false;
- bool IgnoreLinkWarningAsError = false;
- std::map<std::string, bool> UsedCliVariables;
- std::string CMakeEditCommand;
- std::string CXXEnvironment;
- std::string CCEnvironment;
- std::string CheckBuildSystemArgument;
- std::string CheckStampFile;
- std::string CheckStampList;
- std::string VSSolutionFile;
- std::string EnvironmentGenerator;
- FileExtensions CLikeSourceFileExtensions;
- FileExtensions HeaderFileExtensions;
- FileExtensions CudaFileExtensions;
- FileExtensions ISPCFileExtensions;
- FileExtensions FortranFileExtensions;
- FileExtensions HipFileExtensions;
- bool ClearBuildSystem = false;
- bool DebugTryCompile = false;
- bool FreshCache = false;
- bool RegenerateDuringBuild = false;
- std::string CMakeListName;
- std::unique_ptr<cmFileTimeCache> FileTimeCache;
- std::string GraphVizFile;
- InstalledFilesMap InstalledFiles;
- #ifndef CMAKE_BOOTSTRAP
- std::map<std::string, cm::optional<cmCMakePresetsGraph::CacheVariable>>
- UnprocessedPresetVariables;
- std::map<std::string, cm::optional<std::string>>
- UnprocessedPresetEnvironment;
- #endif
- #if !defined(CMAKE_BOOTSTRAP)
- std::unique_ptr<cmVariableWatch> VariableWatch;
- std::unique_ptr<cmFileAPI> FileAPI;
- std::unique_ptr<cmInstrumentation> Instrumentation;
- #endif
- std::unique_ptr<cmState> State;
- cmStateSnapshot CurrentSnapshot;
- std::unique_ptr<cmMessenger> Messenger;
- #ifndef CMAKE_BOOTSTRAP
- bool SarifFileOutput = false;
- std::string SarifFilePath;
- #endif
- std::vector<std::string> TraceOnlyThisSources;
- std::set<std::string> DebugFindPkgs;
- std::set<std::string> DebugFindVars;
- Message::LogLevel MessageLogLevel = Message::LogLevel::LOG_STATUS;
- bool LogLevelWasSetViaCLI = false;
- bool LogContext = false;
- std::vector<std::string> CheckInProgressMessages;
- std::unique_ptr<cmGlobalGenerator> GlobalGenerator;
- //! Print a list of valid generators to stderr.
- void PrintGeneratorList();
- std::unique_ptr<cmGlobalGenerator> EvaluateDefaultGlobalGenerator();
- void CreateDefaultGlobalGenerator();
- void AppendGlobalGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
- void AppendExtraGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
- #if !defined(CMAKE_BOOTSTRAP)
- template <typename T>
- T const* FindPresetForWorkflow(
- cm::static_string_view type,
- std::map<std::string, cmCMakePresetsGraph::PresetPair<T>> const& presets,
- cmCMakePresetsGraph::WorkflowPreset::WorkflowStep const& step);
- std::function<int()> BuildWorkflowStep(std::vector<std::string> const& args);
- #endif
- #if !defined(CMAKE_BOOTSTRAP)
- std::unique_ptr<cmMakefileProfilingData> ProfilingOutput;
- #endif
- #ifdef CMake_ENABLE_DEBUGGER
- std::shared_ptr<cmDebugger::cmDebuggerAdapter> DebugAdapter;
- bool DebuggerOn = false;
- std::string DebuggerPipe;
- std::string DebuggerDapLogFile;
- #endif
- cm::optional<int> ScriptModeExitCode;
- public:
- bool HasScriptModeExitCode() const { return ScriptModeExitCode.has_value(); }
- void SetScriptModeExitCode(int code) { ScriptModeExitCode = code; }
- int GetScriptModeExitCode() const { return ScriptModeExitCode.value_or(-1); }
- static cmDocumentationEntry CMAKE_STANDARD_OPTIONS_TABLE[19];
- };
- #define FOR_EACH_C90_FEATURE(F) F(c_function_prototypes)
- #define FOR_EACH_C99_FEATURE(F) \
- F(c_restrict) \
- F(c_variadic_macros)
- #define FOR_EACH_C11_FEATURE(F) F(c_static_assert)
- #define FOR_EACH_C_FEATURE(F) \
- F(c_std_90) \
- F(c_std_99) \
- F(c_std_11) \
- F(c_std_17) \
- F(c_std_23) \
- FOR_EACH_C90_FEATURE(F) \
- FOR_EACH_C99_FEATURE(F) \
- FOR_EACH_C11_FEATURE(F)
- #define FOR_EACH_CXX98_FEATURE(F) F(cxx_template_template_parameters)
- #define FOR_EACH_CXX11_FEATURE(F) \
- F(cxx_alias_templates) \
- F(cxx_alignas) \
- F(cxx_alignof) \
- F(cxx_attributes) \
- F(cxx_auto_type) \
- F(cxx_constexpr) \
- F(cxx_decltype) \
- F(cxx_decltype_incomplete_return_types) \
- F(cxx_default_function_template_args) \
- F(cxx_defaulted_functions) \
- F(cxx_defaulted_move_initializers) \
- F(cxx_delegating_constructors) \
- F(cxx_deleted_functions) \
- F(cxx_enum_forward_declarations) \
- F(cxx_explicit_conversions) \
- F(cxx_extended_friend_declarations) \
- F(cxx_extern_templates) \
- F(cxx_final) \
- F(cxx_func_identifier) \
- F(cxx_generalized_initializers) \
- F(cxx_inheriting_constructors) \
- F(cxx_inline_namespaces) \
- F(cxx_lambdas) \
- F(cxx_local_type_template_args) \
- F(cxx_long_long_type) \
- F(cxx_noexcept) \
- F(cxx_nonstatic_member_init) \
- F(cxx_nullptr) \
- F(cxx_override) \
- F(cxx_range_for) \
- F(cxx_raw_string_literals) \
- F(cxx_reference_qualified_functions) \
- F(cxx_right_angle_brackets) \
- F(cxx_rvalue_references) \
- F(cxx_sizeof_member) \
- F(cxx_static_assert) \
- F(cxx_strong_enums) \
- F(cxx_thread_local) \
- F(cxx_trailing_return_types) \
- F(cxx_unicode_literals) \
- F(cxx_uniform_initialization) \
- F(cxx_unrestricted_unions) \
- F(cxx_user_literals) \
- F(cxx_variadic_macros) \
- F(cxx_variadic_templates)
- #define FOR_EACH_CXX14_FEATURE(F) \
- F(cxx_aggregate_default_initializers) \
- F(cxx_attribute_deprecated) \
- F(cxx_binary_literals) \
- F(cxx_contextual_conversions) \
- F(cxx_decltype_auto) \
- F(cxx_digit_separators) \
- F(cxx_generic_lambdas) \
- F(cxx_lambda_init_captures) \
- F(cxx_relaxed_constexpr) \
- F(cxx_return_type_deduction) \
- F(cxx_variable_templates)
- #define FOR_EACH_CXX_FEATURE(F) \
- F(cxx_std_98) \
- F(cxx_std_11) \
- F(cxx_std_14) \
- F(cxx_std_17) \
- F(cxx_std_20) \
- F(cxx_std_23) \
- F(cxx_std_26) \
- FOR_EACH_CXX98_FEATURE(F) \
- FOR_EACH_CXX11_FEATURE(F) \
- FOR_EACH_CXX14_FEATURE(F)
- #define FOR_EACH_CUDA_FEATURE(F) \
- F(cuda_std_03) \
- F(cuda_std_11) \
- F(cuda_std_14) \
- F(cuda_std_17) \
- F(cuda_std_20) \
- F(cuda_std_23) \
- F(cuda_std_26)
- #define FOR_EACH_HIP_FEATURE(F) \
- F(hip_std_98) \
- F(hip_std_11) \
- F(hip_std_14) \
- F(hip_std_17) \
- F(hip_std_20) \
- F(hip_std_23) \
- F(hip_std_26)
|