mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-14 21:41:06 -05:00
cmake: Allow CMAKE_CONFIGURATION_TYPES to be set by environment variable
When no `CMAKE_CONFIGURATION_TYPES` is explicitly specified while creating a new build tree, check for an environment variable of the same name. Issue: #20983
This commit is contained in:
11
Help/envvar/CMAKE_CONFIGURATION_TYPES.rst
Normal file
11
Help/envvar/CMAKE_CONFIGURATION_TYPES.rst
Normal file
@@ -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.
|
||||||
@@ -31,6 +31,7 @@ Environment Variables that Control the Build
|
|||||||
/envvar/CMAKE_APPLE_SILICON_PROCESSOR
|
/envvar/CMAKE_APPLE_SILICON_PROCESSOR
|
||||||
/envvar/CMAKE_BUILD_PARALLEL_LEVEL
|
/envvar/CMAKE_BUILD_PARALLEL_LEVEL
|
||||||
/envvar/CMAKE_BUILD_TYPE
|
/envvar/CMAKE_BUILD_TYPE
|
||||||
|
/envvar/CMAKE_CONFIGURATION_TYPES
|
||||||
/envvar/CMAKE_CONFIG_TYPE
|
/envvar/CMAKE_CONFIG_TYPE
|
||||||
/envvar/CMAKE_EXPORT_COMPILE_COMMANDS
|
/envvar/CMAKE_EXPORT_COMPILE_COMMANDS
|
||||||
/envvar/CMAKE_GENERATOR
|
/envvar/CMAKE_GENERATOR
|
||||||
|
|||||||
@@ -3,3 +3,7 @@ env-init-configs
|
|||||||
|
|
||||||
* The :envvar:`CMAKE_BUILD_TYPE` environment variable was added to
|
* The :envvar:`CMAKE_BUILD_TYPE` environment variable was added to
|
||||||
provide a default value for the :variable:`CMAKE_BUILD_TYPE` variable.
|
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.
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ types.
|
|||||||
|
|
||||||
This variable is initialized by the first :command:`project` or
|
This variable is initialized by the first :command:`project` or
|
||||||
:command:`enable_language` command called in a project when a new build
|
:command:`enable_language` command called in a project when a new build
|
||||||
tree is first created. The default value is generator-specific.
|
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
|
See :variable:`CMAKE_BUILD_TYPE` for specifying the configuration with
|
||||||
single-config generators.
|
single-config generators.
|
||||||
|
|||||||
@@ -3187,8 +3187,12 @@ void cmMakefile::InitCMAKE_CONFIGURATION_TYPES(std::string const& genDefault)
|
|||||||
if (this->GetDefinition("CMAKE_CONFIGURATION_TYPES")) {
|
if (this->GetDefinition("CMAKE_CONFIGURATION_TYPES")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
std::string initConfigs;
|
||||||
|
if (!cmSystemTools::GetEnv("CMAKE_CONFIGURATION_TYPES", initConfigs)) {
|
||||||
|
initConfigs = genDefault;
|
||||||
|
}
|
||||||
this->AddCacheDefinition(
|
this->AddCacheDefinition(
|
||||||
"CMAKE_CONFIGURATION_TYPES", genDefault,
|
"CMAKE_CONFIGURATION_TYPES", initConfigs,
|
||||||
"Semicolon separated list of supported configuration types, "
|
"Semicolon separated list of supported configuration types, "
|
||||||
"only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
|
"only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
|
||||||
"anything else will be ignored.",
|
"anything else will be ignored.",
|
||||||
|
|||||||
2
Tests/RunCMake/CommandLine/EnvConfigTypes-stdout.txt
Normal file
2
Tests/RunCMake/CommandLine/EnvConfigTypes-stdout.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
-- ENV{CMAKE_CONFIGURATION_TYPES}='ConfigTypesEnv'
|
||||||
|
-- CMAKE_CONFIGURATION_TYPES='ConfigTypesEnv'
|
||||||
2
Tests/RunCMake/CommandLine/EnvConfigTypes.cmake
Normal file
2
Tests/RunCMake/CommandLine/EnvConfigTypes.cmake
Normal file
@@ -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'
|
||||||
1
Tests/RunCMake/CommandLine/EnvConfigTypesIgnore.cmake
Normal file
1
Tests/RunCMake/CommandLine/EnvConfigTypesIgnore.cmake
Normal file
@@ -0,0 +1 @@
|
|||||||
|
include(EnvConfigTypes.cmake)
|
||||||
@@ -351,8 +351,17 @@ function(run_EnvironmentBuildType)
|
|||||||
unset(ENV{CMAKE_BUILD_TYPE})
|
unset(ENV{CMAKE_BUILD_TYPE})
|
||||||
endfunction()
|
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$")
|
if(RunCMake_GENERATOR MATCHES "Make|^Ninja$")
|
||||||
run_EnvironmentBuildType()
|
run_EnvironmentBuildType()
|
||||||
|
elseif(RunCMake_GENERATOR MATCHES "Ninja Multi-Config|Visual Studio|Xcode")
|
||||||
|
run_EnvironmentConfigTypes()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
function(run_EnvironmentToolchain)
|
function(run_EnvironmentToolchain)
|
||||||
|
|||||||
Reference in New Issue
Block a user