mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-23 14:48:19 -05:00
Merge topic 'env-init-configs'
ef56eefc9bcmake: Allow CMAKE_CONFIGURATION_TYPES to be set by environment variablee216b9bbd3cmake: Allow CMAKE_BUILD_TYPE to be set by environment variable6986a382a9Help: Document when CMAKE_BUILD_TYPE and CMAKE_CONFIGURATION_TYPES are sete96169a3ecHelp: Cross-reference CMAKE_CONFIGURATION_TYPES from CMAKE_BUILD_TYPE03bd9c4c10cmMakefile: Add helper to initialize CMAKE_CONFIGURATION_TYPES Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6291
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
CMAKE_BUILD_TYPE
|
||||
----------------
|
||||
|
||||
.. versionadded:: 3.22
|
||||
|
||||
.. include:: ENV_VAR.txt
|
||||
|
||||
The ``CMAKE_BUILD_TYPE`` environment variable specifies a default value
|
||||
for the :variable:`CMAKE_BUILD_TYPE` variable when there is no explicit
|
||||
configuration given on the first run while creating a new build tree.
|
||||
@@ -0,0 +1,11 @@
|
||||
CMAKE_CONFIGURATION_TYPES
|
||||
-------------------------
|
||||
|
||||
.. versionadded:: 3.22
|
||||
|
||||
.. include:: ENV_VAR.txt
|
||||
|
||||
The ``CMAKE_CONFIGURATION_TYPES`` environment variable specifies a
|
||||
default value for the :variable:`CMAKE_CONFIGURATION_TYPES` variable
|
||||
when there is no explicit configuration given on the first run while
|
||||
creating a new build tree.
|
||||
@@ -30,6 +30,8 @@ Environment Variables that Control the Build
|
||||
|
||||
/envvar/CMAKE_APPLE_SILICON_PROCESSOR
|
||||
/envvar/CMAKE_BUILD_PARALLEL_LEVEL
|
||||
/envvar/CMAKE_BUILD_TYPE
|
||||
/envvar/CMAKE_CONFIGURATION_TYPES
|
||||
/envvar/CMAKE_CONFIG_TYPE
|
||||
/envvar/CMAKE_EXPORT_COMPILE_COMMANDS
|
||||
/envvar/CMAKE_GENERATOR
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
env-init-configs
|
||||
----------------
|
||||
|
||||
* The :envvar:`CMAKE_BUILD_TYPE` environment variable was added to
|
||||
provide a default value for the :variable:`CMAKE_BUILD_TYPE` variable.
|
||||
|
||||
* The :envvar:`CMAKE_CONFIGURATION_TYPES` environment variable was added to
|
||||
provide a default value for the :variable:`CMAKE_CONFIGURATION_TYPES`
|
||||
variable.
|
||||
@@ -23,3 +23,12 @@ Note that configuration names are case-insensitive. The value of this
|
||||
variable will be the same as it is specified when invoking CMake.
|
||||
For instance, if ``-DCMAKE_BUILD_TYPE=ReLeAsE`` is specified, then the
|
||||
value of ``CMAKE_BUILD_TYPE`` will be ``ReLeAsE``.
|
||||
|
||||
This variable is initialized by the first :command:`project` or
|
||||
:command:`enable_language` command called in a project when a new build
|
||||
tree is first created. If the :envvar:`CMAKE_BUILD_TYPE` environment
|
||||
variable is set, its value is used. Otherwise, a toolchain-specific
|
||||
default is chosen when a language is enabled.
|
||||
|
||||
See :variable:`CMAKE_CONFIGURATION_TYPES` for specifying the configuration
|
||||
with multi-config generators.
|
||||
|
||||
@@ -8,5 +8,11 @@ such as ``Debug``, ``Release``, ``RelWithDebInfo`` etc. This has reasonable
|
||||
defaults on most platforms, but can be extended to provide other build
|
||||
types.
|
||||
|
||||
This variable is initialized by the first :command:`project` or
|
||||
:command:`enable_language` command called in a project when a new build
|
||||
tree is first created. If the :envvar:`CMAKE_CONFIGURATION_TYPES`
|
||||
environment variable is set, its value is used. Otherwise, the default
|
||||
value is generator-specific.
|
||||
|
||||
See :variable:`CMAKE_BUILD_TYPE` for specifying the configuration with
|
||||
single-config generators.
|
||||
|
||||
@@ -498,6 +498,18 @@ bool cmGlobalGenerator::CheckLanguages(
|
||||
void cmGlobalGenerator::EnableLanguage(
|
||||
std::vector<std::string> const& languages, cmMakefile* mf, bool optional)
|
||||
{
|
||||
if (!this->IsMultiConfig()) {
|
||||
std::string envBuildType;
|
||||
if (!mf->GetDefinition("CMAKE_BUILD_TYPE") &&
|
||||
cmSystemTools::GetEnv("CMAKE_BUILD_TYPE", envBuildType)) {
|
||||
mf->AddCacheDefinition(
|
||||
"CMAKE_BUILD_TYPE", envBuildType,
|
||||
"Choose the type of build. Options include: empty, "
|
||||
"Debug, Release, RelWithDebInfo, MinSizeRel.",
|
||||
cmStateEnums::STRING);
|
||||
}
|
||||
}
|
||||
|
||||
if (languages.empty()) {
|
||||
cmSystemTools::Error("EnableLanguage must have a lang specified!");
|
||||
cmSystemTools::SetFatalErrorOccured();
|
||||
|
||||
@@ -920,14 +920,7 @@ void cmGlobalNinjaGenerator::EnableLanguage(
|
||||
std::vector<std::string> const& langs, cmMakefile* mf, bool optional)
|
||||
{
|
||||
if (this->IsMultiConfig()) {
|
||||
if (!mf->GetDefinition("CMAKE_CONFIGURATION_TYPES")) {
|
||||
mf->AddCacheDefinition(
|
||||
"CMAKE_CONFIGURATION_TYPES", "Debug;Release;RelWithDebInfo",
|
||||
"Semicolon separated list of supported configuration types, only "
|
||||
"supports Debug, Release, MinSizeRel, and RelWithDebInfo, anything "
|
||||
"else will be ignored",
|
||||
cmStateEnums::STRING);
|
||||
}
|
||||
mf->InitCMAKE_CONFIGURATION_TYPES("Debug;Release;RelWithDebInfo");
|
||||
}
|
||||
|
||||
this->cmGlobalGenerator::EnableLanguage(langs, mf, optional);
|
||||
|
||||
@@ -107,14 +107,7 @@ void cmGlobalVisualStudio7Generator::EnableLanguage(
|
||||
{
|
||||
mf->AddDefinition("CMAKE_GENERATOR_RC", "rc");
|
||||
mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
|
||||
if (!mf->GetDefinition("CMAKE_CONFIGURATION_TYPES")) {
|
||||
mf->AddCacheDefinition(
|
||||
"CMAKE_CONFIGURATION_TYPES", "Debug;Release;MinSizeRel;RelWithDebInfo",
|
||||
"Semicolon separated list of supported configuration types, "
|
||||
"only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
|
||||
"anything else will be ignored.",
|
||||
cmStateEnums::STRING);
|
||||
}
|
||||
mf->InitCMAKE_CONFIGURATION_TYPES("Debug;Release;MinSizeRel;RelWithDebInfo");
|
||||
|
||||
// Create list of configurations requested by user's cache, if any.
|
||||
this->cmGlobalVisualStudioGenerator::EnableLanguage(lang, mf, optional);
|
||||
|
||||
@@ -431,14 +431,7 @@ void cmGlobalXCodeGenerator::EnableLanguage(
|
||||
{
|
||||
mf->AddDefinition("XCODE", "1");
|
||||
mf->AddDefinition("XCODE_VERSION", this->VersionString);
|
||||
if (!mf->GetDefinition("CMAKE_CONFIGURATION_TYPES")) {
|
||||
mf->AddCacheDefinition(
|
||||
"CMAKE_CONFIGURATION_TYPES", "Debug;Release;MinSizeRel;RelWithDebInfo",
|
||||
"Semicolon separated list of supported configuration types, "
|
||||
"only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
|
||||
"anything else will be ignored.",
|
||||
cmStateEnums::STRING);
|
||||
}
|
||||
mf->InitCMAKE_CONFIGURATION_TYPES("Debug;Release;MinSizeRel;RelWithDebInfo");
|
||||
mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
|
||||
this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
|
||||
this->ComputeArchitectures(mf);
|
||||
|
||||
@@ -3182,6 +3182,23 @@ void cmMakefile::RemoveVariablesInString(std::string& source,
|
||||
}
|
||||
}
|
||||
|
||||
void cmMakefile::InitCMAKE_CONFIGURATION_TYPES(std::string const& genDefault)
|
||||
{
|
||||
if (this->GetDefinition("CMAKE_CONFIGURATION_TYPES")) {
|
||||
return;
|
||||
}
|
||||
std::string initConfigs;
|
||||
if (!cmSystemTools::GetEnv("CMAKE_CONFIGURATION_TYPES", initConfigs)) {
|
||||
initConfigs = genDefault;
|
||||
}
|
||||
this->AddCacheDefinition(
|
||||
"CMAKE_CONFIGURATION_TYPES", initConfigs,
|
||||
"Semicolon separated list of supported configuration types, "
|
||||
"only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
|
||||
"anything else will be ignored.",
|
||||
cmStateEnums::STRING);
|
||||
}
|
||||
|
||||
std::string cmMakefile::GetDefaultConfiguration() const
|
||||
{
|
||||
if (this->GetGlobalGenerator()->IsMultiConfig()) {
|
||||
|
||||
@@ -310,6 +310,8 @@ public:
|
||||
*/
|
||||
void SetProjectName(std::string const& name);
|
||||
|
||||
void InitCMAKE_CONFIGURATION_TYPES(std::string const& genDefault);
|
||||
|
||||
/* Get the default configuration */
|
||||
std::string GetDefaultConfiguration() const;
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
-- ENV{CMAKE_BUILD_TYPE}='BuildTypeEnv'
|
||||
-- CMAKE_BUILD_TYPE='BuildTypeEnv'
|
||||
@@ -0,0 +1,2 @@
|
||||
message(STATUS "ENV{CMAKE_BUILD_TYPE}='$ENV{CMAKE_BUILD_TYPE}'")
|
||||
message(STATUS "CMAKE_BUILD_TYPE='${CMAKE_BUILD_TYPE}'")
|
||||
@@ -0,0 +1,2 @@
|
||||
-- ENV{CMAKE_BUILD_TYPE}='BuildTypeEnv'
|
||||
-- CMAKE_BUILD_TYPE='BuildTypeOpt'
|
||||
@@ -0,0 +1 @@
|
||||
include(EnvBuildType.cmake)
|
||||
@@ -0,0 +1,2 @@
|
||||
-- ENV{CMAKE_CONFIGURATION_TYPES}='ConfigTypesEnv'
|
||||
-- CMAKE_CONFIGURATION_TYPES='ConfigTypesEnv'
|
||||
@@ -0,0 +1,2 @@
|
||||
message(STATUS "ENV{CMAKE_CONFIGURATION_TYPES}='$ENV{CMAKE_CONFIGURATION_TYPES}'")
|
||||
message(STATUS "CMAKE_CONFIGURATION_TYPES='${CMAKE_CONFIGURATION_TYPES}'")
|
||||
@@ -0,0 +1,2 @@
|
||||
-- ENV{CMAKE_CONFIGURATION_TYPES}='ConfigTypesEnv'
|
||||
-- CMAKE_CONFIGURATION_TYPES='ConfigTypesOpt'
|
||||
@@ -0,0 +1 @@
|
||||
include(EnvConfigTypes.cmake)
|
||||
@@ -344,6 +344,26 @@ if(RunCMake_GENERATOR MATCHES "Unix Makefiles" OR RunCMake_GENERATOR MATCHES "Ni
|
||||
run_EnvironmentExportCompileCommands()
|
||||
endif()
|
||||
|
||||
function(run_EnvironmentBuildType)
|
||||
set(ENV{CMAKE_BUILD_TYPE} "BuildTypeEnv")
|
||||
run_cmake(EnvBuildType)
|
||||
run_cmake_with_options(EnvBuildTypeIgnore -DCMAKE_BUILD_TYPE=BuildTypeOpt)
|
||||
unset(ENV{CMAKE_BUILD_TYPE})
|
||||
endfunction()
|
||||
|
||||
function(run_EnvironmentConfigTypes)
|
||||
set(ENV{CMAKE_CONFIGURATION_TYPES} "ConfigTypesEnv")
|
||||
run_cmake(EnvConfigTypes)
|
||||
run_cmake_with_options(EnvConfigTypesIgnore -DCMAKE_CONFIGURATION_TYPES=ConfigTypesOpt)
|
||||
unset(ENV{CMAKE_CONFIGURATION_TYPES})
|
||||
endfunction()
|
||||
|
||||
if(RunCMake_GENERATOR MATCHES "Make|^Ninja$")
|
||||
run_EnvironmentBuildType()
|
||||
elseif(RunCMake_GENERATOR MATCHES "Ninja Multi-Config|Visual Studio|Xcode")
|
||||
run_EnvironmentConfigTypes()
|
||||
endif()
|
||||
|
||||
function(run_EnvironmentToolchain)
|
||||
set(ENV{CMAKE_TOOLCHAIN_FILE} "${RunCMake_SOURCE_DIR}/EnvToolchain-toolchain.cmake")
|
||||
run_cmake(EnvToolchainAbsolute)
|
||||
|
||||
Reference in New Issue
Block a user