summaryrefslogtreecommitdiff
path: root/libcxxabi/cmake
diff options
context:
space:
mode:
authorLouis Dionne <ldionne.2@gmail.com>2021-07-15 13:02:43 -0400
committerLouis Dionne <ldionne.2@gmail.com>2021-07-15 16:52:02 -0400
commita59165b01778a3b02c510a96951d115d39babd86 (patch)
tree9f348f1b619dbd15ce3bd8cd77b41aecd8eaf68a /libcxxabi/cmake
parent6596778b46ba69517191e7397289228168064ff4 (diff)
downloadllvm-a59165b01778a3b02c510a96951d115d39babd86.tar.gz
[runtimes] Don't try passing --target flags to GCC
When a target triple is specified in CMake via XXX_TARGET_TRIPLE, we tried passing the --target=<...> flag to the compiler. However, not all compilers support that flag (e.g. GCC, which is not a cross-compiler). As a result, setting e.g. LIBCXX_TARGET_TRIPLE=<host-triple> would end up trying to pass --target=<host-triple> to GCC, which breaks everything because the flag isn't even supported. This commit only adds `--target=<...>` & friends to the flags if it is supported by the compiler. One could argue that it's confusing to pass LIBCXX_TARGET_TRIPLE=<...> and have it be ignored. That's correct, and one possibility would be to assert that the requested triple is the same as the host triple when we know the compiler is unable to cross-compile. However, note that this is a pre-existing issue (setting the TARGET_TRIPLE variable never had an influence on the flags passed to the compiler), and also fixing that is starting to look like reimplementing a lot of CMake logic that is already handled with CMAKE_CXX_COMPILER_TARGET. Differential Revision: https://reviews.llvm.org/D106082
Diffstat (limited to 'libcxxabi/cmake')
-rw-r--r--libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake11
1 files changed, 11 insertions, 0 deletions
diff --git a/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake b/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake
index 19d6e93b20b0..512e71a6a780 100644
--- a/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake
+++ b/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake
@@ -123,6 +123,17 @@ macro(add_target_flags_if condition)
endif()
endmacro()
+# Add all the flags supported by the compiler to all of
+# 'CMAKE_CXX_FLAGS', 'CMAKE_C_FLAGS', 'LIBCXXABI_COMPILE_FLAGS'
+# and 'LIBCXXABI_LINK_FLAGS'.
+macro(add_target_flags_if_supported)
+ foreach(flag ${ARGN})
+ mangle_name("${flag}" flagname)
+ check_cxx_compiler_flag("${flag}" "LIBCXXABI_SUPPORTS_${flagname}_FLAG")
+ add_target_flags_if(LIBCXXABI_SUPPORTS_${flagname}_FLAG ${flag})
+ endforeach()
+endmacro()
+
# Add a specified list of flags to both 'LIBCXXABI_COMPILE_FLAGS' and
# 'LIBCXXABI_LINK_FLAGS'.
macro(add_flags)