Files
clang-p2996/cmake/Modules/LLVMCheckLinkerFlag.cmake
Petr Hosek efae3174f0 [CMake] Unify llvm_check_linker_flag and llvm_check_compiler_linker_flag
These have the same purposes but two different implementations.
llvm_check_compiler_linker_flag uses CMAKE_REQUIRED_FLAGS which affects
flags used both for compilation and linking which is problematic because
some flags may be link-only and trigger unused argument warning when set
during compilation. llvm_check_linker_flag does not have this issue so
we chose it as the prevailaing implementation.

Differential Revision: https://reviews.llvm.org/D143052
2023-02-22 04:24:49 +00:00

29 lines
879 B
CMake

include(CheckLinkerFlag OPTIONAL)
if (COMMAND check_linker_flag)
macro(llvm_check_linker_flag)
check_linker_flag(${ARGN})
endmacro()
else()
# Until the minimum CMAKE version is 3.18
include(CheckCXXCompilerFlag)
# 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)
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})
elseif("${lang}" STREQUAL "CXX")
check_cxx_compiler_flag("" ${out_var})
else()
message(FATAL_ERROR "\"${lang}\" is not C or CXX")
endif()
set(CMAKE_EXE_LINKER_FLAGS ${_CMAKE_EXE_LINKER_FLAGS_SAVE})
cmake_policy(POP)
endfunction()
endif()