diff options
author | Brad King <brad.king@kitware.com> | 2021-11-22 17:19:03 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-11-22 17:50:42 (GMT) |
commit | 5b1ed2a64650405127d434f6267fb10baf1401d4 (patch) | |
tree | fdea7d216b5f6b4d8f9b13cea1d816b4770a7445 /Tests/RunCMake/try_compile | |
parent | deb9b076368512c1c7c391706f6f9e21cfb473f3 (diff) | |
download | CMake-5b1ed2a64650405127d434f6267fb10baf1401d4.zip CMake-5b1ed2a64650405127d434f6267fb10baf1401d4.tar.gz CMake-5b1ed2a64650405127d434f6267fb10baf1401d4.tar.bz2 |
try_compile: Do not use CMAKE_BUILD_TYPE or CMAKE_CONFIGURATION_TYPES env vars
Since:
* commit e216b9bbd3 (cmake: Allow CMAKE_BUILD_TYPE to be set by
environment variable, 2021-06-29, v3.22.0-rc1~503^2~1)
* commit ef56eefc9b (cmake: Allow CMAKE_CONFIGURATION_TYPES to be set by
environment variable, 2021-06-29, v3.22.0-rc1~503^2)
the environment variables are supposed to provide defaults for settings
the user otherwise can control via cache entries. However, they
accidentally affect `try_compile` projects too, which are supposed to be
programmatically controlled.
Fixes: #22935
Diffstat (limited to 'Tests/RunCMake/try_compile')
-rw-r--r-- | Tests/RunCMake/try_compile/EnvConfig.c | 7 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/EnvConfig.cmake | 18 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/RunCMakeTest.cmake | 2 |
3 files changed, 27 insertions, 0 deletions
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 fffb038..b19fd0e 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) |