[CMake] Save and restore CMAKE_EXE_LINKER_FLAGS manually
authorPetr Hosek <phosek@google.com>
Wed, 1 Feb 2023 17:29:54 +0000 (17:29 +0000)
committerPetr Hosek <phosek@google.com>
Wed, 1 Feb 2023 18:05:01 +0000 (18:05 +0000)
cmake_push_check_state and cmake_pop_check_state doesn't save and
restore CMAKE_EXE_LINKER_FLAGS so we need to do it manually.

Differential Revision: https://reviews.llvm.org/D143088

llvm/cmake/modules/LLVMCheckLinkerFlag.cmake

index cea6a7f..e09bbc6 100644 (file)
@@ -8,13 +8,12 @@ else()
   # Until the minimum CMAKE version is 3.18
 
   include(CheckCXXCompilerFlag)
-  include(CMakePushCheckState)
 
   # cmake builtin compatible, except we assume lang is C or CXX
   function(llvm_check_linker_flag lang flag out_var)
     cmake_policy(PUSH)
     cmake_policy(SET CMP0056 NEW)
-    cmake_push_check_state()
+    set(_CMAKE_EXE_LINKER_FLAGS_SAVE ${CMAKE_EXE_LINKER_FLAGS})
     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}")
     if("${lang}" STREQUAL "C")
       check_c_compiler_flag("" ${out_var})
@@ -23,7 +22,7 @@ else()
     else()
       message(FATAL_ERROR "\"${lang}\" is not C or CXX")
     endif()
-    cmake_pop_check_state()
+    set(CMAKE_EXE_LINKER_FLAGS ${_CMAKE_EXE_LINKER_FLAGS_SAVE})
     cmake_policy(POP)
   endfunction()
 endif()