Skip to content

Commit f34093a

Browse files
committed
[cmake] also do static-vs-linker work-around for libcxx{,abi}'s add_flags_if_supported
1 parent fcd9671 commit f34093a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

libcxx/cmake/Modules/HandleLibcxxFlags.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,27 @@ endmacro()
2929
# Add each flag in the list to LIBCXX_COMPILE_FLAGS and LIBCXX_LINK_FLAGS
3030
# if that flag is supported by the current compiler.
3131
macro(add_flags_if_supported)
32+
33+
# Disable linker for CMake flag compatibility checks
34+
#
35+
# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
36+
# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
37+
# for static targets; cache the target type here, and reset it after the various
38+
# checks have been performed.
39+
set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
40+
set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
41+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
42+
set(CMAKE_REQUIRED_LINK_OPTIONS)
43+
3244
foreach(flag ${ARGN})
3345
mangle_name("${flag}" flagname)
3446
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
3547
add_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag})
3648
endforeach()
49+
50+
# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
51+
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
52+
set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
3753
endmacro()
3854

3955
# Add a list of flags to 'LIBCXX_LINK_FLAGS'.

libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,27 @@ endmacro()
2929
# Add each flag in the list to LIBCXXABI_COMPILE_FLAGS and LIBCXXABI_LINK_FLAGS
3030
# if that flag is supported by the current compiler.
3131
macro(add_flags_if_supported)
32+
33+
# Disable linker for CMake flag compatibility checks
34+
#
35+
# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
36+
# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
37+
# for static targets; cache the target type here, and reset it after the various
38+
# checks have been performed.
39+
set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
40+
set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
41+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
42+
set(CMAKE_REQUIRED_LINK_OPTIONS)
43+
3244
foreach(flag ${ARGN})
3345
mangle_name("${flag}" flagname)
3446
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
3547
add_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag})
3648
endforeach()
49+
50+
# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
51+
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
52+
set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
3753
endmacro()
3854

3955
# Add a list of flags to 'LIBCXXABI_COMPILE_FLAGS'.

0 commit comments

Comments
 (0)