Browse Source

Check*CompilerFlag: Do not set result as a normal variable too

This was previously fixed by commit d46590910c (Check*CompilerFlag: Do
not set result as a normal variable too, 2020-09-21, v3.18.3~1^2^2), but
was regressed by refactoring in commit 90dead024c (CheckCompilerFlag:
unified way to check compiler flags per language, 2020-09-25,
v3.19.0-rc1~88^2) due to the changes being developed concurrently.
Fix it again, and add a test case.

Fixes: #21207
Robert Maynard 4 years ago
parent
commit
018d300ca0
2 changed files with 10 additions and 1 deletions
  1. 0 1
      Modules/Internal/CheckCompilerFlag.cmake
  2. 10 0
      Tests/TryCompile/CMakeLists.txt

+ 0 - 1
Modules/Internal/CheckCompilerFlag.cmake

@@ -73,7 +73,6 @@ int main(void) { return 0; }]=])
   foreach(v IN LISTS _locale_vars)
     set(ENV{${v}} ${_locale_vars_saved_${v}})
   endforeach()
-  set(${_var} "${${_var}}" PARENT_SCOPE)
 endfunction ()
 
 cmake_policy(POP)

+ 10 - 0
Tests/TryCompile/CMakeLists.txt

@@ -305,11 +305,21 @@ unset(C_BOGUS_FLAG CACHE)
 include(CheckCCompilerFlag)
 CHECK_C_COMPILER_FLAG(${C_DD}-_this_is_not_a_flag_ C_BOGUS_FLAG)
 TEST_FAIL(C_BOGUS_FLAG "CHECK_C_COMPILER_FLAG() succeeded, but should have failed")
+unset(C_BOGUS_FLAG CACHE)
+if(DEFINED C_BOGUS_FLAG)
+  # Verify that CHECK_C_COMPILER_FLAG didn't construct a normal variable
+  message(SEND_ERROR "CHECK_C_COMPILER_FLAG shouldn't construct C_BOGUS_FLAG as a normal variable")
+endif()
 
 unset(CXX_BOGUS_FLAG CACHE)
 include(CheckCXXCompilerFlag)
 CHECK_CXX_COMPILER_FLAG(${CXX_DD}-_this_is_not_a_flag_ CXX_BOGUS_FLAG)
 TEST_FAIL(CXX_BOGUS_FLAG "CHECK_CXX_COMPILER_FLAG() succeeded, but should have failed")
+unset(CXX_BOGUS_FLAG CACHE)
+if(DEFINED CXX_BOGUS_FLAG)
+  # Verify that CHECK_C_COMPILER_FLAG didn't construct a normal variable
+  message(SEND_ERROR "CHECK_CXX_COMPILER_FLAG shouldn't construct CXX_BOGUS_FLAG as a normal variable")
+endif()
 
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
   unset(C_STRICT_PROTOTYPES CACHE)