diff --git a/clang/tools/driver/CMakeLists.txt b/clang/tools/driver/CMakeLists.txt --- a/clang/tools/driver/CMakeLists.txt +++ b/clang/tools/driver/CMakeLists.txt @@ -93,7 +93,7 @@ if(CLANG_ORDER_FILE AND (LLVM_LINKER_IS_LD64 OR LLVM_LINKER_IS_GOLD OR LLVM_LINKER_IS_LLD)) - include(CheckLinkerFlag) + include(LLVMCheckLinkerFlag) if (LLVM_LINKER_IS_LD64) set(LINKER_ORDER_FILE_OPTION "-Wl,-order_file,${CLANG_ORDER_FILE}") @@ -104,7 +104,7 @@ endif() # This is a test to ensure the actual order file works with the linker. - check_linker_flag(${LINKER_ORDER_FILE_OPTION} LINKER_ORDER_FILE_WORKS) + llvm_check_linker_flag(CXX ${LINKER_ORDER_FILE_OPTION} LINKER_ORDER_FILE_WORKS) # Passing an empty order file disables some linker layout optimizations. # To work around this and enable workflows for re-linking when the order file diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -236,8 +236,8 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") # Support for ld -z discard-unused=sections was only added in # Solaris 11.4. - include(CheckLinkerFlag) - check_linker_flag("-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED) + include(LLVMCheckLinkerFlag) + llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED) if (LINKER_SUPPORTS_Z_DISCARD_UNUSED) set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-z,discard-unused=sections") diff --git a/llvm/cmake/modules/CheckLinkerFlag.cmake b/llvm/cmake/modules/CheckLinkerFlag.cmake deleted file mode 100644 --- a/llvm/cmake/modules/CheckLinkerFlag.cmake +++ /dev/null @@ -1,6 +0,0 @@ -include(CheckCXXCompilerFlag) - -function(check_linker_flag flag out_var) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}") - check_cxx_compiler_flag("" ${out_var}) -endfunction() diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -888,8 +888,8 @@ # lld doesn't print colored diagnostics when invoked from Ninja if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja") - include(CheckLinkerFlag) - check_linker_flag("-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS) + include(LLVMCheckLinkerFlag) + llvm_check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS) append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics" CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) endif() diff --git a/llvm/cmake/modules/HandleLLVMStdlib.cmake b/llvm/cmake/modules/HandleLLVMStdlib.cmake --- a/llvm/cmake/modules/HandleLLVMStdlib.cmake +++ b/llvm/cmake/modules/HandleLLVMStdlib.cmake @@ -13,12 +13,12 @@ endfunction() include(CheckCXXCompilerFlag) - include(CheckLinkerFlag) + include(LLVMCheckLinkerFlag) set(LLVM_LIBCXX_USED 0) if(LLVM_ENABLE_LIBCXX) if(LLVM_COMPILER_IS_GCC_COMPATIBLE) check_cxx_compiler_flag("-stdlib=libc++" CXX_COMPILER_SUPPORTS_STDLIB) - check_linker_flag("-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB) + llvm_check_linker_flag(CXX "-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB) if(CXX_COMPILER_SUPPORTS_STDLIB AND CXX_LINKER_SUPPORTS_STDLIB) append("-stdlib=libc++" CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS @@ -36,7 +36,7 @@ if(LLVM_COMPILER_IS_GCC_COMPATIBLE) check_cxx_compiler_flag("-static-libstdc++" CXX_COMPILER_SUPPORTS_STATIC_STDLIB) - check_linker_flag("-static-libstdc++" CXX_LINKER_SUPPORTS_STATIC_STDLIB) + llvm_check_linker_flag(CXX "-static-libstdc++" CXX_LINKER_SUPPORTS_STATIC_STDLIB) if(CXX_COMPILER_SUPPORTS_STATIC_STDLIB AND CXX_LINKER_SUPPORTS_STATIC_STDLIB) append("-static-libstdc++" diff --git a/llvm/cmake/modules/LLVMCheckLinkerFlag.cmake b/llvm/cmake/modules/LLVMCheckLinkerFlag.cmake new file mode 100644 --- /dev/null +++ b/llvm/cmake/modules/LLVMCheckLinkerFlag.cmake @@ -0,0 +1,17 @@ +include(CheckLinkerFlag OPTIONAL) + +if (COMMAND check_linker_flag) + macro(llvm_check_linker_flag) + check_linker_flag(${ARGN}) + endmacro() +else() + include(CheckCXXCompilerFlag) + + # cmake builtin compatible, except we assume lang is CXX + function(llvm_check_linker_flag lang flag out_var) + cmake_push_check_state() + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}") + check_cxx_compiler_flag("" ${out_var}) + cmake_pop_check_state() + endfunction() +endif()