llvm.org GIT mirror llvm / 6c2f3c2
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316972 91177308-0d34-0410-b5e6-96231b3b80d8 Shoaib Meenai 1 year, 11 months ago
2 changed file(s) with 5 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
1212 # defer to the OLD behavior of not including generator expressions
1313 # in the output for now.
1414 cmake_policy(SET CMP0051 OLD)
15 endif()
16
17 if(POLICY CMP0056)
18 cmake_policy(SET CMP0056 NEW)
1519 endif()
1620
1721 if(POLICY CMP0057)
0 include(CheckCXXCompilerFlag)
11
22 function(check_linker_flag flag out_var)
3 set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
4 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}")
3 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}")
54 check_cxx_compiler_flag("" ${out_var})
6 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
75 endfunction()