[libcxx-commits] [libcxxabi] [libc++abi] Use target_compile_options to pass LIBCXXABI_ADDITIONAL_COMPILE_FLAGS (PR #96112)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 19 13:30:44 PDT 2024


https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/96112

We use target_compile_options to pass the libc++ variant of this flag, so we should be consistent for libc++abi. This is actually not only a matter of consistency: target_compile_options handles duplicate CMake options in a certain way (it removes duplicates but has an escape hatch using the "SHELL:" prefix), and it is important for both libc++ and libc++abi options to be handled in the same way.

>From 59ea50c2282f3fe046cf064d6ba0b87ece39c31c Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 19 Jun 2024 16:27:19 -0400
Subject: [PATCH] [libc++abi] Use target_compile_options to pass
 LIBCXXABI_ADDITIONAL_COMPILE_FLAGS

We use target_compile_options to pass the libc++ variant of this flag, so
we should be consistent for libc++abi. This is actually not only a matter
of consistency: target_compile_options handles duplicate CMake options in
a certain way (it removes duplicates but has an escape hatch using the
"SHELL:" prefix), and it is important for both libc++ and libc++abi
options to be handled in the same way.
---
 libcxxabi/CMakeLists.txt     | 1 -
 libcxxabi/src/CMakeLists.txt | 2 ++
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index 52ba52f3439fb..43400c6e8d9af 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -244,7 +244,6 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
   add_flags_if_supported("-mdefault-visibility-export-mapping=explicit")
   set(CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF)
 endif()
-add_compile_flags("${LIBCXXABI_ADDITIONAL_COMPILE_FLAGS}")
 add_library_flags("${LIBCXXABI_ADDITIONAL_LIBRARIES}")
 
 # Configure compiler. Must happen after setting the target flags.
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index c54ced4dc3ea8..d6fcd72dcb1bd 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -182,6 +182,7 @@ set_target_properties(cxxabi_shared_objects
 if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
   set_target_properties(cxxabi_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
 endif()
+target_compile_options(cxxabi_shared_objects PUBLIC "${LIBCXXABI_ADDITIONAL_COMPILE_FLAGS}")
 
 if (LIBCXXABI_ENABLE_SHARED)
   add_library(cxxabi_shared SHARED)
@@ -261,6 +262,7 @@ set_target_properties(cxxabi_static_objects
     CXX_STANDARD_REQUIRED OFF # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake
     COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
 )
+target_compile_options(cxxabi_static_objects PUBLIC "${LIBCXXABI_ADDITIONAL_COMPILE_FLAGS}")
 
 if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
   target_add_compile_flags_if_supported(cxxabi_static_objects PRIVATE -fvisibility=hidden)



More information about the libcxx-commits mailing list