[Openmp-commits] [compiler-rt] [libcxx] [libcxxabi] [libunwind] [llvm] [openmp] [runtimes] remove workaround for old CMake when setting `--unwindlib=none` (PR #93429)
via Openmp-commits
openmp-commits at lists.llvm.org
Sun Aug 11 22:38:39 PDT 2024
https://github.com/h-vetinari updated https://github.com/llvm/llvm-project/pull/93429
>From 8c1b899aa174b107fece1edbf99eaf261bdea516 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Mon, 25 Apr 2022 09:45:22 +0300
Subject: [PATCH 01/15] [runtimes] [CMake] Use CMAKE_REQUIRED_LINK_OPTIONS to
simplify handling of the --unwindlib=none option
This avoids passing the option unnecessarily to compilation commands
(where it causes warnings).
This fails in practice with libunwind, where setting
CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY breaks it, as
the option from CMAKE_REQUIRED_LINK_OPTIONS ends up passed to the "ar"
tool too.
---
libunwind/CMakeLists.txt | 3 +++
runtimes/CMakeLists.txt | 22 +---------------------
2 files changed, 4 insertions(+), 21 deletions(-)
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index b22ade0a7d71eb..3d2fadca9d2ecf 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -221,9 +221,12 @@ add_cxx_compile_flags_if_supported(-EHsc)
# This leads to libunwind not being built with this flag, which makes
# libunwind quite useless in this setup.
set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+set(CMAKE_REQUIRED_LINK_OPTIONS)
add_compile_flags_if_supported(-funwind-tables)
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
if (LIBUNWIND_USES_ARM_EHABI AND NOT CXX_SUPPORTS_FUNWIND_TABLES_FLAG)
message(SEND_ERROR "The -funwind-tables flag must be supported "
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 24f48511695915..8f909322c9a98c 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -116,27 +116,7 @@ filter_prefixed("${CMAKE_ASM_IMPLICIT_INCLUDE_DIRECTORIES}" ${LLVM_BINARY_DIR} C
# brittle. We should ideally move this to runtimes/CMakeLists.txt.
llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
- set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --unwindlib=none")
- # TODO: When we can require CMake 3.14, we should use
- # CMAKE_REQUIRED_LINK_OPTIONS here. Until then, we need a workaround:
- # When using CMAKE_REQUIRED_FLAGS, this option gets added both to
- # compilation and linking commands. That causes warnings in the
- # compilation commands during cmake tests. This is normally benign, but
- # when testing whether -Werror works, that test fails (due to the
- # preexisting warning).
- #
- # Therefore, before we can use CMAKE_REQUIRED_LINK_OPTIONS, check if we
- # can use --start-no-unused-arguments to silence the warnings about
- # --unwindlib=none during compilation.
- #
- # We must first add --unwindlib=none to CMAKE_REQUIRED_FLAGS above, to
- # allow this subsequent test to succeed, then rewrite CMAKE_REQUIRED_FLAGS
- # below.
- check_c_compiler_flag("--start-no-unused-arguments" C_SUPPORTS_START_NO_UNUSED_ARGUMENTS)
- if (C_SUPPORTS_START_NO_UNUSED_ARGUMENTS)
- set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS} --start-no-unused-arguments --unwindlib=none --end-no-unused-arguments")
- endif()
+ list(APPEND CMAKE_REQUIRED_LINK_OPTIONS "--unwindlib=none")
endif()
# Disable use of the installed C++ standard library when building runtimes.
>From 816e9e6d81ac12537879406e0495fc80394a1a66 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Thu, 20 Jun 2024 23:18:51 +1100
Subject: [PATCH 02/15] add comment (and CMake issue reference) about
incompatible options
---
libunwind/CMakeLists.txt | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 3d2fadca9d2ecf..d84f8fa6ff954b 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -220,6 +220,10 @@ add_cxx_compile_flags_if_supported(-EHsc)
#
# This leads to libunwind not being built with this flag, which makes
# libunwind quite useless in this setup.
+#
+# NOTE: we need to work around https://gitlab.kitware.com/cmake/cmake/-/issues/23454
+# because CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
+# is incompatible with CMAKE_TRY_COMPILE_TARGET_TYPE==STATIC_LIBRARY.
set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
>From 3f917d22bdcd8b398cf7162563547418a056ecec Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Thu, 20 Jun 2024 23:18:51 +1100
Subject: [PATCH 03/15] [cmake] move check for `-fno-exceptions` to "safe zone"
w.r.t. interference between CMAKE_REQUIRED_LINK_OPTIONS and static libraries
---
libunwind/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index d84f8fa6ff954b..d8aad8d73befab 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -229,6 +229,7 @@ set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_REQUIRED_LINK_OPTIONS)
add_compile_flags_if_supported(-funwind-tables)
+add_cxx_compile_flags_if_supported(-fno-exceptions)
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
@@ -237,7 +238,6 @@ if (LIBUNWIND_USES_ARM_EHABI AND NOT CXX_SUPPORTS_FUNWIND_TABLES_FLAG)
"because this target uses ARM Exception Handling ABI")
endif()
-add_cxx_compile_flags_if_supported(-fno-exceptions)
add_cxx_compile_flags_if_supported(-fno-rtti)
# Ensure that we don't depend on C++ standard library.
>From a8dd830691e433f79738c4ce8258b122f2cb2f77 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Wed, 26 Jun 2024 15:40:51 +1100
Subject: [PATCH 04/15] [cmake] same for `-fno-rtti`
---
libunwind/CMakeLists.txt | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index d8aad8d73befab..6dd2f4a813fd9c 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -230,6 +230,7 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_REQUIRED_LINK_OPTIONS)
add_compile_flags_if_supported(-funwind-tables)
add_cxx_compile_flags_if_supported(-fno-exceptions)
+add_cxx_compile_flags_if_supported(-fno-rtti)
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
@@ -238,8 +239,6 @@ if (LIBUNWIND_USES_ARM_EHABI AND NOT CXX_SUPPORTS_FUNWIND_TABLES_FLAG)
"because this target uses ARM Exception Handling ABI")
endif()
-add_cxx_compile_flags_if_supported(-fno-rtti)
-
# Ensure that we don't depend on C++ standard library.
if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++)
>From 7444457b1e3df1d923891d301b507a3909e21b09 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Wed, 26 Jun 2024 17:47:05 +1100
Subject: [PATCH 05/15] [cmake] run _all_ flag checks in
runtimes/CMakeLists.txt without linker
---
libunwind/CMakeLists.txt | 49 ++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 25 deletions(-)
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 6dd2f4a813fd9c..ebef3fdcfe86a0 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -175,6 +175,23 @@ if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt")
endif()
+# Disable linker for running CMake checks
+#
+# This was originally added because when building libunwind for ARM Linux,
+# we need to pass the -funwind-tables flag in order for it to work properly
+# with ARM EHABI. However, this produces a false negative when performing CMake
+# checks, causing libunwind to not be built with this flag.
+#
+# A similar dynamic occurred with the advent of CMAKE_REQUIRED_LINK_OPTIONS
+# (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG), which causes flag checks for static
+# targets to fail due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454.
+# Thus, to avoid failures with static targets, we cache the target type here,
+# and reset it after the various flag support checks have been performed.
+set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+set(CMAKE_REQUIRED_LINK_OPTIONS)
+
add_compile_flags_if_supported(-Werror=return-type)
if (LIBUNWIND_ENABLE_CET)
@@ -207,38 +224,16 @@ endif()
add_cxx_compile_flags_if_supported(-fstrict-aliasing)
add_cxx_compile_flags_if_supported(-EHsc)
-# Don't run the linker in this CMake check.
-#
-# The reason why this was added is that when building libunwind for
-# ARM Linux, we need to pass the -funwind-tables flag in order for it to
-# work properly with ARM EHABI.
-#
-# However, when performing CMake checks, adding this flag causes the check
-# to produce a false negative, because the compiler generates calls
-# to __aeabi_unwind_cpp_pr0, which is defined in libunwind itself,
-# which isn't built yet, so the linker complains about undefined symbols.
-#
-# This leads to libunwind not being built with this flag, which makes
-# libunwind quite useless in this setup.
-#
-# NOTE: we need to work around https://gitlab.kitware.com/cmake/cmake/-/issues/23454
-# because CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
-# is incompatible with CMAKE_TRY_COMPILE_TARGET_TYPE==STATIC_LIBRARY.
-set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
-set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-set(CMAKE_REQUIRED_LINK_OPTIONS)
add_compile_flags_if_supported(-funwind-tables)
-add_cxx_compile_flags_if_supported(-fno-exceptions)
-add_cxx_compile_flags_if_supported(-fno-rtti)
-set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
if (LIBUNWIND_USES_ARM_EHABI AND NOT CXX_SUPPORTS_FUNWIND_TABLES_FLAG)
message(SEND_ERROR "The -funwind-tables flag must be supported "
"because this target uses ARM Exception Handling ABI")
endif()
+add_cxx_compile_flags_if_supported(-fno-exceptions)
+add_cxx_compile_flags_if_supported(-fno-rtti)
+
# Ensure that we don't depend on C++ standard library.
if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++)
@@ -292,6 +287,10 @@ if (LIBUNWIND_ENABLE_ARM_WMMX)
add_compile_flags(-D__ARM_WMMX)
endif()
+# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
+set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
+
if(LIBUNWIND_IS_BAREMETAL)
add_compile_definitions(_LIBUNWIND_IS_BAREMETAL)
endif()
>From 216799acde01688067ea3f0782b73ce4bd6551a2 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Wed, 26 Jun 2024 21:18:36 +1100
Subject: [PATCH 06/15] [cmake] also do static-vs-linker work-around for
cxx_add_warning_flags
---
libunwind/CMakeLists.txt | 8 ++++----
runtimes/cmake/Modules/WarningFlags.cmake | 16 ++++++++++++++++
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index ebef3fdcfe86a0..c787a560470ad3 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -234,6 +234,10 @@ endif()
add_cxx_compile_flags_if_supported(-fno-exceptions)
add_cxx_compile_flags_if_supported(-fno-rtti)
+# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
+set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
+
# Ensure that we don't depend on C++ standard library.
if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++)
@@ -287,10 +291,6 @@ if (LIBUNWIND_ENABLE_ARM_WMMX)
add_compile_flags(-D__ARM_WMMX)
endif()
-# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
-set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
-
if(LIBUNWIND_IS_BAREMETAL)
add_compile_definitions(_LIBUNWIND_IS_BAREMETAL)
endif()
diff --git a/runtimes/cmake/Modules/WarningFlags.cmake b/runtimes/cmake/Modules/WarningFlags.cmake
index d06409841dc9df..2330ad2c0cc6f0 100644
--- a/runtimes/cmake/Modules/WarningFlags.cmake
+++ b/runtimes/cmake/Modules/WarningFlags.cmake
@@ -3,6 +3,18 @@ include(HandleFlags)
# Warning flags ===============================================================
function(cxx_add_warning_flags target enable_werror enable_pedantic)
target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+
+ # Disable linker for CMake flag compatibility checks
+ #
+ # Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
+ # disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
+ # for static targets; cache the target type here, and reset it after the various
+ # checks have been performed.
+ set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+ set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+ set(CMAKE_REQUIRED_LINK_OPTIONS)
+
if (MSVC)
# -W4 is the cl.exe/clang-cl equivalent of -Wall. (In cl.exe and clang-cl,
# -Wall is equivalent to -Weverything in GCC style compiler drivers.)
@@ -74,4 +86,8 @@ function(cxx_add_warning_flags target enable_werror enable_pedantic)
if (${enable_pedantic})
target_add_compile_flags_if_supported(${target} PRIVATE -pedantic)
endif()
+
+ # reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+ set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
endfunction()
>From 47e7688b74a723eb4105a9bfb41c024665adda5d Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Thu, 27 Jun 2024 09:30:05 +1100
Subject: [PATCH 07/15] [cmake] also do static-vs-linker work-around for
target_add_compile_flags_if_supported
---
runtimes/cmake/Modules/HandleFlags.cmake | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/runtimes/cmake/Modules/HandleFlags.cmake b/runtimes/cmake/Modules/HandleFlags.cmake
index 4a62b67169e4d6..6bb3d92043b462 100644
--- a/runtimes/cmake/Modules/HandleFlags.cmake
+++ b/runtimes/cmake/Modules/HandleFlags.cmake
@@ -103,6 +103,18 @@ endmacro()
# For each specified flag, add that compile flag to the provided target.
# The flags are added with the given visibility, i.e. PUBLIC|PRIVATE|INTERFACE.
function(target_add_compile_flags_if_supported target visibility)
+
+ # Disable linker for CMake flag compatibility checks
+ #
+ # Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
+ # disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
+ # for static targets; cache the target type here, and reset it after the various
+ # checks have been performed.
+ set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+ set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+ set(CMAKE_REQUIRED_LINK_OPTIONS)
+
foreach(flag ${ARGN})
mangle_name("${flag}" flagname)
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
@@ -110,4 +122,8 @@ function(target_add_compile_flags_if_supported target visibility)
target_compile_options(${target} ${visibility} ${flag})
endif()
endforeach()
+
+ # reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+ set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
endfunction()
>From 11cbf4fc38b107cd316d7d7a085d1cc4f44a71fa Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Thu, 27 Jun 2024 16:07:59 +1100
Subject: [PATCH 08/15] [cmake] also do static-vs-linker work-around in
libcxx/cmake/config-ix.cmake
---
libcxx/cmake/config-ix.cmake | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index 7406fba482e69d..250d636d8d8042 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -6,6 +6,17 @@ include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckCSourceCompiles)
+# Disable linker for CMake flag compatibility checks
+#
+# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
+# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
+# for static targets; cache the target type here, and reset it after the various
+# checks have been performed.
+set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+set(CMAKE_REQUIRED_LINK_OPTIONS)
+
# The compiler driver may be implicitly trying to link against libunwind.
# This is normally ok (libcxx relies on an unwinder), but if libunwind is
# built in the same cmake invocation as libcxx and we've got
@@ -98,6 +109,10 @@ int main(void) { return 0; }
cmake_pop_check_state()
endif()
+# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
+set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
+
check_symbol_exists(__PICOLIBC__ "string.h" PICOLIBC)
# Check libraries
>From 6ade702ab7af4c829995ce3427b201c00336f48d Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Thu, 27 Jun 2024 18:28:01 +1100
Subject: [PATCH 09/15] [cmake] also do static-vs-linker work-around for
add_flag_if_supported
---
llvm/cmake/modules/HandleLLVMOptions.cmake | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ca580fbb59c59..5e12da351a65ea 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -333,10 +333,26 @@ function(append_if condition value)
endfunction()
macro(add_flag_if_supported flag name)
+
+ # Disable linker for CMake flag compatibility checks
+ #
+ # Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
+ # disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
+ # for static targets; cache the target type here, and reset it after the various
+ # checks have been performed.
+ set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+ set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+ set(CMAKE_REQUIRED_LINK_OPTIONS)
+
check_c_compiler_flag("-Werror ${flag}" "C_SUPPORTS_${name}")
append_if("C_SUPPORTS_${name}" "${flag}" CMAKE_C_FLAGS)
check_cxx_compiler_flag("-Werror ${flag}" "CXX_SUPPORTS_${name}")
append_if("CXX_SUPPORTS_${name}" "${flag}" CMAKE_CXX_FLAGS)
+
+ # reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+ set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
endmacro()
function(add_flag_or_print_warning flag name)
>From fcd96714d59e8fb56c6d6059f70ed2c9ca06d0f4 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Thu, 27 Jun 2024 18:28:23 +1100
Subject: [PATCH 10/15] [cmake] also do static-vs-linker work-around in
runtimes/CMakeLists.txt
---
runtimes/CMakeLists.txt | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 8f909322c9a98c..687661b67c34c4 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -104,6 +104,17 @@ filter_prefixed("${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}" ${LLVM_BINARY_DIR} CMA
filter_prefixed("${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}" ${LLVM_BINARY_DIR} CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES)
filter_prefixed("${CMAKE_ASM_IMPLICIT_INCLUDE_DIRECTORIES}" ${LLVM_BINARY_DIR} CMAKE_ASM_IMPLICIT_INCLUDE_DIRECTORIES)
+# Disable linker for CMake flag compatibility checks
+#
+# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
+# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
+# for static targets; cache the target type here, and reset it after the various
+# checks have been performed.
+set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+set(CMAKE_REQUIRED_LINK_OPTIONS)
+
# The compiler driver may be implicitly trying to link against libunwind,
# which might not work if libunwind doesn't exist yet. Try to check if
# --unwindlib=none is supported, and use that if possible.
@@ -132,6 +143,10 @@ if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++")
endif()
+# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
+set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
+
# Avoid checking whether the compiler is working.
set(LLVM_COMPILER_CHECKED ON)
>From f34093ab9593b113e863443a6041a08c4e5738b5 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Thu, 27 Jun 2024 18:31:39 +1100
Subject: [PATCH 11/15] [cmake] also do static-vs-linker work-around for
libcxx{,abi}'s add_flags_if_supported
---
libcxx/cmake/Modules/HandleLibcxxFlags.cmake | 16 ++++++++++++++++
.../cmake/Modules/HandleLibcxxabiFlags.cmake | 16 ++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/libcxx/cmake/Modules/HandleLibcxxFlags.cmake b/libcxx/cmake/Modules/HandleLibcxxFlags.cmake
index ffd859e4b1f222..32ded5d17cef87 100644
--- a/libcxx/cmake/Modules/HandleLibcxxFlags.cmake
+++ b/libcxx/cmake/Modules/HandleLibcxxFlags.cmake
@@ -29,11 +29,27 @@ endmacro()
# Add each flag in the list to LIBCXX_COMPILE_FLAGS and LIBCXX_LINK_FLAGS
# if that flag is supported by the current compiler.
macro(add_flags_if_supported)
+
+ # Disable linker for CMake flag compatibility checks
+ #
+ # Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
+ # disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
+ # for static targets; cache the target type here, and reset it after the various
+ # checks have been performed.
+ set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+ set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+ set(CMAKE_REQUIRED_LINK_OPTIONS)
+
foreach(flag ${ARGN})
mangle_name("${flag}" flagname)
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
add_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag})
endforeach()
+
+ # reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+ set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
endmacro()
# Add a list of flags to 'LIBCXX_LINK_FLAGS'.
diff --git a/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake b/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake
index 16aed0242a6df0..40184d7f503e97 100644
--- a/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake
+++ b/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake
@@ -29,11 +29,27 @@ endmacro()
# Add each flag in the list to LIBCXXABI_COMPILE_FLAGS and LIBCXXABI_LINK_FLAGS
# if that flag is supported by the current compiler.
macro(add_flags_if_supported)
+
+ # Disable linker for CMake flag compatibility checks
+ #
+ # Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
+ # disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
+ # for static targets; cache the target type here, and reset it after the various
+ # checks have been performed.
+ set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+ set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+ set(CMAKE_REQUIRED_LINK_OPTIONS)
+
foreach(flag ${ARGN})
mangle_name("${flag}" flagname)
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
add_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag})
endforeach()
+
+ # reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+ set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
endmacro()
# Add a list of flags to 'LIBCXXABI_COMPILE_FLAGS'.
>From 37bb8e153bf7ec517d18d3d94313b3666c254680 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Fri, 28 Jun 2024 09:02:59 +1100
Subject: [PATCH 12/15] [cmake] also do static-vs-linker work-around in
libcxxabi/cmake/config-ix.cmake
---
libcxxabi/cmake/config-ix.cmake | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/libcxxabi/cmake/config-ix.cmake b/libcxxabi/cmake/config-ix.cmake
index 10f2087c68c5e7..9ce8744c3af86f 100644
--- a/libcxxabi/cmake/config-ix.cmake
+++ b/libcxxabi/cmake/config-ix.cmake
@@ -14,6 +14,17 @@ if (NOT LIBCXXABI_USE_COMPILER_RT)
endif ()
endif ()
+# Disable linker for CMake flag compatibility checks
+#
+# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
+# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
+# for static targets; cache the target type here, and reset it after the various
+# checks have been performed.
+set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+set(CMAKE_REQUIRED_LINK_OPTIONS)
+
# libc++abi is using -nostdlib++ at the link step when available,
# otherwise -nodefaultlibs is used. We want all our checks to also
# use one of these options, otherwise we may end up with an inconsistency between
@@ -94,6 +105,10 @@ endif()
# Check compiler flags
check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG)
+# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
+set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
+
# Check libraries
if(FUCHSIA)
set(LIBCXXABI_HAS_DL_LIB NO)
>From 74b9d3f3ed6306863a1e298a98c9f990eee0aee3 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Fri, 28 Jun 2024 09:10:02 +1100
Subject: [PATCH 13/15] [cmake] also do static-vs-linker work-around in
libunwind/cmake/config-ix.cmake
---
libunwind/cmake/config-ix.cmake | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake
index 126c872f0d4895..b44e41edbf1a6d 100644
--- a/libunwind/cmake/config-ix.cmake
+++ b/libunwind/cmake/config-ix.cmake
@@ -6,6 +6,17 @@ include(LLVMCheckCompilerLinkerFlag)
include(CheckSymbolExists)
include(CheckCSourceCompiles)
+# Disable linker for CMake flag compatibility checks
+#
+# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
+# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
+# for static targets; cache the target type here, and reset it after the various
+# checks have been performed.
+set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+set(CMAKE_REQUIRED_LINK_OPTIONS)
+
# The compiler driver may be implicitly trying to link against libunwind, which
# might not work if libunwind doesn't exist yet. Try to check if
# --unwindlib=none is supported, and use that if possible.
@@ -105,6 +116,10 @@ endif()
# Check compiler flags
check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG)
+# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
+set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
+
# Check symbols
check_symbol_exists(__arm__ "" LIBUNWIND_TARGET_ARM)
check_symbol_exists(__USING_SJLJ_EXCEPTIONS__ "" LIBUNWIND_USES_SJLJ_EXCEPTIONS)
>From 8c2fda5fe3808a84a841e279629d9aaad93559ca Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Fri, 28 Jun 2024 09:18:23 +1100
Subject: [PATCH 14/15] [cmake] fix up order of work-around with definition of
CMAKE_REQUIRED_LINK_OPTIONS
---
runtimes/CMakeLists.txt | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 687661b67c34c4..f696e7dfa7c518 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -104,17 +104,6 @@ filter_prefixed("${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}" ${LLVM_BINARY_DIR} CMA
filter_prefixed("${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}" ${LLVM_BINARY_DIR} CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES)
filter_prefixed("${CMAKE_ASM_IMPLICIT_INCLUDE_DIRECTORIES}" ${LLVM_BINARY_DIR} CMAKE_ASM_IMPLICIT_INCLUDE_DIRECTORIES)
-# Disable linker for CMake flag compatibility checks
-#
-# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
-# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
-# for static targets; cache the target type here, and reset it after the various
-# checks have been performed.
-set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
-set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-set(CMAKE_REQUIRED_LINK_OPTIONS)
-
# The compiler driver may be implicitly trying to link against libunwind,
# which might not work if libunwind doesn't exist yet. Try to check if
# --unwindlib=none is supported, and use that if possible.
@@ -130,6 +119,17 @@ if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
list(APPEND CMAKE_REQUIRED_LINK_OPTIONS "--unwindlib=none")
endif()
+# Disable linker for CMake flag compatibility checks
+#
+# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
+# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
+# for static targets; cache the target type here, and reset it after the various
+# checks have been performed.
+set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+set(CMAKE_REQUIRED_LINK_OPTIONS)
+
# Disable use of the installed C++ standard library when building runtimes.
# Check for -nostdlib++ first; if there's no C++ standard library yet,
# all check_cxx_compiler_flag commands will fail until we add -nostdlib++
>From 957686949177ccad9f6a0ce583067dd4daf2621d Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari at gmx.com>
Date: Mon, 12 Aug 2024 16:37:34 +1100
Subject: [PATCH 15/15] avoid resetting context for CMake flag checks manually
instead, teach existing llvm_check_compiler_linker_flag to do it
---
.../Modules/LLVMCheckCompilerLinkerFlag.cmake | 28 ++++++++++++++--
compiler-rt/cmake/config-ix.cmake | 18 ++++++-----
libcxx/cmake/Modules/HandleLibcxxFlags.cmake | 20 ++----------
libcxx/cmake/config-ix.cmake | 32 +++++++------------
.../cmake/Modules/HandleLibcxxabiFlags.cmake | 20 ++----------
libcxxabi/cmake/config-ix.cmake | 25 ++++-----------
libunwind/CMakeLists.txt | 21 ------------
.../cmake/Modules/HandleLibunwindFlags.cmake | 4 ++-
libunwind/cmake/config-ix.cmake | 24 ++++----------
llvm/cmake/modules/HandleLLVMOptions.cmake | 23 +++----------
offload/CMakeLists.txt | 4 ++-
openmp/runtime/cmake/config-ix.cmake | 18 ++++++-----
runtimes/CMakeLists.txt | 21 ++----------
runtimes/cmake/Modules/HandleFlags.cmake | 21 ++----------
runtimes/cmake/Modules/WarningFlags.cmake | 16 ----------
15 files changed, 93 insertions(+), 202 deletions(-)
diff --git a/cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake b/cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake
index 2524aafff05746..bf542a8abf48ec 100644
--- a/cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake
+++ b/cmake/Modules/LLVMCheckCompilerLinkerFlag.cmake
@@ -1,7 +1,7 @@
include(CMakePushCheckState)
include(CheckCompilerFlag)
-function(llvm_check_compiler_linker_flag lang flag out_var)
+function(llvm_check_compiler_linker_flag lang reset target_type flag out_var)
# If testing a flag with check_compiler_flag, it gets added to the compile
# command only, but not to the linker command in that test. If the flag
# is vital for linking to succeed, the test would fail even if it would
@@ -10,8 +10,32 @@ function(llvm_check_compiler_linker_flag lang flag out_var)
# Therefore, try adding the flag to CMAKE_REQUIRED_FLAGS, which gets
# added to both compiling and linking commands in the tests.
- cmake_push_check_state()
+ # In some cases, we need to disable existing linker options completely;
+ # e.g. due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, in the
+ # context of CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG, for example. To this end,
+ # we the RESET option of cmake_push_check_state, c.f.
+ # https://cmake.org/cmake/help/latest/module/CMakePushCheckState.html
+ #
+ # Due to the same CMake issue, we need to be able to override the targe type,
+ # as some checks will fail by default for shared libraries. A concrete example
+ # is checking for `-funwind-tables` when building libunwind (e.g. for ARM EHABI).
+ #
+ # This happens because, when performing CMake checks, adding `-funwind-tables`
+ # for a dynamic target causes the check to produce a false negative, because the
+ # compiler compiler generates calls to `__aeabi_unwind_cpp_pr0`, which is defined
+ # in libunwind itself, which isn't built yet, so the linker complains about
+ # undefined symbols. This would lead to libunwind not being built with this flag,
+ # which makes libunwind quite useless in this setup.
+ cmake_push_check_state(${reset})
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}")
+ if (NOT target_type STREQUAL "")
+ set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+ endif()
+ # run the actual check
check_compiler_flag("${lang}" "" ${out_var})
+ if (NOT target_type STREQUAL "")
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
+ endif()
cmake_pop_check_state()
endfunction()
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 97204177cde9a4..796de031096452 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -4,8 +4,8 @@ include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckIncludeFiles)
include(CheckLibraryExists)
-include(LLVMCheckCompilerLinkerFlag)
include(CheckSymbolExists)
+include(LLVMCheckCompilerLinkerFlag)
include(TestBigEndian)
# The compiler driver may be implicitly trying to link against libunwind.
@@ -15,7 +15,7 @@ include(TestBigEndian)
# libunwind (and the compiler implicit -lunwind wouldn't succeed as the newly
# built libunwind isn't installed yet). For those cases, it'd be good to
# link with --unwindlib=none. Check if that option works.
-llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_NONE_FLAG)
+llvm_check_compiler_linker_flag(C "--unwindlib=none" "" "" CXX_SUPPORTS_UNWINDLIB_NONE_FLAG)
check_library_exists(c fopen "" COMPILER_RT_HAS_LIBC)
if (COMPILER_RT_USE_BUILTINS_LIBRARY)
@@ -190,12 +190,13 @@ check_library_exists(c++ __cxa_throw "" COMPILER_RT_HAS_LIBCXX)
check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX)
# Linker flags.
-llvm_check_compiler_linker_flag(C "-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT)
-llvm_check_compiler_linker_flag(C "-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG)
+llvm_check_compiler_linker_flag(C "-Wl,-z,text" "" "" COMPILER_RT_HAS_Z_TEXT)
+llvm_check_compiler_linker_flag(C "-fuse-ld=lld" "" "" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG)
if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
set(VERS_COMPAT_OPTION "-Wl,-z,gnu-version-script-compat")
- llvm_check_compiler_linker_flag(C "${VERS_COMPAT_OPTION}" COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
+ llvm_check_compiler_linker_flag(
+ C "${VERS_COMPAT_OPTION}" "" "" COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
endif()
set(DUMMY_VERS ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/dummy.vers)
@@ -206,10 +207,10 @@ if(COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
# -z gnu-version-script-compat.
string(APPEND VERS_OPTION " ${VERS_COMPAT_OPTION}")
endif()
-llvm_check_compiler_linker_flag(C "${VERS_OPTION}" COMPILER_RT_HAS_VERSION_SCRIPT)
+llvm_check_compiler_linker_flag(C "${VERS_OPTION}" "" "" COMPILER_RT_HAS_VERSION_SCRIPT)
if(ANDROID)
- llvm_check_compiler_linker_flag(C "-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL)
+ llvm_check_compiler_linker_flag(C "-Wl,-z,global" "" "" COMPILER_RT_HAS_Z_GLOBAL)
check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG)
endif()
@@ -494,7 +495,8 @@ if(APPLE)
-lc++
-lc++abi)
- llvm_check_compiler_linker_flag(C "-fapplication-extension" COMPILER_RT_HAS_APP_EXTENSION)
+ llvm_check_compiler_linker_flag(
+ C "-fapplication-extension" "" "" COMPILER_RT_HAS_APP_EXTENSION)
if(COMPILER_RT_HAS_APP_EXTENSION)
list(APPEND DARWIN_COMMON_LINK_FLAGS "-fapplication-extension")
endif()
diff --git a/libcxx/cmake/Modules/HandleLibcxxFlags.cmake b/libcxx/cmake/Modules/HandleLibcxxFlags.cmake
index 32ded5d17cef87..4419fa2266ab3f 100644
--- a/libcxx/cmake/Modules/HandleLibcxxFlags.cmake
+++ b/libcxx/cmake/Modules/HandleLibcxxFlags.cmake
@@ -6,6 +6,7 @@
include(CheckCXXCompilerFlag)
include(HandleFlags)
+include(LLVMCheckCompilerLinkerFlag)
unset(add_flag_if_supported)
@@ -29,27 +30,12 @@ endmacro()
# Add each flag in the list to LIBCXX_COMPILE_FLAGS and LIBCXX_LINK_FLAGS
# if that flag is supported by the current compiler.
macro(add_flags_if_supported)
-
- # Disable linker for CMake flag compatibility checks
- #
- # Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
- # disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
- # for static targets; cache the target type here, and reset it after the various
- # checks have been performed.
- set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
- set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
- set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
- set(CMAKE_REQUIRED_LINK_OPTIONS)
-
foreach(flag ${ARGN})
mangle_name("${flag}" flagname)
- check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
+ llvm_check_compiler_linker_flag(
+ CXX "${flag}" RESET STATIC_LIBRARY "CXX_SUPPORTS_${flagname}_FLAG")
add_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag})
endforeach()
-
- # reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
- set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
- set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
endmacro()
# Add a list of flags to 'LIBCXX_LINK_FLAGS'.
diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index cd4750b65fdafd..e9cca1469d1352 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -1,21 +1,10 @@
include(CMakePushCheckState)
include(CheckLibraryExists)
include(CheckSymbolExists)
-include(LLVMCheckCompilerLinkerFlag)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckCSourceCompiles)
-
-# Disable linker for CMake flag compatibility checks
-#
-# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
-# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
-# for static targets; cache the target type here, and reset it after the various
-# checks have been performed.
-set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
-set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-set(CMAKE_REQUIRED_LINK_OPTIONS)
+include(LLVMCheckCompilerLinkerFlag)
# The compiler driver may be implicitly trying to link against libunwind.
# This is normally ok (libcxx relies on an unwinder), but if libunwind is
@@ -24,7 +13,8 @@ set(CMAKE_REQUIRED_LINK_OPTIONS)
# libunwind (and the compiler implicit -lunwind wouldn't succeed as the newly
# built libunwind isn't installed yet). For those cases, it'd be good to
# link with --unwindlib=none. Check if that option works.
-llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
+llvm_check_compiler_linker_flag(
+ C "--unwindlib=none" RESET STATIC_LIBRARY CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
if (NOT LIBCXX_USE_COMPILER_RT)
if(WIN32 AND NOT MINGW)
@@ -38,8 +28,10 @@ if (NOT LIBCXX_USE_COMPILER_RT)
endif()
endif()
-check_cxx_compiler_flag(-nostdlibinc CXX_SUPPORTS_NOSTDLIBINC_FLAG)
-check_cxx_compiler_flag(-nolibc CXX_SUPPORTS_NOLIBC_FLAG)
+llvm_check_compiler_linker_flag(
+ CXX "-nostdlibinc" RESET STATIC_LIBRARY CXX_SUPPORTS_NOSTDLIBINC_FLAG)
+llvm_check_compiler_linker_flag(
+ CXX "-nolibc" RESET STATIC_LIBRARY CXX_SUPPORTS_NOLIBC_FLAG)
# libc++ is using -nostdlib++ at the link step when available,
# otherwise -nodefaultlibs is used. We want all our checks to also
@@ -50,11 +42,13 @@ check_cxx_compiler_flag(-nolibc CXX_SUPPORTS_NOLIBC_FLAG)
# required for the link to go through. We remove sanitizers from the
# configuration checks to avoid spurious link errors.
-check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+llvm_check_compiler_linker_flag(
+ CXX "-nostdlib++" RESET STATIC_LIBRARY CXX_SUPPORTS_NOSTDLIBXX_FLAG)
if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
else()
- check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
+ llvm_check_compiler_linker_flag(
+ C "-nodefaultlibs" RESET STATIC_LIBRARY C_SUPPORTS_NODEFAULTLIBS_FLAG)
if (C_SUPPORTS_NODEFAULTLIBS_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
endif()
@@ -112,10 +106,6 @@ int main(void) { return 0; }
cmake_pop_check_state()
endif()
-# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
-set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
-
check_symbol_exists(__PICOLIBC__ "string.h" PICOLIBC)
# Check libraries
diff --git a/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake b/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake
index 40184d7f503e97..97e4207ca1dab2 100644
--- a/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake
+++ b/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake
@@ -6,6 +6,7 @@
include(CheckCXXCompilerFlag)
include(HandleFlags)
+include(LLVMCheckCompilerLinkerFlag)
unset(add_flag_if_supported)
@@ -29,27 +30,12 @@ endmacro()
# Add each flag in the list to LIBCXXABI_COMPILE_FLAGS and LIBCXXABI_LINK_FLAGS
# if that flag is supported by the current compiler.
macro(add_flags_if_supported)
-
- # Disable linker for CMake flag compatibility checks
- #
- # Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
- # disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
- # for static targets; cache the target type here, and reset it after the various
- # checks have been performed.
- set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
- set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
- set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
- set(CMAKE_REQUIRED_LINK_OPTIONS)
-
foreach(flag ${ARGN})
mangle_name("${flag}" flagname)
- check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
+ llvm_check_compiler_linker_flag(
+ CXX "${flag}" RESET STATIC_LIBRARY "CXX_SUPPORTS_${flagname}_FLAG")
add_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag})
endforeach()
-
- # reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
- set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
- set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
endmacro()
# Add a list of flags to 'LIBCXXABI_COMPILE_FLAGS'.
diff --git a/libcxxabi/cmake/config-ix.cmake b/libcxxabi/cmake/config-ix.cmake
index 9ce8744c3af86f..ef3a6b6c77ee43 100644
--- a/libcxxabi/cmake/config-ix.cmake
+++ b/libcxxabi/cmake/config-ix.cmake
@@ -3,6 +3,7 @@ include(CheckLibraryExists)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckCSourceCompiles)
+include(LLVMCheckCompilerLinkerFlag)
check_library_exists(c fopen "" LIBCXXABI_HAS_C_LIB)
if (NOT LIBCXXABI_USE_COMPILER_RT)
@@ -14,17 +15,6 @@ if (NOT LIBCXXABI_USE_COMPILER_RT)
endif ()
endif ()
-# Disable linker for CMake flag compatibility checks
-#
-# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
-# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
-# for static targets; cache the target type here, and reset it after the various
-# checks have been performed.
-set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
-set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-set(CMAKE_REQUIRED_LINK_OPTIONS)
-
# libc++abi is using -nostdlib++ at the link step when available,
# otherwise -nodefaultlibs is used. We want all our checks to also
# use one of these options, otherwise we may end up with an inconsistency between
@@ -34,11 +24,13 @@ set(CMAKE_REQUIRED_LINK_OPTIONS)
# required for the link to go through. We remove sanitizers from the
# configuration checks to avoid spurious link errors.
-check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+llvm_check_compiler_linker_flag(
+ CXX "-nostdlib++" RESET STATIC_LIBRARY CXX_SUPPORTS_NOSTDLIBXX_FLAG)
if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
else()
- check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
+ llvm_check_compiler_linker_flag(
+ C "-nodefaultlibs" RESET STATIC_LIBRARY C_SUPPORTS_NODEFAULTLIBS_FLAG)
if (C_SUPPORTS_NODEFAULTLIBS_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
endif()
@@ -103,11 +95,8 @@ int main(void) { return 0; }
endif()
# Check compiler flags
-check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG)
-
-# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
-set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
+llvm_check_compiler_linker_flag(
+ CXX "-nostdinc++" RESET STATIC_LIBRARY CXX_SUPPORTS_NOSTDINCXX_FLAG)
# Check libraries
if(FUCHSIA)
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 86d7a81ab422ed..68efb4107fbca1 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -176,23 +176,6 @@ if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt")
endif()
-# Disable linker for running CMake checks
-#
-# This was originally added because when building libunwind for ARM Linux,
-# we need to pass the -funwind-tables flag in order for it to work properly
-# with ARM EHABI. However, this produces a false negative when performing CMake
-# checks, causing libunwind to not be built with this flag.
-#
-# A similar dynamic occurred with the advent of CMAKE_REQUIRED_LINK_OPTIONS
-# (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG), which causes flag checks for static
-# targets to fail due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454.
-# Thus, to avoid failures with static targets, we cache the target type here,
-# and reset it after the various flag support checks have been performed.
-set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
-set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-set(CMAKE_REQUIRED_LINK_OPTIONS)
-
add_compile_flags_if_supported(-Werror=return-type)
if (LIBUNWIND_ENABLE_CET)
@@ -242,10 +225,6 @@ endif()
add_cxx_compile_flags_if_supported(-fno-exceptions)
add_cxx_compile_flags_if_supported(-fno-rtti)
-# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
-set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
-
# Ensure that we don't depend on C++ standard library.
if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++)
diff --git a/libunwind/cmake/Modules/HandleLibunwindFlags.cmake b/libunwind/cmake/Modules/HandleLibunwindFlags.cmake
index 94c676338821c7..835d07965515cd 100644
--- a/libunwind/cmake/Modules/HandleLibunwindFlags.cmake
+++ b/libunwind/cmake/Modules/HandleLibunwindFlags.cmake
@@ -7,6 +7,7 @@
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(HandleFlags)
+include(LLVMCheckCompilerLinkerFlag)
unset(add_flag_if_supported)
@@ -30,7 +31,8 @@ endmacro()
macro(add_compile_flags_if_supported)
foreach(flag ${ARGN})
mangle_name("${flag}" flagname)
- check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
+ llvm_check_compiler_linker_flag(
+ CXX "${flag}" RESET STATIC_LIBRARY "CXX_SUPPORTS_${flagname}_FLAG")
add_compile_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag})
endforeach()
endmacro()
diff --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake
index b44e41edbf1a6d..0613e805ff704d 100644
--- a/libunwind/cmake/config-ix.cmake
+++ b/libunwind/cmake/config-ix.cmake
@@ -6,21 +6,11 @@ include(LLVMCheckCompilerLinkerFlag)
include(CheckSymbolExists)
include(CheckCSourceCompiles)
-# Disable linker for CMake flag compatibility checks
-#
-# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
-# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
-# for static targets; cache the target type here, and reset it after the various
-# checks have been performed.
-set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
-set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-set(CMAKE_REQUIRED_LINK_OPTIONS)
-
# The compiler driver may be implicitly trying to link against libunwind, which
# might not work if libunwind doesn't exist yet. Try to check if
# --unwindlib=none is supported, and use that if possible.
-llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
+llvm_check_compiler_linker_flag(
+ C "--unwindlib=none" RESET STATIC_LIBRARY CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
if (HAIKU)
check_library_exists(root fopen "" LIBUNWIND_HAS_ROOT_LIB)
@@ -46,11 +36,13 @@ endif()
# required for the link to go through. We remove sanitizers from the
# configuration checks to avoid spurious link errors.
-llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+llvm_check_compiler_linker_flag(
+ CXX "-nostdlib++" RESET STATIC_LIBRARY CXX_SUPPORTS_NOSTDLIBXX_FLAG)
if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
else()
- llvm_check_compiler_linker_flag(C "-nodefaultlibs" C_SUPPORTS_NODEFAULTLIBS_FLAG)
+ llvm_check_compiler_linker_flag(
+ C "-nodefaultlibs" RESET STATIC_LIBRARY C_SUPPORTS_NODEFAULTLIBS_FLAG)
if (C_SUPPORTS_NODEFAULTLIBS_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
endif()
@@ -116,10 +108,6 @@ endif()
# Check compiler flags
check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG)
-# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
-set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
-
# Check symbols
check_symbol_exists(__arm__ "" LIBUNWIND_TARGET_ARM)
check_symbol_exists(__USING_SJLJ_EXCEPTIONS__ "" LIBUNWIND_USES_SJLJ_EXCEPTIONS)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 6a947e36c00d38..3105464784b4fc 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -15,6 +15,7 @@ include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
include(CheckSymbolExists)
include(CMakeDependentOption)
+include(LLVMCheckCompilerLinkerFlag)
include(LLVMProcessSources)
if(CMAKE_LINKER MATCHES ".*lld" OR (LLVM_USE_LINKER STREQUAL "lld" OR LLVM_ENABLE_LLD))
@@ -333,26 +334,12 @@ function(append_if condition value)
endfunction()
macro(add_flag_if_supported flag name)
-
- # Disable linker for CMake flag compatibility checks
- #
- # Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
- # disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
- # for static targets; cache the target type here, and reset it after the various
- # checks have been performed.
- set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
- set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
- set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
- set(CMAKE_REQUIRED_LINK_OPTIONS)
-
- check_c_compiler_flag("-Werror ${flag}" "C_SUPPORTS_${name}")
+ llvm_check_compiler_linker_flag(
+ C "-Werror ${flag}" RESET STATIC_LIBRARY "C_SUPPORTS_${name}")
append_if("C_SUPPORTS_${name}" "${flag}" CMAKE_C_FLAGS)
- check_cxx_compiler_flag("-Werror ${flag}" "CXX_SUPPORTS_${name}")
+ llvm_check_compiler_linker_flag(
+ CXX "-Werror ${flag}" RESET STATIC_LIBRARY "CXX_SUPPORTS_${name}")
append_if("CXX_SUPPORTS_${name}" "${flag}" CMAKE_CXX_FLAGS)
-
- # reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
- set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
- set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
endmacro()
function(add_flag_or_print_warning flag name)
diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt
index 4cd97a6a5ff63d..e74d69710db1b4 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -296,7 +296,9 @@ if(OPENMP_STANDALONE_BUILD OR TARGET omp)
# Check LIBOMP_HAVE_VERSION_SCRIPT_FLAG
include(LLVMCheckCompilerLinkerFlag)
if(NOT APPLE)
- llvm_check_compiler_linker_flag(C "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/../openmp/runtime/src/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
+ llvm_check_compiler_linker_flag(C
+ "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/../openmp/runtime/src/exports_test_so.txt"
+ "" "" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
endif()
endif()
diff --git a/openmp/runtime/cmake/config-ix.cmake b/openmp/runtime/cmake/config-ix.cmake
index 0568474f1d74ed..78f649e354d7de 100644
--- a/openmp/runtime/cmake/config-ix.cmake
+++ b/openmp/runtime/cmake/config-ix.cmake
@@ -128,13 +128,15 @@ check_symbol_exists(_aligned_malloc "malloc.h" LIBOMP_HAVE__ALIGNED_MALLOC)
# Check linker flags
if(WIN32)
- llvm_check_compiler_linker_flag(C /SAFESEH LIBOMP_HAVE_SAFESEH_FLAG)
+ llvm_check_compiler_linker_flag(C "/SAFESEH" "" "" LIBOMP_HAVE_SAFESEH_FLAG)
elseif(NOT APPLE)
- llvm_check_compiler_linker_flag(C -Wl,-x LIBOMP_HAVE_X_FLAG)
- llvm_check_compiler_linker_flag(C -Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG)
- llvm_check_compiler_linker_flag(C "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
- llvm_check_compiler_linker_flag(C -static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG)
- llvm_check_compiler_linker_flag(C -Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG)
+ llvm_check_compiler_linker_flag(C "-Wl,-x" "" "" LIBOMP_HAVE_X_FLAG)
+ llvm_check_compiler_linker_flag(C "-Wl,--as-needed" "" "" LIBOMP_HAVE_AS_NEEDED_FLAG)
+ llvm_check_compiler_linker_flag(C
+ "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_test_so.txt"
+ "" "" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
+ llvm_check_compiler_linker_flag(C "-static-libgcc" "" "" LIBOMP_HAVE_STATIC_LIBGCC_FLAG)
+ llvm_check_compiler_linker_flag(C "-Wl,-z,noexecstack" "" "" LIBOMP_HAVE_Z_NOEXECSTACK_FLAG)
endif()
# Check Intel(R) C Compiler specific flags
@@ -145,8 +147,8 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Intel" OR CMAKE_C_COMPILER_ID STREQUAL "IntelLL
check_cxx_compiler_flag(-Qoption,cpp,--extended_float_types LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG)
check_cxx_compiler_flag(-falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG)
check_cxx_compiler_flag("-opt-streaming-stores never" LIBOMP_HAVE_OPT_STREAMING_STORES_FLAG)
- llvm_check_compiler_linker_flag(C -static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG)
- llvm_check_compiler_linker_flag(C -no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG)
+ llvm_check_compiler_linker_flag(C "-static-intel" "" "" LIBOMP_HAVE_STATIC_INTEL_FLAG)
+ llvm_check_compiler_linker_flag(C "-no-intel-extensions" "" "" LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG)
check_library_exists(irc_pic _intel_fast_memcpy "" LIBOMP_HAVE_IRC_PIC_LIBRARY)
endif()
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index f2b4a34cfaa000..9c46690b4a6924 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -114,39 +114,24 @@ filter_prefixed("${CMAKE_ASM_IMPLICIT_INCLUDE_DIRECTORIES}" ${LLVM_BINARY_DIR} C
# Currently, we counteract this issue by adding -fno-sanitize=all flag in
# the project specific code within */cmake/config-ix.cmake files but that's
# brittle. We should ideally move this to runtimes/CMakeLists.txt.
-llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
+llvm_check_compiler_linker_flag(C "--unwindlib=none" "" "" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
list(APPEND CMAKE_REQUIRED_LINK_OPTIONS "--unwindlib=none")
endif()
-# Disable linker for CMake flag compatibility checks
-#
-# Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
-# disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
-# for static targets; cache the target type here, and reset it after the various
-# checks have been performed.
-set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
-set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-set(CMAKE_REQUIRED_LINK_OPTIONS)
-
# Disable use of the installed C++ standard library when building runtimes.
# Check for -nostdlib++ first; if there's no C++ standard library yet,
# all check_cxx_compiler_flag commands will fail until we add -nostdlib++
# (or -nodefaultlibs).
-llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+llvm_check_compiler_linker_flag(CXX "-nostdlib++" RESET STATIC_LIBRARY CXX_SUPPORTS_NOSTDLIBXX_FLAG)
if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
endif()
-check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG)
+llvm_check_compiler_linker_flag(CXX "-nostdinc++" RESET STATIC_LIBRARY CXX_SUPPORTS_NOSTDINCXX_FLAG)
if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++")
endif()
-# reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
-set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
-set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
-
# Avoid checking whether the compiler is working.
set(LLVM_COMPILER_CHECKED ON)
diff --git a/runtimes/cmake/Modules/HandleFlags.cmake b/runtimes/cmake/Modules/HandleFlags.cmake
index 6bb3d92043b462..26463a714b1531 100644
--- a/runtimes/cmake/Modules/HandleFlags.cmake
+++ b/runtimes/cmake/Modules/HandleFlags.cmake
@@ -1,5 +1,5 @@
-
include(CheckCXXCompilerFlag)
+include(LLVMCheckCompilerLinkerFlag)
unset(add_flag_if_supported)
@@ -103,27 +103,12 @@ endmacro()
# For each specified flag, add that compile flag to the provided target.
# The flags are added with the given visibility, i.e. PUBLIC|PRIVATE|INTERFACE.
function(target_add_compile_flags_if_supported target visibility)
-
- # Disable linker for CMake flag compatibility checks
- #
- # Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
- # disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
- # for static targets; cache the target type here, and reset it after the various
- # checks have been performed.
- set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
- set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
- set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
- set(CMAKE_REQUIRED_LINK_OPTIONS)
-
foreach(flag ${ARGN})
mangle_name("${flag}" flagname)
- check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
+ llvm_check_compiler_linker_flag(
+ CXX "${flag}" RESET STATIC_LIBRARY "CXX_SUPPORTS_${flagname}_FLAG")
if (CXX_SUPPORTS_${flagname}_FLAG)
target_compile_options(${target} ${visibility} ${flag})
endif()
endforeach()
-
- # reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
- set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
- set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
endfunction()
diff --git a/runtimes/cmake/Modules/WarningFlags.cmake b/runtimes/cmake/Modules/WarningFlags.cmake
index c496653025ecf0..068d22150d3875 100644
--- a/runtimes/cmake/Modules/WarningFlags.cmake
+++ b/runtimes/cmake/Modules/WarningFlags.cmake
@@ -3,18 +3,6 @@ include(HandleFlags)
# Warning flags ===============================================================
function(cxx_add_warning_flags target enable_werror enable_pedantic)
target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-
- # Disable linker for CMake flag compatibility checks
- #
- # Due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454, we need to
- # disable CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG),
- # for static targets; cache the target type here, and reset it after the various
- # checks have been performed.
- set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
- set(_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
- set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
- set(CMAKE_REQUIRED_LINK_OPTIONS)
-
if (MSVC)
# -W4 is the cl.exe/clang-cl equivalent of -Wall. (In cl.exe and clang-cl,
# -Wall is equivalent to -Weverything in GCC style compiler drivers.)
@@ -92,8 +80,4 @@ function(cxx_add_warning_flags target enable_werror enable_pedantic)
if (${enable_pedantic})
target_add_compile_flags_if_supported(${target} PRIVATE -pedantic)
endif()
-
- # reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
- set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE})
- set(CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS})
endfunction()
More information about the Openmp-commits
mailing list