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 @@ -333,10 +333,26 @@ function(append_if condition value)
333
333
endfunction ()
334
334
335
335
macro (add_flag_if_supported flag name )
336
+
337
+ # Disable linker for CMake flag compatibility checks
338
+ #
339
+ # Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
340
+ # disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
341
+ # for static targets; cache the target type here, and reset it after the various
342
+ # checks have been performed.
343
+ set (_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE} )
344
+ set (_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS} )
345
+ set (CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY )
346
+ set (CMAKE_REQUIRED_LINK_OPTIONS )
347
+
336
348
check_c_compiler_flag ("-Werror ${flag} " "C_SUPPORTS_${name} " )
337
349
append_if ("C_SUPPORTS_${name} " "${flag} " CMAKE_C_FLAGS )
338
350
check_cxx_compiler_flag ("-Werror ${flag} " "CXX_SUPPORTS_${name} " )
339
351
append_if ("CXX_SUPPORTS_${name} " "${flag} " CMAKE_CXX_FLAGS )
352
+
353
+ # reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
354
+ set (CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE} )
355
+ set (CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS} )
340
356
endmacro ()
341
357
342
358
function (add_flag_or_print_warning flag name )
You can’t perform that action at this time.
0 commit comments