Skip to content

Commit 8c1b899

Browse files
mstorsjoh-vetinari
authored andcommitted
[runtimes] [CMake] Use CMAKE_REQUIRED_LINK_OPTIONS to simplify handling of the --unwindlib=none option
This avoids passing the option unnecessarily to compilation commands (where it causes warnings). This fails in practice with libunwind, where setting CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY breaks it, as the option from CMAKE_REQUIRED_LINK_OPTIONS ends up passed to the "ar" tool too.
1 parent 6859685 commit 8c1b899

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

libunwind/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,12 @@ add_cxx_compile_flags_if_supported(-EHsc)
221221
# This leads to libunwind not being built with this flag, which makes
222222
# libunwind quite useless in this setup.
223223
set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
224+
set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
224225
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
226+
set(CMAKE_REQUIRED_LINK_OPTIONS)
225227
add_compile_flags_if_supported(-funwind-tables)
226228
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
229+
set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
227230

228231
if (LIBUNWIND_USES_ARM_EHABI AND NOT CXX_SUPPORTS_FUNWIND_TABLES_FLAG)
229232
message(SEND_ERROR "The -funwind-tables flag must be supported "

runtimes/CMakeLists.txt

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,27 +116,7 @@ filter_prefixed("${CMAKE_ASM_IMPLICIT_INCLUDE_DIRECTORIES}" ${LLVM_BINARY_DIR} C
116116
# brittle. We should ideally move this to runtimes/CMakeLists.txt.
117117
llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
118118
if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
119-
set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
120-
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --unwindlib=none")
121-
# TODO: When we can require CMake 3.14, we should use
122-
# CMAKE_REQUIRED_LINK_OPTIONS here. Until then, we need a workaround:
123-
# When using CMAKE_REQUIRED_FLAGS, this option gets added both to
124-
# compilation and linking commands. That causes warnings in the
125-
# compilation commands during cmake tests. This is normally benign, but
126-
# when testing whether -Werror works, that test fails (due to the
127-
# preexisting warning).
128-
#
129-
# Therefore, before we can use CMAKE_REQUIRED_LINK_OPTIONS, check if we
130-
# can use --start-no-unused-arguments to silence the warnings about
131-
# --unwindlib=none during compilation.
132-
#
133-
# We must first add --unwindlib=none to CMAKE_REQUIRED_FLAGS above, to
134-
# allow this subsequent test to succeed, then rewrite CMAKE_REQUIRED_FLAGS
135-
# below.
136-
check_c_compiler_flag("--start-no-unused-arguments" C_SUPPORTS_START_NO_UNUSED_ARGUMENTS)
137-
if (C_SUPPORTS_START_NO_UNUSED_ARGUMENTS)
138-
set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS} --start-no-unused-arguments --unwindlib=none --end-no-unused-arguments")
139-
endif()
119+
list(APPEND CMAKE_REQUIRED_LINK_OPTIONS "--unwindlib=none")
140120
endif()
141121

142122
# Disable use of the installed C++ standard library when building runtimes.

0 commit comments

Comments
 (0)