cmake/Source/cmake.h

891 lines
33 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-07-09 11:21:54 +02:00
2020-08-30 11:54:41 +02:00
#include <cstddef>
2019-11-11 23:01:05 +01:00
#include <functional>
2016-10-30 18:24:19 +01:00
#include <map>
2020-02-01 23:06:01 +01:00
#include <memory>
2016-10-30 18:24:19 +01:00
#include <set>
2020-08-30 11:54:41 +02:00
#include <stack>
2016-10-30 18:24:19 +01:00
#include <string>
2018-04-23 21:13:27 +02:00
#include <unordered_set>
2020-08-30 11:54:41 +02:00
#include <utility>
2016-10-30 18:24:19 +01:00
#include <vector>
2020-08-30 11:54:41 +02:00
#include <cm/string_view>
2020-02-01 23:06:01 +01:00
#include "cmGeneratedFileStream.h"
2017-04-14 19:02:05 +02:00
#include "cmInstalledFile.h"
#include "cmListFileCache.h"
2019-11-11 23:01:05 +01:00
#include "cmMessageType.h"
#include "cmState.h"
2017-04-14 19:02:05 +02:00
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
2021-11-20 13:41:27 +01:00
#include "cmValue.h"
2017-04-14 19:02:05 +02:00
2020-02-01 23:06:01 +01:00
#if !defined(CMAKE_BOOTSTRAP)
2021-09-14 00:13:48 +02:00
# include <cm/optional>
2020-08-30 11:54:41 +02:00
# include <cm3p/json/value.h>
2021-09-14 00:13:48 +02:00
2022-03-29 21:10:50 +02:00
# include "cmCMakePresetsGraph.h"
2016-10-30 18:24:19 +01:00
#endif
class cmExternalMakefileProjectGeneratorFactory;
2019-11-11 23:01:05 +01:00
class cmFileAPI;
class cmFileTimeCache;
class cmGlobalGenerator;
2016-10-30 18:24:19 +01:00
class cmGlobalGeneratorFactory;
class cmMakefile;
2020-08-30 11:54:41 +02:00
#if !defined(CMAKE_BOOTSTRAP)
class cmMakefileProfilingData;
#endif
2016-10-30 18:24:19 +01:00
class cmMessenger;
class cmVariableWatch;
2022-03-29 21:10:50 +02:00
struct cmBuildOptions;
2016-10-30 18:24:19 +01:00
struct cmDocumentationEntry;
2012-04-19 19:04:21 +03:00
/** \brief Represents a cmake invocation.
*
* This class represents a cmake invocation. It is the top level class when
2013-11-03 12:27:13 +02:00
* running cmake. Most cmake based GUIs should primarily create an instance
2012-04-19 19:04:21 +03:00
* of this class and communicate with it.
*
* The basic process for a GUI is as follows:
*
* -# Create a cmake instance
2015-08-17 11:37:30 +02:00
* -# Set the Home directories, generator, and cmake command. this
2012-04-19 19:04:21 +03:00
* 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
2015-08-17 11:37:30 +02:00
* If your GUI allows the user to change the home directories then
2012-04-19 19:04:21 +03:00
* you must at a minimum redo steps 2 through 7.
*/
class cmake
{
2016-07-09 11:21:54 +02:00
public:
2017-07-20 19:35:53 +02:00
enum Role
{
RoleInternal, // no commands
RoleScript, // script commands
RoleProject // all commands
};
2016-03-13 13:35:51 +01:00
enum DiagLevel
{
DIAG_IGNORE,
DIAG_WARN,
DIAG_ERROR
};
2012-02-18 12:40:36 +02:00
2012-04-19 19:04:21 +03:00
/** \brief Describes the working modes of cmake */
2012-02-18 12:40:36 +02:00
enum WorkingMode
{
2012-04-19 19:04:21 +03:00
NORMAL_MODE, ///< Cmake runs to create project files
2021-09-14 00:13:48 +02:00
/** \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.
*/
2012-02-18 12:40:36 +02:00
SCRIPT_MODE,
2021-09-14 00:13:48 +02:00
/** \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,
2012-04-19 19:04:21 +03:00
/** \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.
*/
2012-02-18 12:40:36 +02:00
FIND_PACKAGE_MODE
};
2016-03-13 13:35:51 +01:00
2019-11-11 23:01:05 +01:00
/** \brief Define log level constants. */
enum LogLevel
{
LOG_UNDEFINED,
LOG_ERROR,
LOG_WARNING,
LOG_NOTICE,
LOG_STATUS,
LOG_VERBOSE,
LOG_DEBUG,
LOG_TRACE
};
2020-08-30 11:54:41 +02:00
/** \brief Define supported trace formats **/
enum TraceFormat
{
TRACE_UNDEFINED,
TRACE_HUMAN,
TRACE_JSON_V1,
};
2016-03-13 13:35:51 +01:00
struct GeneratorInfo
2016-07-09 11:21:54 +02:00
{
2016-03-13 13:35:51 +01:00
std::string name;
2016-10-30 18:24:19 +01:00
std::string baseName;
std::string extraName;
2016-03-13 13:35:51 +01:00
bool supportsToolset;
2016-10-30 18:24:19 +01:00
bool supportsPlatform;
2019-11-11 23:01:05 +01:00
std::vector<std::string> supportedPlatforms;
std::string defaultPlatform;
2016-10-30 18:24:19 +01:00
bool isAlias;
2016-07-09 11:21:54 +02:00
};
2016-03-13 13:35:51 +01:00
2020-02-01 23:06:01 +01:00
struct FileExtensions
{
2020-08-30 11:54:41 +02:00
bool Test(cm::string_view ext) const
2020-02-01 23:06:01 +01:00
{
return (this->unordered.find(ext) != this->unordered.end());
}
std::vector<std::string> ordered;
2020-08-30 11:54:41 +02:00
std::unordered_set<cm::string_view> unordered;
2020-02-01 23:06:01 +01:00
};
using InstalledFilesMap = std::map<std::string, cmInstalledFile>;
2018-08-09 18:06:22 +02:00
static const int NO_BUILD_PARALLEL_LEVEL = -1;
static const int DEFAULT_BUILD_PARALLEL_LEVEL = 0;
2012-04-19 19:04:21 +03:00
/// Default constructor
2021-11-20 13:41:27 +01:00
cmake(Role role, cmState::Mode mode,
cmState::ProjectKind projectKind = cmState::ProjectKind::Normal);
2012-04-19 19:04:21 +03:00
/// Destructor
~cmake();
2019-11-11 23:01:05 +01:00
cmake(cmake const&) = delete;
cmake& operator=(cmake const&) = delete;
2020-02-01 23:06:01 +01:00
#if !defined(CMAKE_BOOTSTRAP)
2018-10-28 12:09:07 +01:00
Json::Value ReportVersionJson() const;
2019-11-11 23:01:05 +01:00
Json::Value ReportCapabilitiesJson() const;
2016-10-30 18:24:19 +01:00
#endif
2019-11-11 23:01:05 +01:00
std::string ReportCapabilities() const;
2011-01-16 11:35:12 +01:00
2022-03-29 21:10:50 +02:00
/**
* 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
2012-04-19 19:04:21 +03:00
* home directory is the top directory of the project. It is the
2015-08-17 11:37:30 +02:00
* path-to-source cmake was run with.
*/
2015-04-27 22:25:09 +02:00
void SetHomeDirectory(const std::string& dir);
2018-04-23 21:13:27 +02:00
std::string const& GetHomeDirectory() const;
2015-08-17 11:37:30 +02:00
void SetHomeOutputDirectory(const std::string& dir);
2018-04-23 21:13:27 +02:00
std::string const& GetHomeOutputDirectory() const;
//@}
2021-09-14 00:13:48 +02:00
/**
* Working directory at CMake launch
*/
std::string const& GetCMakeWorkingDirectory() const
{
return this->CMakeWorkingDirectory;
}
/**
* Handle a command line invocation of cmake.
*/
2016-07-09 11:21:54 +02:00
int Run(const std::vector<std::string>& args)
{
return this->Run(args, false);
}
int Run(const std::vector<std::string>& 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();
2019-11-11 23:01:05 +01:00
//! Break up a line like VAR:type="value" into var, type and value
2016-07-09 11:21:54 +02:00
static bool ParseCacheEntry(const std::string& entry, std::string& var,
std::string& value,
2017-04-14 19:02:05 +02:00
cmStateEnums::CacheEntryType& type);
2015-08-17 11:37:30 +02:00
int LoadCache();
2015-08-17 11:37:30 +02:00
bool LoadCache(const std::string& path);
bool LoadCache(const std::string& path, bool internal,
std::set<std::string>& excludes,
std::set<std::string>& includes);
bool SaveCache(const std::string& path);
bool DeleteCache(const std::string& path);
void PreLoadCMakeFiles();
2019-11-11 23:01:05 +01:00
//! Create a GlobalGenerator
2020-08-30 11:54:41 +02:00
std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator(
2021-09-14 00:13:48 +02:00
const std::string& name, bool allowArch = true);
//! Create a GlobalGenerator and set it as our own
bool CreateAndSetGlobalGenerator(const std::string& name, bool allowArch);
#ifndef CMAKE_BOOTSTRAP
//! Print list of configure presets
2022-03-29 21:10:50 +02:00
void PrintPresetList(const cmCMakePresetsGraph& graph) const;
2021-09-14 00:13:48 +02:00
#endif
2019-11-11 23:01:05 +01:00
//! Return the global generator assigned to this instance of cmake
2020-08-30 11:54:41 +02:00
cmGlobalGenerator* GetGlobalGenerator()
{
return this->GlobalGenerator.get();
}
2019-11-11 23:01:05 +01:00
//! Return the global generator assigned to this instance of cmake, const
2011-01-16 11:35:12 +01:00
const cmGlobalGenerator* GetGlobalGenerator() const
2016-07-09 11:21:54 +02:00
{
2020-08-30 11:54:41 +02:00
return this->GlobalGenerator.get();
2016-07-09 11:21:54 +02:00
}
2019-11-11 23:01:05 +01:00
//! Return the full path to where the CMakeCache.txt file should be.
2016-10-30 18:24:19 +01:00
static std::string FindCacheFile(const std::string& binaryDir);
2019-11-11 23:01:05 +01:00
//! Return the global generator assigned to this instance of cmake
2020-08-30 11:54:41 +02:00
void SetGlobalGenerator(std::unique_ptr<cmGlobalGenerator>);
2019-11-11 23:01:05 +01:00
//! Get the names of the current registered generators
void GetRegisteredGenerators(std::vector<GeneratorInfo>& generators,
bool includeNamesWithPlatform = true) const;
2019-11-11 23:01:05 +01:00
//! Set the name of the selected generator-specific instance.
2018-04-23 21:13:27 +02:00
void SetGeneratorInstance(std::string const& instance)
{
this->GeneratorInstance = instance;
2019-11-11 23:01:05 +01:00
this->GeneratorInstanceSet = true;
2018-04-23 21:13:27 +02:00
}
2019-11-11 23:01:05 +01:00
//! Set the name of the selected generator-specific platform.
2015-04-27 22:25:09 +02:00
void SetGeneratorPlatform(std::string const& ts)
2016-07-09 11:21:54 +02:00
{
this->GeneratorPlatform = ts;
2019-11-11 23:01:05 +01:00
this->GeneratorPlatformSet = true;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
2019-11-11 23:01:05 +01:00
//! Set the name of the selected generator-specific toolset.
2013-03-16 19:13:01 +02:00
void SetGeneratorToolset(std::string const& ts)
2016-07-09 11:21:54 +02:00
{
this->GeneratorToolset = ts;
2019-11-11 23:01:05 +01:00
this->GeneratorToolsetSet = true;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2021-09-14 00:13:48 +02:00
bool IsAKnownSourceExtension(cm::string_view ext) const
2016-07-09 11:21:54 +02:00
{
2021-09-14 00:13:48 +02:00
return this->CLikeSourceFileExtensions.Test(ext) ||
this->CudaFileExtensions.Test(ext) ||
this->FortranFileExtensions.Test(ext) ||
this->HipFileExtensions.Test(ext) || this->ISPCFileExtensions.Test(ext);
2016-07-09 11:21:54 +02:00
}
2018-04-23 21:13:27 +02:00
2021-09-14 00:13:48 +02:00
bool IsACLikeSourceExtension(cm::string_view ext) const
2018-04-23 21:13:27 +02:00
{
2021-09-14 00:13:48 +02:00
return this->CLikeSourceFileExtensions.Test(ext);
2018-04-23 21:13:27 +02:00
}
2021-09-14 00:13:48 +02:00
bool IsAKnownExtension(cm::string_view ext) const
2016-07-09 11:21:54 +02:00
{
2021-09-14 00:13:48 +02:00
return this->IsAKnownSourceExtension(ext) || this->IsAHeaderExtension(ext);
2016-07-09 11:21:54 +02:00
}
2016-03-13 13:35:51 +01:00
2021-09-14 00:13:48 +02:00
std::vector<std::string> GetAllExtensions() const;
2020-02-01 23:06:01 +01:00
2021-09-14 00:13:48 +02:00
const std::vector<std::string>& GetHeaderExtensions() const
2020-02-01 23:06:01 +01:00
{
2021-09-14 00:13:48 +02:00
return this->HeaderFileExtensions.ordered;
2020-02-01 23:06:01 +01:00
}
2021-09-14 00:13:48 +02:00
bool IsAHeaderExtension(cm::string_view ext) const
2020-02-01 23:06:01 +01:00
{
2021-09-14 00:13:48 +02:00
return this->HeaderFileExtensions.Test(ext);
2018-04-23 21:13:27 +02:00
}
// Strips the extension (if present and known) from a filename
std::string StripExtension(const std::string& file) const;
/**
* Given a variable name, return its value (as a string).
*/
2021-11-20 13:41:27 +01:00
cmValue GetCacheDefinition(const std::string&) const;
2019-11-11 23:01:05 +01:00
//! Add an entry into the cache
2015-04-27 22:25:09 +02:00
void AddCacheEntry(const std::string& key, const char* value,
2021-11-20 13:41:27 +01:00
const char* helpString, int type)
{
this->AddCacheEntry(key,
value ? cmValue(std::string(value)) : cmValue(nullptr),
helpString, type);
}
void AddCacheEntry(const std::string& key, const std::string& value,
const char* helpString, int type)
{
this->AddCacheEntry(key, cmValue(value), helpString, type);
}
void AddCacheEntry(const std::string& key, cmValue value,
2016-07-09 11:21:54 +02:00
const char* helpString, int type);
2018-08-09 18:06:22 +02:00
bool DoWriteGlobVerifyTarget() const;
std::string const& GetGlobVerifyScript() const;
std::string const& GetGlobVerifyStamp() const;
void AddGlobCacheEntry(bool recurse, bool listDirectories,
bool followSymlinks, const std::string& relative,
const std::string& expression,
const std::vector<std::string>& files,
const std::string& variable,
cmListFileBacktrace const& bt);
2011-01-16 11:35:12 +01:00
/**
* Get the system information and write it to the file specified
*/
int GetSystemInformation(std::vector<std::string>&);
2019-11-11 23:01:05 +01:00
//! Parse environment variables
void LoadEnvironmentPresets();
//! Parse command line arguments
2019-02-03 13:14:49 +01:00
void SetArgs(const std::vector<std::string>& args);
2019-11-11 23:01:05 +01:00
//! Is this cmake running as a result of a TRY_COMPILE command
2015-08-17 11:37:30 +02:00
bool GetIsInTryCompile() const;
2011-01-16 11:35:12 +01:00
2021-09-14 00:13:48 +02:00
#ifndef CMAKE_BOOTSTRAP
void SetWarningFromPreset(const std::string& name,
const cm::optional<bool>& warning,
const cm::optional<bool>& error);
void ProcessPresetVariables();
void PrintPresetVariables();
void ProcessPresetEnvironment();
void PrintPresetEnvironment();
#endif
2019-11-11 23:01:05 +01:00
//! Parse command line arguments that might set cache values
bool SetCacheArgs(const std::vector<std::string>&);
2021-09-14 00:13:48 +02:00
void ProcessCacheArg(const std::string& var, const std::string& value,
cmStateEnums::CacheEntryType type);
2019-11-11 23:01:05 +01:00
using ProgressCallbackType = std::function<void(const std::string&, float)>;
/**
2013-11-03 12:27:13 +02:00
* Set the function used by GUIs to receive progress updates
2011-01-16 11:35:12 +01:00
* Function gets passed: message as a const char*, a progress
* amount ranging from 0 to 1.0 and client data. The progress
2011-01-16 11:35:12 +01:00
* number provided may be negative in cases where a message is
* to be displayed without any progress percentage.
*/
2019-11-11 23:01:05 +01:00
void SetProgressCallback(ProgressCallbackType f);
2019-11-11 23:01:05 +01:00
//! this is called by generators to update the progress
void UpdateProgress(const std::string& msg, float prog);
2020-02-01 23:06:01 +01:00
#if !defined(CMAKE_BOOTSTRAP)
2019-11-11 23:01:05 +01:00
//! Get the variable watch object
2020-02-01 23:06:01 +01:00
cmVariableWatch* GetVariableWatch() { return this->VariableWatch.get(); }
2018-10-28 12:09:07 +01:00
#endif
2019-11-11 23:01:05 +01:00
std::vector<cmDocumentationEntry> GetGeneratorsDocumentation();
2019-11-11 23:01:05 +01:00
//! Set/Get a property of this target file
2016-07-09 11:21:54 +02:00
void SetProperty(const std::string& prop, const char* value);
2021-11-20 13:41:27 +01:00
void SetProperty(const std::string& prop, cmValue value);
void SetProperty(const std::string& prop, const std::string& value)
{
this->SetProperty(prop, cmValue(value));
}
2020-08-30 11:54:41 +02:00
void AppendProperty(const std::string& prop, const std::string& value,
2016-07-09 11:21:54 +02:00
bool asString = false);
2021-11-20 13:41:27 +01:00
cmValue GetProperty(const std::string& prop);
2015-04-27 22:25:09 +02:00
bool GetPropertyAsBool(const std::string& prop);
2019-11-11 23:01:05 +01:00
//! Get or create an cmInstalledFile instance and return a pointer to it
2016-07-09 11:21:54 +02:00
cmInstalledFile* GetOrCreateInstalledFile(cmMakefile* mf,
const std::string& name);
2015-04-27 22:25:09 +02:00
cmInstalledFile const* GetInstalledFile(const std::string& name) const;
InstalledFilesMap const& GetInstalledFiles() const
2016-07-09 11:21:54 +02:00
{
return this->InstalledFiles;
}
2019-11-11 23:01:05 +01:00
//! Do all the checks before running configure
int DoPreConfigureChecks();
2012-02-18 12:40:36 +02:00
void SetWorkingMode(WorkingMode mode) { this->CurrentWorkingMode = mode; }
WorkingMode GetWorkingMode() { return this->CurrentWorkingMode; }
2011-01-16 11:35:12 +01:00
2019-11-11 23:01:05 +01:00
//! Debug the try compile stuff by not deleting the files
2021-09-14 00:13:48 +02:00
bool GetDebugTryCompile() const { return this->DebugTryCompile; }
2016-07-09 11:21:54 +02:00
void DebugTryCompileOn() { this->DebugTryCompile = true; }
/**
* Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
*/
int AddCMakePaths();
/**
* Get the file comparison class
*/
2020-02-01 23:06:01 +01:00
cmFileTimeCache* GetFileTimeCache() { return this->FileTimeCache.get(); }
2019-11-11 23:01:05 +01:00
2020-08-30 11:54:41 +02:00
bool WasLogLevelSetViaCLI() const { return this->LogLevelWasSetViaCLI; }
2020-02-01 23:06:01 +01:00
//! Get the selected log level for `message()` commands during the cmake run.
2019-11-11 23:01:05 +01:00
LogLevel GetLogLevel() const { return this->MessageLogLevel; }
void SetLogLevel(LogLevel level) { this->MessageLogLevel = level; }
static LogLevel StringToLogLevel(const std::string& levelStr);
2020-08-30 11:54:41 +02:00
static TraceFormat StringToTraceFormat(const std::string& levelStr);
bool HasCheckInProgress() const
{
return !this->CheckInProgressMessages.empty();
}
std::size_t GetCheckInProgressSize() const
{
return this->CheckInProgressMessages.size();
}
std::string GetTopCheckInProgressMessage()
{
auto message = this->CheckInProgressMessages.top();
this->CheckInProgressMessages.pop();
return message;
}
void PushCheckInProgressMessage(std::string message)
{
this->CheckInProgressMessages.emplace(std::move(message));
}
//! Should `message` command display context.
bool GetShowLogContext() const { return this->LogContext; }
void SetShowLogContext(bool b) { this->LogContext = b; }
2020-02-01 23:06:01 +01:00
//! Do we want debug output during the cmake run.
2021-09-14 00:13:48 +02:00
bool GetDebugOutput() const { return this->DebugOutput; }
2016-07-09 11:21:54 +02:00
void SetDebugOutputOn(bool b) { this->DebugOutput = b; }
2020-08-30 11:54:41 +02:00
//! Do we want debug output from the find commands during the cmake run.
2021-09-14 00:13:48 +02:00
bool GetDebugFindOutput() const { return this->DebugFindOutput; }
2022-03-29 21:10:50 +02:00
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);
2020-08-30 11:54:41 +02:00
2020-02-01 23:06:01 +01:00
//! Do we want trace output during the cmake run.
2020-08-30 11:54:41 +02:00
bool GetTrace() const { return this->Trace; }
2016-07-09 11:21:54 +02:00
void SetTrace(bool b) { this->Trace = b; }
2020-08-30 11:54:41 +02:00
bool GetTraceExpand() const { return this->TraceExpand; }
2016-07-09 11:21:54 +02:00
void SetTraceExpand(bool b) { this->TraceExpand = b; }
2020-08-30 11:54:41 +02:00
TraceFormat GetTraceFormat() const { return this->TraceFormatVar; }
void SetTraceFormat(TraceFormat f) { this->TraceFormatVar = f; }
2016-10-30 18:24:19 +01:00
void AddTraceSource(std::string const& file)
{
this->TraceOnlyThisSources.push_back(file);
}
std::vector<std::string> const& GetTraceSources() const
{
return this->TraceOnlyThisSources;
}
2020-02-01 23:06:01 +01:00
cmGeneratedFileStream& GetTraceFile() { return this->TraceFile; }
void SetTraceFile(std::string const& file);
2020-08-30 11:54:41 +02:00
void PrintTraceFormatVersion();
2020-02-01 23:06:01 +01:00
2021-09-14 00:13:48 +02:00
bool GetWarnUninitialized() const { return this->WarnUninitialized; }
2016-07-09 11:21:54 +02:00
void SetWarnUninitialized(bool b) { this->WarnUninitialized = b; }
2021-09-14 00:13:48 +02:00
bool GetWarnUnusedCli() const { return this->WarnUnusedCli; }
2016-07-09 11:21:54 +02:00
void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b; }
2021-09-14 00:13:48 +02:00
bool GetCheckSystemVars() const { return this->CheckSystemVars; }
2016-07-09 11:21:54 +02:00
void SetCheckSystemVars(bool b) { this->CheckSystemVars = b; }
2011-02-07 16:37:25 +01:00
void MarkCliAsUsed(const std::string& variable);
/** Get the list of configurations (in upper case) considered to be
debugging configurations.*/
2015-08-17 11:37:30 +02:00
std::vector<std::string> GetDebugConfigs();
2014-08-03 19:52:23 +02:00
void SetCMakeEditCommand(std::string const& s)
2016-07-09 11:21:54 +02:00
{
this->CMakeEditCommand = s;
}
2014-08-03 19:52:23 +02:00
std::string const& GetCMakeEditCommand() const
2016-07-09 11:21:54 +02:00
{
return this->CMakeEditCommand;
}
2020-02-01 23:06:01 +01:00
cmMessenger* GetMessenger() const { return this->Messenger.get(); }
2016-10-30 18:24:19 +01:00
2020-02-01 23:06:01 +01:00
/**
2016-03-13 13:35:51 +01:00
* Get the state of the suppression of developer (author) warnings.
* Returns false, by default, if developer warnings should be shown, true
* otherwise.
*/
2016-10-30 18:24:19 +01:00
bool GetSuppressDevWarnings() const;
2020-02-01 23:06:01 +01:00
/**
2016-03-13 13:35:51 +01:00
* Set the state of the suppression of developer (author) warnings.
*/
void SetSuppressDevWarnings(bool v);
2020-02-01 23:06:01 +01:00
/**
2016-03-13 13:35:51 +01:00
* Get the state of the suppression of deprecated warnings.
* Returns false, by default, if deprecated warnings should be shown, true
* otherwise.
*/
2016-10-30 18:24:19 +01:00
bool GetSuppressDeprecatedWarnings() const;
2020-02-01 23:06:01 +01:00
/**
2016-03-13 13:35:51 +01:00
* Set the state of the suppression of deprecated warnings.
*/
void SetSuppressDeprecatedWarnings(bool v);
2020-02-01 23:06:01 +01:00
/**
2016-03-13 13:35:51 +01:00
* Get the state of treating developer (author) warnings as errors.
* Returns false, by default, if warnings should not be treated as errors,
* true otherwise.
*/
2016-10-30 18:24:19 +01:00
bool GetDevWarningsAsErrors() const;
2016-03-13 13:35:51 +01:00
/**
* Set the state of treating developer (author) warnings as errors.
*/
void SetDevWarningsAsErrors(bool v);
2020-02-01 23:06:01 +01:00
/**
2016-03-13 13:35:51 +01:00
* Get the state of treating deprecated warnings as errors.
* Returns false, by default, if warnings should not be treated as errors,
* true otherwise.
*/
2016-10-30 18:24:19 +01:00
bool GetDeprecatedWarningsAsErrors() const;
2016-03-13 13:35:51 +01:00
/**
* Set the state of treating developer (author) warnings as errors.
*/
void SetDeprecatedWarningsAsErrors(bool v);
/** Display a message to the user. */
2016-07-09 11:21:54 +02:00
void IssueMessage(
2019-11-11 23:01:05 +01:00
MessageType t, std::string const& text,
2016-10-30 18:24:19 +01:00
cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const;
2015-08-17 11:37:30 +02:00
2019-11-11 23:01:05 +01:00
//! run the --build option
2021-09-14 00:13:48 +02:00
int Build(int jobs, std::string dir, std::vector<std::string> targets,
std::string config, std::vector<std::string> nativeOptions,
2022-03-29 21:10:50 +02:00
cmBuildOptions& buildOptions, bool verbose,
const std::string& presetName, bool listPresets);
2011-02-07 16:37:25 +01:00
2019-11-11 23:01:05 +01:00
//! run the --open option
2018-04-23 21:13:27 +02:00
bool Open(const std::string& dir, bool dryRun);
2015-04-27 22:25:09 +02:00
void UnwatchUnusedCli(const std::string& var);
void WatchUnusedCli(const std::string& var);
2015-08-17 11:37:30 +02:00
2020-02-01 23:06:01 +01:00
cmState* GetState() const { return this->State.get(); }
2017-07-20 19:35:53 +02:00
void SetCurrentSnapshot(cmStateSnapshot const& snapshot)
2016-07-09 11:21:54 +02:00
{
this->CurrentSnapshot = snapshot;
}
2017-04-14 19:02:05 +02:00
cmStateSnapshot GetCurrentSnapshot() const { return this->CurrentSnapshot; }
2015-08-17 11:37:30 +02:00
2020-08-30 11:54:41 +02:00
bool GetRegenerateDuringBuild() const { return this->RegenerateDuringBuild; }
#if !defined(CMAKE_BOOTSTRAP)
cmMakefileProfilingData& GetProfilingOutput();
bool IsProfilingEnabled() const;
#endif
protected:
2011-06-19 15:41:06 +03:00
void RunCheckForUnusedVariables();
2015-04-27 22:25:09 +02:00
int HandleDeleteCacheVariables(const std::string& var);
2020-08-30 11:54:41 +02:00
using RegisteredGeneratorsVector =
std::vector<std::unique_ptr<cmGlobalGeneratorFactory>>;
2013-03-16 19:13:01 +02:00
RegisteredGeneratorsVector Generators;
2020-02-01 23:06:01 +01:00
using RegisteredExtraGeneratorsVector =
std::vector<cmExternalMakefileProjectGeneratorFactory*>;
2016-10-30 18:24:19 +01:00
RegisteredExtraGeneratorsVector ExtraGenerators;
2021-09-14 00:13:48 +02:00
void AddScriptingCommands() const;
void AddProjectCommands() const;
void AddDefaultGenerators();
void AddDefaultExtraGenerators();
2016-03-13 13:35:51 +01:00
std::map<std::string, DiagLevel> DiagLevels;
2018-04-23 21:13:27 +02:00
std::string GeneratorInstance;
2015-04-27 22:25:09 +02:00
std::string GeneratorPlatform;
2013-03-16 19:13:01 +02:00
std::string GeneratorToolset;
2020-02-01 23:06:01 +01:00
bool GeneratorInstanceSet = false;
bool GeneratorPlatformSet = false;
bool GeneratorToolsetSet = false;
2019-11-11 23:01:05 +01:00
//! read in a cmake list file to initialize the cache
void ReadListFile(const std::vector<std::string>& args,
const std::string& path);
2012-02-18 12:40:36 +02:00
bool FindPackage(const std::vector<std::string>& args);
2019-11-11 23:01:05 +01:00
//! 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(const char* fname);
2011-01-16 11:35:12 +01:00
/**
* Method called to check build system integrity at build time.
* Returns 1 if CMake should rerun and 0 otherwise.
*/
int CheckBuildSystem();
2022-03-29 21:10:50 +02:00
bool SetDirectoriesFromFile(const std::string& arg);
//! Make sure all commands are what they say they are and there is no
2012-04-19 19:04:21 +03:00
/// macros.
void CleanupCommandsAndMacros();
2019-11-11 23:01:05 +01:00
void GenerateGraphViz(const std::string& fileName) const;
2011-01-16 11:35:12 +01:00
private:
2021-09-14 00:13:48 +02:00
std::string CMakeWorkingDirectory;
ProgressCallbackType ProgressCallback;
2020-02-01 23:06:01 +01:00
WorkingMode CurrentWorkingMode = NORMAL_MODE;
bool DebugOutput = false;
2020-08-30 11:54:41 +02:00
bool DebugFindOutput = false;
2020-02-01 23:06:01 +01:00
bool Trace = false;
bool TraceExpand = false;
2020-08-30 11:54:41 +02:00
TraceFormat TraceFormatVar = TRACE_HUMAN;
2020-02-01 23:06:01 +01:00
cmGeneratedFileStream TraceFile;
bool WarnUninitialized = false;
bool WarnUnusedCli = true;
bool CheckSystemVars = false;
2015-04-27 22:25:09 +02:00
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;
2019-11-11 23:01:05 +01:00
std::string EnvironmentGenerator;
2021-09-14 00:13:48 +02:00
FileExtensions CLikeSourceFileExtensions;
2020-02-01 23:06:01 +01:00
FileExtensions HeaderFileExtensions;
FileExtensions CudaFileExtensions;
2021-09-14 00:13:48 +02:00
FileExtensions ISPCFileExtensions;
2020-02-01 23:06:01 +01:00
FileExtensions FortranFileExtensions;
2021-09-14 00:13:48 +02:00
FileExtensions HipFileExtensions;
2020-02-01 23:06:01 +01:00
bool ClearBuildSystem = false;
bool DebugTryCompile = false;
2020-08-30 11:54:41 +02:00
bool RegenerateDuringBuild = false;
2020-02-01 23:06:01 +01:00
std::unique_ptr<cmFileTimeCache> FileTimeCache;
std::string GraphVizFile;
2015-04-27 22:25:09 +02:00
InstalledFilesMap InstalledFiles;
2021-09-14 00:13:48 +02:00
#ifndef CMAKE_BOOTSTRAP
2022-03-29 21:10:50 +02:00
std::map<std::string, cm::optional<cmCMakePresetsGraph::CacheVariable>>
2021-09-14 00:13:48 +02:00
UnprocessedPresetVariables;
std::map<std::string, cm::optional<std::string>>
UnprocessedPresetEnvironment;
#endif
2011-01-16 11:35:12 +01:00
2020-02-01 23:06:01 +01:00
#if !defined(CMAKE_BOOTSTRAP)
std::unique_ptr<cmVariableWatch> VariableWatch;
2019-11-11 23:01:05 +01:00
std::unique_ptr<cmFileAPI> FileAPI;
2018-10-28 12:09:07 +01:00
#endif
2020-02-01 23:06:01 +01:00
std::unique_ptr<cmState> State;
2017-04-14 19:02:05 +02:00
cmStateSnapshot CurrentSnapshot;
2020-02-01 23:06:01 +01:00
std::unique_ptr<cmMessenger> Messenger;
2016-10-30 18:24:19 +01:00
std::vector<std::string> TraceOnlyThisSources;
2015-08-17 11:37:30 +02:00
2022-03-29 21:10:50 +02:00
std::set<std::string> DebugFindPkgs;
std::set<std::string> DebugFindVars;
2019-11-11 23:01:05 +01:00
LogLevel MessageLogLevel = LogLevel::LOG_STATUS;
2020-08-30 11:54:41 +02:00
bool LogLevelWasSetViaCLI = false;
bool LogContext = false;
std::stack<std::string> CheckInProgressMessages;
std::unique_ptr<cmGlobalGenerator> GlobalGenerator;
2019-11-11 23:01:05 +01:00
void UpdateConversionPathTable();
2015-08-17 11:37:30 +02:00
2020-02-01 23:06:01 +01:00
//! Print a list of valid generators to stderr.
2015-08-17 11:37:30 +02:00
void PrintGeneratorList();
2019-11-11 23:01:05 +01:00
std::unique_ptr<cmGlobalGenerator> EvaluateDefaultGlobalGenerator();
2017-04-14 19:02:05 +02:00
void CreateDefaultGlobalGenerator();
2019-11-11 23:01:05 +01:00
void AppendGlobalGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
void AppendExtraGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
2020-08-30 11:54:41 +02:00
#if !defined(CMAKE_BOOTSTRAP)
std::unique_ptr<cmMakefileProfilingData> ProfilingOutput;
#endif
};
2016-07-09 11:21:54 +02:00
#define CMAKE_STANDARD_OPTIONS_TABLE \
2018-10-28 12:09:07 +01:00
{ "-S <path-to-source>", "Explicitly specify a source directory." }, \
{ "-B <path-to-build>", "Explicitly specify a build directory." }, \
{ "-C <initial-cache>", "Pre-load a script to populate the cache." }, \
2018-08-09 18:06:22 +02:00
{ "-D <var>[:<type>]=<value>", "Create or update a cmake cache entry." }, \
2016-07-09 11:21:54 +02:00
{ "-U <globbing_expr>", "Remove matching entries from CMake cache." }, \
{ "-G <generator-name>", "Specify a build system generator." }, \
{ "-T <toolset-name>", \
"Specify toolset name if supported by generator." }, \
{ "-A <platform-name>", \
"Specify platform name if supported by generator." }, \
2021-09-14 00:13:48 +02:00
{ "--toolchain <file>", \
"Specify toolchain file [CMAKE_TOOLCHAIN_FILE]." }, \
{ "--install-prefix <directory>", \
"Specify install directory [CMAKE_INSTALL_PREFIX]." }, \
2016-07-09 11:21:54 +02:00
{ "-Wdev", "Enable developer warnings." }, \
{ "-Wno-dev", "Suppress developer warnings." }, \
{ "-Werror=dev", "Make developer warnings errors." }, \
{ "-Wno-error=dev", "Make developer warnings not errors." }, \
{ "-Wdeprecated", "Enable deprecation warnings." }, \
{ "-Wno-deprecated", "Suppress deprecation warnings." }, \
2018-08-09 18:06:22 +02:00
{ "-Werror=deprecated", \
"Make deprecated macro and function warnings " \
"errors." }, \
2016-07-09 11:21:54 +02:00
{ \
2018-08-09 18:06:22 +02:00
"-Wno-error=deprecated", \
"Make deprecated macro and function warnings " \
"not errors." \
2016-07-09 11:21:54 +02:00
}
2019-11-11 23:01:05 +01:00
#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)
2016-07-09 11:21:54 +02:00
#define FOR_EACH_C_FEATURE(F) \
2017-04-14 19:02:05 +02:00
F(c_std_90) \
F(c_std_99) \
F(c_std_11) \
2021-09-14 00:13:48 +02:00
F(c_std_17) \
F(c_std_23) \
2019-11-11 23:01:05 +01:00
FOR_EACH_C90_FEATURE(F) \
FOR_EACH_C99_FEATURE(F) \
FOR_EACH_C11_FEATURE(F)
2015-04-27 22:25:09 +02:00
2019-11-11 23:01:05 +01:00
#define FOR_EACH_CXX98_FEATURE(F) F(cxx_template_template_parameters)
#define FOR_EACH_CXX11_FEATURE(F) \
2016-07-09 11:21:54 +02:00
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) \
2015-04-27 22:25:09 +02:00
F(cxx_variadic_templates)
2019-11-11 23:01:05 +01:00
#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) \
2021-09-14 00:13:48 +02:00
F(cxx_std_23) \
2019-11-11 23:01:05 +01:00
FOR_EACH_CXX98_FEATURE(F) \
FOR_EACH_CXX11_FEATURE(F) \
FOR_EACH_CXX14_FEATURE(F)
2020-08-30 11:54:41 +02:00
#define FOR_EACH_CUDA_FEATURE(F) \
F(cuda_std_03) \
F(cuda_std_11) \
F(cuda_std_14) \
F(cuda_std_17) \
2021-09-14 00:13:48 +02:00
F(cuda_std_20) \
F(cuda_std_23)
#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)