[llvm] r316972 - [cmake] Make check_linker_flags operate via linker flags

Shoaib Meenai via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 30 18:30:46 PDT 2017


Author: smeenai
Date: Mon Oct 30 18:30:46 2017
New Revision: 316972

URL: http://llvm.org/viewvc/llvm-project?rev=316972&view=rev
Log:
[cmake] Make check_linker_flags operate via linker flags

`check_linker_flags` currently sets the *compiler* flags (via
`CMAKE_REQUIRED_FLAGS`), and thus implicitly relies on cmake's default
behavior of passing the compiler flags to the linker. This breaks when
cmake's build rules have been altered to not pollute the link line with
compiler flags (which can be desirable for build cleanliness). Instead,
set `CMAKE_EXE_LINKER_FLAGS` explicitly and use `CMP0056` to ensure the
linker flags are passed along. Additionally, since we're inside a
function, we can just alter the variable directly (as the alteration
will be limited to the scope of the function) rather than saving and
restoring the old value.

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

Modified:
    llvm/trunk/CMakeLists.txt
    llvm/trunk/cmake/modules/CheckLinkerFlag.cmake

Modified: llvm/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/CMakeLists.txt?rev=316972&r1=316971&r2=316972&view=diff
==============================================================================
--- llvm/trunk/CMakeLists.txt (original)
+++ llvm/trunk/CMakeLists.txt Mon Oct 30 18:30:46 2017
@@ -15,6 +15,10 @@ if (POLICY CMP0051)
   cmake_policy(SET CMP0051 OLD)
 endif()
 
+if(POLICY CMP0056)
+  cmake_policy(SET CMP0056 NEW)
+endif()
+
 if(POLICY CMP0057)
   cmake_policy(SET CMP0057 NEW)
 endif()

Modified: llvm/trunk/cmake/modules/CheckLinkerFlag.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/CheckLinkerFlag.cmake?rev=316972&r1=316971&r2=316972&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/CheckLinkerFlag.cmake (original)
+++ llvm/trunk/cmake/modules/CheckLinkerFlag.cmake Mon Oct 30 18:30:46 2017
@@ -1,8 +1,6 @@
 include(CheckCXXCompilerFlag)
 
 function(check_linker_flag flag out_var)
-  set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
-  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}")
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}")
   check_cxx_compiler_flag("" ${out_var})
-  set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
 endfunction()




More information about the llvm-commits mailing list