Skip to content

Commit 89946bd

Browse files
[cmake] switch to CMake's native check_{compiler,linker}_flag (#96171)
Broken out from #93429 Somewhat closing the loop opened by 7017e6c. Co-authored-by: Ryan Prichard <[email protected]>
1 parent 9b017db commit 89946bd

File tree

9 files changed

+17
-64
lines changed

9 files changed

+17
-64
lines changed

clang/tools/clang-repl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export_executable_symbols_for_plugins(clang-repl)
6969
# gold. This flag tells the linker to build a PLT for the full address range.
7070
# Linkers without this flag are assumed to support proper PLTs by default.
7171
set(flag_long_plt "-Wl,--long-plt")
72-
llvm_check_linker_flag(CXX ${flag_long_plt} HAVE_LINKER_FLAG_LONG_PLT)
72+
check_linker_flag(CXX ${flag_long_plt} HAVE_LINKER_FLAG_LONG_PLT)
7373
if(HAVE_LINKER_FLAG_LONG_PLT)
7474
target_link_options(clang-repl PRIVATE ${flag_long_plt})
7575
endif()

clang/tools/driver/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ endif()
107107

108108
if(CLANG_ORDER_FILE AND
109109
(LLVM_LINKER_IS_APPLE OR LLVM_LINKER_IS_GOLD OR LLVM_LINKER_IS_LLD))
110-
include(LLVMCheckLinkerFlag)
110+
include(CheckLinkerFlag)
111111

112112
if (LLVM_LINKER_IS_APPLE OR (LLVM_LINKER_IS_LLD AND APPLE))
113113
set(LINKER_ORDER_FILE_OPTION "-Wl,-order_file,${CLANG_ORDER_FILE}")
@@ -118,7 +118,7 @@ if(CLANG_ORDER_FILE AND
118118
endif()
119119

120120
# This is a test to ensure the actual order file works with the linker.
121-
llvm_check_linker_flag(CXX ${LINKER_ORDER_FILE_OPTION} LINKER_ORDER_FILE_WORKS)
121+
check_linker_flag(CXX ${LINKER_ORDER_FILE_OPTION} LINKER_ORDER_FILE_WORKS)
122122

123123
# Passing an empty order file disables some linker layout optimizations.
124124
# To work around this and enable workflows for re-linking when the order file
Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
include(CMakePushCheckState)
2-
3-
include(CheckCompilerFlag OPTIONAL)
4-
5-
if(NOT COMMAND check_compiler_flag)
6-
include(CheckCCompilerFlag)
7-
include(CheckCXXCompilerFlag)
8-
endif()
2+
include(CheckCompilerFlag)
93

104
function(llvm_check_compiler_linker_flag lang flag out_var)
11-
# If testing a flag with check_c_compiler_flag, it gets added to the compile
5+
# If testing a flag with check_compiler_flag, it gets added to the compile
126
# command only, but not to the linker command in that test. If the flag
137
# is vital for linking to succeed, the test would fail even if it would
148
# have succeeded if it was included on both commands.
@@ -18,18 +12,6 @@ function(llvm_check_compiler_linker_flag lang flag out_var)
1812

1913
cmake_push_check_state()
2014
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}")
21-
if(COMMAND check_compiler_flag)
22-
check_compiler_flag("${lang}" "" ${out_var})
23-
else()
24-
# Until the minimum CMAKE version is 3.19
25-
# cmake builtin compatible, except we assume lang is C or CXX
26-
if("${lang}" STREQUAL "C")
27-
check_c_compiler_flag("" ${out_var})
28-
elseif("${lang}" STREQUAL "CXX")
29-
check_cxx_compiler_flag("" ${out_var})
30-
else()
31-
message(FATAL_ERROR "\"${lang}\" is not C or CXX")
32-
endif()
33-
endif()
15+
check_compiler_flag("${lang}" "" ${out_var})
3416
cmake_pop_check_state()
3517
endfunction()

compiler-rt/cmake/config-ix.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
include(CMakePushCheckState)
22
include(AddLLVM)
3-
include(LLVMCheckCompilerLinkerFlag)
43
include(CheckCCompilerFlag)
54
include(CheckCXXCompilerFlag)
65
include(CheckIncludeFiles)
@@ -15,7 +14,7 @@ include(TestBigEndian)
1514
# in tree version of runtimes, we'd be linking against the just-built
1615
# libunwind (and the compiler implicit -lunwind wouldn't succeed as the newly
1716
# built libunwind isn't installed yet). For those cases, it'd be good to
18-
# link with --uwnindlib=none. Check if that option works.
17+
# link with --unwindlib=none. Check if that option works.
1918
llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_NONE_FLAG)
2019

2120
check_library_exists(c fopen "" COMPILER_RT_HAS_LIBC)

libcxx/cmake/config-ix.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include(CheckCSourceCompiles)
1212
# LIBCXXABI_USE_LLVM_UNWINDER set, we'd be linking against the just-built
1313
# libunwind (and the compiler implicit -lunwind wouldn't succeed as the newly
1414
# built libunwind isn't installed yet). For those cases, it'd be good to
15-
# link with --uwnindlib=none. Check if that option works.
15+
# link with --unwindlib=none. Check if that option works.
1616
llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
1717

1818
if (NOT LIBCXX_USE_COMPILER_RT)

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ function(add_link_opts target_name)
327327
elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
328328
# Support for ld -z discard-unused=sections was only added in
329329
# Solaris 11.4. GNU ld ignores it, but warns every time.
330-
include(LLVMCheckLinkerFlag)
331-
llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED)
330+
include(CheckLinkerFlag)
331+
check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED)
332332
if (LINKER_SUPPORTS_Z_DISCARD_UNUSED)
333333
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
334334
LINK_FLAGS " -Wl,-z,discard-unused=sections")

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,8 @@ if (LLVM_USE_SPLIT_DWARF AND
10611061
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
10621062
CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
10631063
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-gsplit-dwarf>)
1064-
include(LLVMCheckLinkerFlag)
1065-
llvm_check_linker_flag(CXX "-Wl,--gdb-index" LINKER_SUPPORTS_GDB_INDEX)
1064+
include(CheckLinkerFlag)
1065+
check_linker_flag(CXX "-Wl,--gdb-index" LINKER_SUPPORTS_GDB_INDEX)
10661066
append_if(LINKER_SUPPORTS_GDB_INDEX "-Wl,--gdb-index"
10671067
CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
10681068
endif()
@@ -1083,8 +1083,8 @@ endif()
10831083

10841084
# lld doesn't print colored diagnostics when invoked from Ninja
10851085
if (UNIX AND CMAKE_GENERATOR MATCHES "Ninja")
1086-
include(LLVMCheckLinkerFlag)
1087-
llvm_check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS)
1086+
include(CheckLinkerFlag)
1087+
check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS)
10881088
append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics"
10891089
CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
10901090
endif()

llvm/cmake/modules/HandleLLVMStdlib.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ if(NOT DEFINED LLVM_STDLIB_HANDLED)
1313
endfunction()
1414

1515
include(CheckCXXCompilerFlag)
16-
include(LLVMCheckLinkerFlag)
16+
include(CheckLinkerFlag)
1717
set(LLVM_LIBCXX_USED 0)
1818
if(LLVM_ENABLE_LIBCXX)
1919
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
2020
check_cxx_compiler_flag("-stdlib=libc++" CXX_COMPILER_SUPPORTS_STDLIB)
21-
llvm_check_linker_flag(CXX "-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB)
21+
check_linker_flag(CXX "-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB)
2222
if(CXX_COMPILER_SUPPORTS_STDLIB AND CXX_LINKER_SUPPORTS_STDLIB)
2323
append("-stdlib=libc++"
2424
CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS
@@ -36,7 +36,7 @@ if(NOT DEFINED LLVM_STDLIB_HANDLED)
3636
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
3737
check_cxx_compiler_flag("-static-libstdc++"
3838
CXX_COMPILER_SUPPORTS_STATIC_STDLIB)
39-
llvm_check_linker_flag(CXX "-static-libstdc++" CXX_LINKER_SUPPORTS_STATIC_STDLIB)
39+
check_linker_flag(CXX "-static-libstdc++" CXX_LINKER_SUPPORTS_STATIC_STDLIB)
4040
if(CXX_COMPILER_SUPPORTS_STATIC_STDLIB AND
4141
CXX_LINKER_SUPPORTS_STATIC_STDLIB)
4242
append("-static-libstdc++"

llvm/cmake/modules/LLVMCheckLinkerFlag.cmake

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)