Revert "[runtimes] Always define cxx_shared, cxx_static & other targets"

This reverts commit 79ee0342db which
breaks the LLVM TSan bots.
This commit is contained in:
Haowei Wu 2022-10-12 12:54:48 -07:00
parent 17095dfe36
commit a353909088
4 changed files with 215 additions and 228 deletions

View File

@ -17,10 +17,3 @@ set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
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 "")

View File

@ -147,6 +147,10 @@ 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()
@ -191,14 +195,13 @@ endfunction()
split_list(LIBCXX_COMPILE_FLAGS)
split_list(LIBCXX_LINK_FLAGS)
#
# Build the shared library.
#
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
if (LIBCXX_ENABLE_SHARED)
add_library(cxx_shared 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})
set_target_properties(cxx_shared
set_target_properties(cxx_shared
PROPERTIES
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
@ -206,11 +209,11 @@ set_target_properties(cxx_shared
VERSION "${LIBCXX_LIBRARY_VERSION}"
SOVERSION "${LIBCXX_ABI_VERSION}"
DEFINE_SYMBOL ""
)
cxx_add_common_build_flags(cxx_shared)
cxx_set_common_defines(cxx_shared)
)
cxx_add_common_build_flags(cxx_shared)
cxx_set_common_defines(cxx_shared)
if(ZOS)
if(ZOS)
add_custom_command(TARGET cxx_shared POST_BUILD
COMMAND
${LIBCXX_SOURCE_DIR}/utils/zos_rename_dll_side_deck.sh
@ -218,25 +221,25 @@ if(ZOS)
COMMENT "Rename dll name inside the side deck file"
WORKING_DIRECTORY $<TARGET_FILE_DIR:cxx_shared>
)
endif()
endif()
# Link against libc++abi
if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY)
# Link against libc++abi
if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY)
target_link_libraries(cxx_shared PRIVATE libcxx-abi-shared-objects)
else()
else()
target_link_libraries(cxx_shared PUBLIC libcxx-abi-shared)
endif()
endif()
# Maybe re-export symbols from libc++abi
# In particular, we don't re-export the symbols if libc++abi is merged statically
# into libc++ because in that case there's no dylib to re-export from.
if (APPLE AND LIBCXX_CXX_ABI STREQUAL "libcxxabi"
# Maybe re-export symbols from libc++abi
# In particular, we don't re-export the symbols if libc++abi is merged statically
# into libc++ because in that case there's no dylib to re-export from.
if (APPLE AND LIBCXX_CXX_ABI STREQUAL "libcxxabi"
AND NOT DEFINED LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS
AND NOT LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY)
set(LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS ON)
endif()
endif()
if (LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS)
if (LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS)
target_link_libraries(cxx_shared PRIVATE
"-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++unexp.exp"
"-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++abi.exp"
@ -244,10 +247,10 @@ if (LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS)
"-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/weak.exp")
target_link_libraries(cxx_shared PRIVATE $<TARGET_NAME_IF_EXISTS:cxxabi-reexports>)
endif()
endif()
# Generate a linker script in place of a libc++.so symlink.
if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
# Generate a linker script in place of a libc++.so symlink.
if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
set(link_libraries)
set(imported_libname "$<TARGET_PROPERTY:libcxx-abi-shared,IMPORTED_LIBNAME>")
@ -272,39 +275,37 @@ if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
COMMENT "Generating linker script: '${linker_script}' as file $<TARGET_LINKER_FILE:cxx_shared>"
VERBATIM
)
endif()
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")
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
# will attempt to use the manifest tool to generate the bundled manifest
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.
#
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
if (LIBCXX_ENABLE_STATIC)
add_library(cxx_static 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}
PRIVATE libcxx-abi-static)
set_target_properties(cxx_static
set_target_properties(cxx_static
PROPERTIES
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
OUTPUT_NAME "${LIBCXX_STATIC_OUTPUT_NAME}"
)
cxx_add_common_build_flags(cxx_static)
cxx_set_common_defines(cxx_static)
)
cxx_add_common_build_flags(cxx_static)
cxx_set_common_defines(cxx_static)
if (LIBCXX_HERMETIC_STATIC_LIBRARY)
if (LIBCXX_HERMETIC_STATIC_LIBRARY)
# If the hermetic library doesn't define the operator new/delete functions
# then its code shouldn't declare them with hidden visibility. They might
# actually be provided by a shared library at link time.
@ -315,22 +316,18 @@ if (LIBCXX_HERMETIC_STATIC_LIBRARY)
# _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS can be defined in __config_site
# too. Define it in the same way here, to avoid redefinition conflicts.
target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
endif()
endif()
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)
# 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/memory_resource.cpp
format.cpp

View File

@ -182,16 +182,17 @@ 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()
add_library(cxxabi_shared SHARED $<$<NOT:$<BOOL:LIBCXXABI_ENABLE_SHARED>>:EXCLUDE_FROM_ALL>)
set_target_properties(cxxabi_shared
if (LIBCXXABI_ENABLE_SHARED)
add_library(cxxabi_shared SHARED)
set_target_properties(cxxabi_shared
PROPERTIES
LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
OUTPUT_NAME "${LIBCXXABI_SHARED_OUTPUT_NAME}"
SOVERSION "1"
VERSION "${LIBCXXABI_LIBRARY_VERSION}"
)
)
if (ZOS)
if (ZOS)
add_custom_command(TARGET cxxabi_shared POST_BUILD
COMMAND
${LIBCXXABI_LIBCXX_PATH}/utils/zos_rename_dll_side_deck.sh
@ -199,25 +200,24 @@ if (ZOS)
COMMENT "Rename dll name inside the side deck file"
WORKING_DIRECTORY $<TARGET_FILE_DIR:cxxabi_shared>
)
endif ()
endif ()
target_link_libraries(cxxabi_shared
target_link_libraries(cxxabi_shared
PUBLIC cxxabi_shared_objects
PRIVATE ${LIBCXXABI_SHARED_LIBRARIES} ${LIBCXXABI_LIBRARIES})
if (TARGET pstl::ParallelSTL)
if (TARGET pstl::ParallelSTL)
target_link_libraries(cxxabi_shared PUBLIC pstl::ParallelSTL)
endif()
endif()
if (LIBCXXABI_ENABLE_SHARED)
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared")
endif()
if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
endif()
endif()
add_library(cxxabi-reexports INTERFACE)
# -exported_symbols_list is only available on Apple platforms
if (APPLE)
add_library(cxxabi-reexports INTERFACE)
# -exported_symbols_list is only available on Apple platforms
if (APPLE)
function(export_symbols file)
target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${file}")
endfunction()
@ -241,6 +241,7 @@ if (APPLE)
reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-v0.exp")
endif()
endif()
endif()
endif()
# Build the static library.
@ -276,27 +277,27 @@ if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
endif()
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)
if (LIBCXXABI_ENABLE_STATIC)
add_library(cxxabi_static STATIC)
if (LIBCXXABI_USE_LLVM_UNWINDER AND NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
target_link_libraries(cxxabi_static PUBLIC unwind_static)
endif()
set_target_properties(cxxabi_static
endif()
set_target_properties(cxxabi_static
PROPERTIES
LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
OUTPUT_NAME "${LIBCXXABI_STATIC_OUTPUT_NAME}"
)
target_link_libraries(cxxabi_static
target_link_libraries(cxxabi_static
PUBLIC cxxabi_static_objects
PRIVATE ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
if (TARGET pstl::ParallelSTL)
if (TARGET pstl::ParallelSTL)
target_link_libraries(cxxabi_static PUBLIC pstl::ParallelSTL)
endif()
endif()
if (LIBCXXABI_ENABLE_STATIC)
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_static")
endif()
if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
endif()
endif()
# Add a meta-target for both libraries.

View File

@ -135,9 +135,7 @@ set_property(SOURCE ${LIBUNWIND_C_SOURCES}
# ease, but does not rely on C++ at runtime.
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
#
# Build the shared library.
#
add_library(unwind_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
target_compile_options(unwind_shared_objects PRIVATE /GR-)
@ -156,27 +154,25 @@ 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()
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
if (LIBUNWIND_ENABLE_SHARED)
add_library(unwind_shared SHARED)
target_link_libraries(unwind_shared PUBLIC unwind_shared_objects)
set_target_properties(unwind_shared
PROPERTIES
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
LINKER_LANGUAGE C
OUTPUT_NAME "${LIBUNWIND_SHARED_OUTPUT_NAME}"
VERSION "1.0"
SOVERSION "1"
)
)
if (LIBUNWIND_ENABLE_SHARED)
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
endif()
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
endif()
endif()
#
# Build the static library.
#
add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
target_compile_options(unwind_static_objects PRIVATE /GR-)
@ -198,20 +194,20 @@ if(LIBUNWIND_HIDE_SYMBOLS)
target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
endif()
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
if (LIBUNWIND_ENABLE_STATIC)
add_library(unwind_static STATIC)
target_link_libraries(unwind_static PUBLIC unwind_static_objects)
set_target_properties(unwind_static
PROPERTIES
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
LINKER_LANGUAGE C
OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
)
)
if (LIBUNWIND_ENABLE_STATIC)
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
endif()
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
endif()
endif()
# Add a meta-target for both libraries.