[libcxx-commits] [libcxxabi] [libunwind] [libcxx] [runtimes] Always define cxx_shared, cxx_static & other targets (PR #80007)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 30 06:14:53 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libunwind
Author: Louis Dionne (ldionne)
<details>
<summary>Changes</summary>
However, mark them as EXCLUDE_FROM_ALL when we don't want to build them. Simply declaring the targets should be of no harm, and it allows other projects to mention these targets regardless of whether they end up being built or not.
This patch basically moves the definition of e.g. cxx_shared out of the `if (LIBCXX_ENABLE_SHARED)` and instead marks it as EXCLUDE_FROM_ALL conditionally on whether LIBCXX_ENABLE_SHARED is passed. It then does the same for libunwind and libc++abi targets.
This is a reapplication of 79ee0342dbf0, which was reverted in a3539090884c because it broke the TSAN and the Fuchsia builds.
Resolves #<!-- -->77654
Differential Revision: https://reviews.llvm.org/D134221
---
Full diff: https://github.com/llvm/llvm-project/pull/80007.diff
4 Files Affected:
- (modified) libcxx/cmake/caches/AIX.cmake (+7)
- (modified) libcxx/src/CMakeLists.txt (+9-11)
- (modified) libcxxabi/src/CMakeLists.txt (+11-11)
- (modified) libunwind/src/CMakeLists.txt (+10-10)
``````````diff
diff --git a/libcxx/cmake/caches/AIX.cmake b/libcxx/cmake/caches/AIX.cmake
index c01aa5b14df0..d9de35d75d91 100644
--- a/libcxx/cmake/caches/AIX.cmake
+++ b/libcxx/cmake/caches/AIX.cmake
@@ -15,3 +15,10 @@ set(LIBCXXABI_ENABLE_STATIC OFF CACHE BOOL "")
set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
set(LIBUNWIND_ENABLE_SHARED ON CACHE BOOL "")
set(LIBUNWIND_ENABLE_STATIC OFF CACHE BOOL "")
+
+# On AIX, both shared and static libraries are archived. As a result, both the static and the shared targets end
+# up with a `.a` suffix, which conflict. To workaround that, we set a different output name for the static
+# libraries, which we never actually build anyway. For more information, see https://gitlab.kitware.com/cmake/cmake/-/issues/19494.
+set(LIBCXX_STATIC_OUTPUT_NAME "c++-static" CACHE STRING "")
+set(LIBCXXABI_STATIC_OUTPUT_NAME "c++abi-static" CACHE STRING "")
+set(LIBUNWIND_STATIC_OUTPUT_NAME "unwind-static" CACHE STRING "")
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 44a088663463..007491897170 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -155,10 +155,6 @@ if (LIBCXX_CONFIGURE_IDE)
endif()
endif()
-if(NOT LIBCXX_INSTALL_LIBRARY)
- set(exclude_from_all EXCLUDE_FROM_ALL)
-endif()
-
if (LIBCXX_GENERATE_COVERAGE AND NOT LIBCXX_COVERAGE_LIBRARY)
find_compiler_rt_library(profile LIBCXX_COVERAGE_LIBRARY)
endif()
@@ -194,8 +190,7 @@ split_list(LIBCXX_COMPILE_FLAGS)
split_list(LIBCXX_LINK_FLAGS)
# Build the shared library.
-if (LIBCXX_ENABLE_SHARED)
- add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
+ add_library(cxx_shared SHARED $<$<NOT:$<BOOL:LIBCXX_ENABLE_SHARED>>:EXCLUDE_FROM_ALL> ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
target_include_directories(cxx_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(cxx_shared PUBLIC cxx-headers
PRIVATE ${LIBCXX_LIBRARIES})
@@ -274,7 +269,10 @@ if (LIBCXX_ENABLE_SHARED)
)
endif()
+if (LIBCXX_ENABLE_SHARED)
list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared")
+endif()
+
if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
# Since we most likely do not have a mt.exe replacement, disable the
# manifest bundling. This allows a normal cmake invocation to pass which
@@ -282,13 +280,11 @@ if (LIBCXX_ENABLE_SHARED)
set_target_properties(cxx_shared PROPERTIES
APPEND_STRING PROPERTY LINK_FLAGS " /MANIFEST:NO")
endif()
-endif()
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
# Build the static library.
-if (LIBCXX_ENABLE_STATIC)
- add_library(cxx_static STATIC ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
+ add_library(cxx_static STATIC $<$<NOT:$<BOOL:LIBCXX_ENABLE_STATIC>>:EXCLUDE_FROM_ALL> ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
target_include_directories(cxx_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(cxx_static PUBLIC cxx-headers
PRIVATE ${LIBCXX_LIBRARIES}
@@ -314,16 +310,18 @@ if (LIBCXX_ENABLE_STATIC)
target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
endif()
- list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")
+ if (LIBCXX_ENABLE_STATIC)
+ list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")
+ endif()
# Attempt to merge the libc++.a archive and the ABI library archive into one.
if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)
target_link_libraries(cxx_static PRIVATE libcxx-abi-static-objects)
endif()
-endif()
# Add a meta-target for both libraries.
add_custom_target(cxx DEPENDS ${LIBCXX_BUILD_TARGETS})
+# Build the experimental static library
set(LIBCXX_EXPERIMENTAL_SOURCES
experimental/keep.cpp
)
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index 4198827203fc..ed357ba63f45 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -183,8 +183,7 @@ if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CO
set_target_properties(cxxabi_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
endif()
-if (LIBCXXABI_ENABLE_SHARED)
- add_library(cxxabi_shared SHARED)
+ add_library(cxxabi_shared SHARED $<$<NOT:$<BOOL:LIBCXXABI_ENABLE_SHARED>>:EXCLUDE_FROM_ALL>)
set_target_properties(cxxabi_shared
PROPERTIES
LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
@@ -207,10 +206,12 @@ if (LIBCXXABI_ENABLE_SHARED)
PUBLIC cxxabi_shared_objects
PRIVATE ${LIBCXXABI_LIBRARIES})
+if (LIBCXXABI_ENABLE_SHARED)
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared")
- if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
- list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
- endif()
+endif()
+if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
+ list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
+endif()
add_library(cxxabi-reexports INTERFACE)
@@ -240,7 +241,6 @@ if (LIBCXXABI_ENABLE_SHARED)
endif()
endif()
endif()
-endif()
# Build the static library.
add_library(cxxabi_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
@@ -276,8 +276,7 @@ if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
endif()
-if (LIBCXXABI_ENABLE_STATIC)
- add_library(cxxabi_static STATIC)
+ add_library(cxxabi_static STATIC $<$<NOT:$<BOOL:LIBCXXABI_ENABLE_STATIC>>:EXCLUDE_FROM_ALL>)
if (LIBCXXABI_USE_LLVM_UNWINDER AND NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
target_link_libraries(cxxabi_static PUBLIC unwind_static)
endif()
@@ -290,10 +289,11 @@ if (LIBCXXABI_ENABLE_STATIC)
PUBLIC cxxabi_static_objects
PRIVATE ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
+if (LIBCXXABI_ENABLE_STATIC)
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_static")
- if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
- list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
- endif()
+endif()
+if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
+ list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
endif()
# Add a meta-target for both libraries.
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 9c6f5d908b09..eca127792287 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -162,8 +162,7 @@ if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CO
set_target_properties(unwind_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
endif()
-if (LIBUNWIND_ENABLE_SHARED)
- add_library(unwind_shared SHARED)
+ add_library(unwind_shared SHARED $<$<NOT:$<BOOL:LIBUNWIND_ENABLE_SHARED>>:EXCLUDE_FROM_ALL>)
target_link_libraries(unwind_shared PUBLIC unwind_shared_objects)
set_target_properties(unwind_shared
PROPERTIES
@@ -174,10 +173,11 @@ if (LIBUNWIND_ENABLE_SHARED)
SOVERSION "1"
)
+if (LIBUNWIND_ENABLE_SHARED)
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
- if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
- list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
- endif()
+endif()
+if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
+ list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
endif()
# Build the static library.
@@ -205,8 +205,7 @@ if(LIBUNWIND_HIDE_SYMBOLS)
target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
endif()
-if (LIBUNWIND_ENABLE_STATIC)
- add_library(unwind_static STATIC)
+ add_library(unwind_static STATIC $<$<NOT:$<BOOL:LIBUNWIND_ENABLE_STATIC>>:EXCLUDE_FROM_ALL>)
target_link_libraries(unwind_static PUBLIC unwind_static_objects)
set_target_properties(unwind_static
PROPERTIES
@@ -215,10 +214,11 @@ if (LIBUNWIND_ENABLE_STATIC)
OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
)
+if (LIBUNWIND_ENABLE_STATIC)
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
- if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
- list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
- endif()
+endif()
+if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
+ list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
endif()
# Add a meta-target for both libraries.
``````````
</details>
https://github.com/llvm/llvm-project/pull/80007
More information about the libcxx-commits
mailing list