summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-04-28 18:37:51 (GMT)
committerBrad King <brad.king@kitware.com>2021-05-03 14:22:23 (GMT)
commitbd16a985fcc26a2138e20ed11c248cd716eb5497 (patch)
treedc80e9edd83ec8a0f70f6568e4f5990958d84956
parent49c6d0f26199c252b493ed5f816dbcb2e9701112 (diff)
downloadCMake-bd16a985fcc26a2138e20ed11c248cd716eb5497.zip
CMake-bd16a985fcc26a2138e20ed11c248cd716eb5497.tar.gz
CMake-bd16a985fcc26a2138e20ed11c248cd716eb5497.tar.bz2
CompilerId/Features: Tolerate variables named for languages
If a `CMakeLists.txt` or `CMAKE_TOOLCHAIN_FILE` sets a variable named `C`, `CXX`, or `CUDA`, we were previously comparing each enabled language name to the value of that variable, rather than the name itself. Double-quote the string to take advantage of policy `CMP0054`, but also add "x" prefixes to support projects that do not set the policy. Fixes: #22125
-rw-r--r--Modules/CMakeCompilerIdDetection.cmake2
-rw-r--r--Modules/CMakeDetermineCompileFeatures.cmake6
-rw-r--r--Tests/RunCMake/ToolchainFile/LangVars-toolchain.cmake2
-rw-r--r--Tests/RunCMake/ToolchainFile/LangVars.cmake7
-rw-r--r--Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake1
5 files changed, 14 insertions, 4 deletions
diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake
index c79d423..850fc14 100644
--- a/Modules/CMakeCompilerIdDetection.cmake
+++ b/Modules/CMakeCompilerIdDetection.cmake
@@ -18,7 +18,7 @@ function(compiler_id_detection outvar lang)
file(GLOB lang_files
"${CMAKE_ROOT}/Modules/Compiler/*-DetermineCompiler.cmake")
set(nonlang CXX)
- if (lang STREQUAL CXX)
+ if ("x${lang}" STREQUAL "xCXX")
set(nonlang C)
endif()
diff --git a/Modules/CMakeDetermineCompileFeatures.cmake b/Modules/CMakeDetermineCompileFeatures.cmake
index f767847..ee7fedb 100644
--- a/Modules/CMakeDetermineCompileFeatures.cmake
+++ b/Modules/CMakeDetermineCompileFeatures.cmake
@@ -4,7 +4,7 @@
function(cmake_determine_compile_features lang)
- if(lang STREQUAL C AND COMMAND cmake_record_c_compile_features)
+ if("x${lang}" STREQUAL "xC" AND COMMAND cmake_record_c_compile_features)
message(CHECK_START "Detecting ${lang} compile features")
set(CMAKE_C90_COMPILE_FEATURES)
@@ -54,7 +54,7 @@ function(cmake_determine_compile_features lang)
message(CHECK_PASS "done")
- elseif(lang STREQUAL CXX AND COMMAND cmake_record_cxx_compile_features)
+ elseif("x${lang}" STREQUAL "xCXX" AND COMMAND cmake_record_cxx_compile_features)
message(CHECK_START "Detecting ${lang} compile features")
set(CMAKE_CXX98_COMPILE_FEATURES)
@@ -110,7 +110,7 @@ function(cmake_determine_compile_features lang)
message(CHECK_PASS "done")
- elseif(lang STREQUAL CUDA AND COMMAND cmake_record_cuda_compile_features)
+ elseif("x${lang}" STREQUAL "xCUDA" AND COMMAND cmake_record_cuda_compile_features)
message(CHECK_START "Detecting ${lang} compile features")
set(CMAKE_CUDA03_COMPILE_FEATURES)
diff --git a/Tests/RunCMake/ToolchainFile/LangVars-toolchain.cmake b/Tests/RunCMake/ToolchainFile/LangVars-toolchain.cmake
new file mode 100644
index 0000000..be07dc3
--- /dev/null
+++ b/Tests/RunCMake/ToolchainFile/LangVars-toolchain.cmake
@@ -0,0 +1,2 @@
+set(C 1)
+set(CXX 1)
diff --git a/Tests/RunCMake/ToolchainFile/LangVars.cmake b/Tests/RunCMake/ToolchainFile/LangVars.cmake
new file mode 100644
index 0000000..169e639
--- /dev/null
+++ b/Tests/RunCMake/ToolchainFile/LangVars.cmake
@@ -0,0 +1,7 @@
+foreach(test_language C CXX)
+ enable_language(${test_language})
+ if(DEFINED CMAKE_${test_language}_STANDARD_DEFAULT
+ AND NOT CMAKE_${test_language}_COMPILE_FEATURES)
+ message(FATAL_ERROR "Compile features not found for ${test_language}")
+ endif()
+endforeach()
diff --git a/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake b/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake
index 659523c..304c105 100644
--- a/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake
@@ -9,6 +9,7 @@ run_cmake_toolchain(CallEnableLanguage)
run_cmake_toolchain(CallProject)
run_cmake_toolchain(CheckLanguage)
run_cmake_toolchain(FlagsInit)
+run_cmake_toolchain(LangVars)
run_cmake_toolchain(LinkFlagsInit)
function(run_IncludeDirectories)