File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -103,11 +103,27 @@ endmacro()
103
103
# For each specified flag, add that compile flag to the provided target.
104
104
# The flags are added with the given visibility, i.e. PUBLIC|PRIVATE|INTERFACE.
105
105
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
+
106
118
foreach (flag ${ARGN} )
107
119
mangle_name ("${flag} " flagname )
108
120
check_cxx_compiler_flag ("${flag} " "CXX_SUPPORTS_${flagname} _FLAG" )
109
121
if (CXX_SUPPORTS_${flagname}_FLAG )
110
122
target_compile_options (${target} ${visibility} ${flag} )
111
123
endif ()
112
124
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} )
113
129
endfunction ()
You can’t perform that action at this time.
0 commit comments