Skip to content

Commit 6ade702

Browse files
committed
[cmake] also do static-vs-linker work-around for add_flag_if_supported
1 parent 11cbf4f commit 6ade702

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,26 @@ function(append_if condition value)
333333
endfunction()
334334

335335
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+
336348
check_c_compiler_flag("-Werror ${flag}" "C_SUPPORTS_${name}")
337349
append_if("C_SUPPORTS_${name}" "${flag}" CMAKE_C_FLAGS)
338350
check_cxx_compiler_flag("-Werror ${flag}" "CXX_SUPPORTS_${name}")
339351
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})
340356
endmacro()
341357

342358
function(add_flag_or_print_warning flag name)

0 commit comments

Comments
 (0)