Skip to content

Commit 47e7688

Browse files
committed
[cmake] also do static-vs-linker work-around for target_add_compile_flags_if_supported
1 parent 216799a commit 47e7688

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

runtimes/cmake/Modules/HandleFlags.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,27 @@ endmacro()
103103
# For each specified flag, add that compile flag to the provided target.
104104
# The flags are added with the given visibility, i.e. PUBLIC|PRIVATE|INTERFACE.
105105
function(target_add_compile_flags_if_supported target visibility)
106+
107+
# Disable linker for CMake flag compatibility checks
108+
#
109+
# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
110+
# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
111+
# for static targets; cache the target type here, and reset it after the various
112+
# checks have been performed.
113+
set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
114+
set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
115+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
116+
set(CMAKE_REQUIRED_LINK_OPTIONS)
117+
106118
foreach(flag ${ARGN})
107119
mangle_name("${flag}" flagname)
108120
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
109121
if (CXX_SUPPORTS_${flagname}_FLAG)
110122
target_compile_options(${target} ${visibility} ${flag})
111123
endif()
112124
endforeach()
125+
126+
# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
127+
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
128+
set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
113129
endfunction()

0 commit comments

Comments
 (0)