[llvm] 06d06f2 - [CMake][llvm] avoid conflict w/ (and use when available) new builtin check_linker_flag
Francis Visoiu Mistrih via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 27 16:43:39 PDT 2021
Author: Jim Radford
Date: 2021-04-27T16:41:28-07:00
New Revision: 06d06f2f6403066415df7b8854e6aff7586a92df
URL: https://github.com/llvm/llvm-project/commit/06d06f2f6403066415df7b8854e6aff7586a92df
DIFF: https://github.com/llvm/llvm-project/commit/06d06f2f6403066415df7b8854e6aff7586a92df.diff
LOG: [CMake][llvm] avoid conflict w/ (and use when available) new builtin check_linker_flag
Match the API for the new check_linker_flag and use it directly when
available, leaving the old code as a fallback.
Differential Revision: https://reviews.llvm.org/D100901
Added:
llvm/cmake/modules/LLVMCheckLinkerFlag.cmake
Modified:
clang/tools/driver/CMakeLists.txt
llvm/cmake/modules/AddLLVM.cmake
llvm/cmake/modules/HandleLLVMOptions.cmake
llvm/cmake/modules/HandleLLVMStdlib.cmake
Removed:
llvm/cmake/modules/CheckLinkerFlag.cmake
################################################################################
diff --git a/clang/tools/driver/CMakeLists.txt b/clang/tools/driver/CMakeLists.txt
index 01efebdcb929..7c32aadb8700 100644
--- a/clang/tools/driver/CMakeLists.txt
+++ b/clang/tools/driver/CMakeLists.txt
@@ -93,7 +93,7 @@ endif()
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 @@ if(CLANG_ORDER_FILE AND
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
index 2f055c779962..9bfef6dd8473 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -236,8 +236,8 @@ function(add_link_opts target_name)
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
index fe9d01a349cd..000000000000
--- 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
index e7c30e9d0082..ee91386055f7 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -888,8 +888,8 @@ endif()
# 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
index b67d87d43005..7afc10cff74f 100644
--- a/llvm/cmake/modules/HandleLLVMStdlib.cmake
+++ b/llvm/cmake/modules/HandleLLVMStdlib.cmake
@@ -13,12 +13,12 @@ if(NOT DEFINED LLVM_STDLIB_HANDLED)
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(NOT DEFINED LLVM_STDLIB_HANDLED)
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
index 000000000000..90d752048564
--- /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()
More information about the llvm-commits
mailing list