summaryrefslogtreecommitdiff
path: root/Modules/CMakeTestCXXCompiler.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-07-15 12:58:44 -0400
committerBrad King <brad.king@kitware.com>2021-07-15 13:06:18 -0400
commit3ddd7f35760055fc501d454f9029f3987536957b (patch)
tree37932a0f25ef5e617cb662391503e1c4adc045cd /Modules/CMakeTestCXXCompiler.cmake
parent7c6234dd21b7af95e7edea6b281d859dafb2ae81 (diff)
downloadcmake-3ddd7f35760055fc501d454f9029f3987536957b.tar.gz
enable_language: Fix test for working compiler with CMP0126 NEW behavior
Update the logic that converts a `try_compile` result from a cache entry to a normal variable to tolerate an existing normal variable under CMP0126 NEW behavior. Otherwise the `try_compile` result is ignored because CMake uses the false value of the normal variable, and CMake incorrectly reports that the compiler does not work. This went unnoticed for some languages (e.g. C and CXX) because the check for a working compiler is skipped if ABI detection works. It does affect other languages (e.g. CSharp). Fixes: #22423
Diffstat (limited to 'Modules/CMakeTestCXXCompiler.cmake')
-rw-r--r--Modules/CMakeTestCXXCompiler.cmake3
1 files changed, 3 insertions, 0 deletions
diff --git a/Modules/CMakeTestCXXCompiler.cmake b/Modules/CMakeTestCXXCompiler.cmake
index 0d2d0b0530..bbe35334be 100644
--- a/Modules/CMakeTestCXXCompiler.cmake
+++ b/Modules/CMakeTestCXXCompiler.cmake
@@ -43,6 +43,9 @@ if(NOT CMAKE_CXX_COMPILER_WORKS)
"# error \"The CMAKE_CXX_COMPILER is set to a C compiler\"\n"
"#endif\n"
"int main(){return 0;}\n")
+ # Clear result from normal variable.
+ unset(CMAKE_CXX_COMPILER_WORKS)
+ # Puts test result in cache variable.
try_compile(CMAKE_CXX_COMPILER_WORKS ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
OUTPUT_VARIABLE __CMAKE_CXX_COMPILER_OUTPUT)