summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-11-23 14:54:56 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-11-23 14:55:17 (GMT)
commit4133c426c2efe3226a3c145af8cce8fd658776c8 (patch)
treeb7316fe6648d28cb24b3b594ca35fafad8708562
parent0e0a2f3fe208d361779bb8b176d3770bdade4cd2 (diff)
parent5b1ed2a64650405127d434f6267fb10baf1401d4 (diff)
downloadCMake-4133c426c2efe3226a3c145af8cce8fd658776c8.zip
CMake-4133c426c2efe3226a3c145af8cce8fd658776c8.tar.gz
CMake-4133c426c2efe3226a3c145af8cce8fd658776c8.tar.bz2
Merge topic 'env-init-configs'
5b1ed2a646 try_compile: Do not use CMAKE_BUILD_TYPE or CMAKE_CONFIGURATION_TYPES env vars Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !6755
-rw-r--r--Source/cmGlobalGenerator.cxx3
-rw-r--r--Source/cmMakefile.cxx3
-rw-r--r--Tests/RunCMake/try_compile/EnvConfig.c7
-rw-r--r--Tests/RunCMake/try_compile/EnvConfig.cmake18
-rw-r--r--Tests/RunCMake/try_compile/RunCMakeTest.cmake2
5 files changed, 31 insertions, 2 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index b02dc29..0a2e7b5 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -503,7 +503,8 @@ bool cmGlobalGenerator::CheckLanguages(
void cmGlobalGenerator::EnableLanguage(
std::vector<std::string> const& languages, cmMakefile* mf, bool optional)
{
- if (!this->IsMultiConfig()) {
+ if (!this->IsMultiConfig() &&
+ !this->GetCMakeInstance()->GetIsInTryCompile()) {
std::string envBuildType;
if (!mf->GetDefinition("CMAKE_BUILD_TYPE") &&
cmSystemTools::GetEnv("CMAKE_BUILD_TYPE", envBuildType)) {
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index fe56dec..661cb05 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -3138,7 +3138,8 @@ void cmMakefile::InitCMAKE_CONFIGURATION_TYPES(std::string const& genDefault)
return;
}
std::string initConfigs;
- if (!cmSystemTools::GetEnv("CMAKE_CONFIGURATION_TYPES", initConfigs)) {
+ if (this->GetCMakeInstance()->GetIsInTryCompile() ||
+ !cmSystemTools::GetEnv("CMAKE_CONFIGURATION_TYPES", initConfigs)) {
initConfigs = genDefault;
}
this->AddCacheDefinition(
diff --git a/Tests/RunCMake/try_compile/EnvConfig.c b/Tests/RunCMake/try_compile/EnvConfig.c
new file mode 100644
index 0000000..5b1d400
--- /dev/null
+++ b/Tests/RunCMake/try_compile/EnvConfig.c
@@ -0,0 +1,7 @@
+#ifdef TC_CONFIG_BAD
+# error "Built in 'Bad' config"
+#endif
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/try_compile/EnvConfig.cmake b/Tests/RunCMake/try_compile/EnvConfig.cmake
new file mode 100644
index 0000000..4040c59
--- /dev/null
+++ b/Tests/RunCMake/try_compile/EnvConfig.cmake
@@ -0,0 +1,18 @@
+enable_language(C)
+
+set(ENV{CMAKE_BUILD_TYPE} "Bad")
+set(ENV{CMAKE_CONFIGURATION_TYPES} "Bad;Debug")
+
+add_library(tc_defs INTERFACE IMPORTED)
+target_compile_definitions(tc_defs INTERFACE "TC_CONFIG_$<UPPER_CASE:$<CONFIG>>")
+
+try_compile(ENV_CONFIG_RESULT "${CMAKE_BINARY_DIR}"
+ SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/EnvConfig.c"
+ COPY_FILE "${CMAKE_CURRENT_BINARY_DIR}/EnvConfig.bin"
+ OUTPUT_VARIABLE tc_output
+ LINK_LIBRARIES tc_defs
+ )
+if(NOT ENV_CONFIG_RESULT)
+ string(REPLACE "\n" "\n " tc_output " ${tc_output}")
+ message(FATAL_ERROR "try_compile failed:\n${tc_output}")
+endif()
diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
index 4f2cc5c..dcd3799 100644
--- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake
+++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
@@ -16,6 +16,8 @@ run_cmake(BadSources2)
run_cmake(NonSourceCopyFile)
run_cmake(NonSourceCompileDefinitions)
+run_cmake(EnvConfig)
+
set(RunCMake_TEST_OPTIONS --debug-trycompile)
run_cmake(PlatformVariables)
run_cmake(WarnDeprecated)