summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-06-29 17:34:28 (GMT)
committerBrad King <brad.king@kitware.com>2021-06-30 14:55:40 (GMT)
commite216b9bbd331e77e59634690a2be98f087acaf2c (patch)
treebbbb4bc6d552751772045ad3993dba2ba70b8536 /Source
parent6986a382a912f4b982f4b20a6e04ff1d773ef1eb (diff)
downloadCMake-e216b9bbd331e77e59634690a2be98f087acaf2c.zip
CMake-e216b9bbd331e77e59634690a2be98f087acaf2c.tar.gz
CMake-e216b9bbd331e77e59634690a2be98f087acaf2c.tar.bz2
cmake: Allow CMAKE_BUILD_TYPE to be set by environment variable
When no `CMAKE_BUILD_TYPE` is explicitly specified while creating a new build tree, check for an environment variable of the same name. Issue: #20983
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGlobalGenerator.cxx12
1 files changed, 12 insertions, 0 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 9193778..cad7855 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -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();