[libcxxabi] Build both static and shared versions of libc++abi by default.

Summary:
This patch builds both static and shared versions of libc++abi by default. It adds/repurposes the following cmake options:
* `LIBCXXABI_ENABLE_SHARED`: Enable/disable building the shared library. (Previously using `OFF` would build the static library instead)
* `LIBCXXABI_ENABLE_STATIC`: Enable/disable building the static library.

This patch also re-purposes the CMake target `cxxabi` to be a meta-target for `cxxabi_shared` and `cxxabi_static`. This could potentially break other builds that depend on `cxxabi` being a library target. We will need to apply a patch to libc++'s CMake before committing this change. 

Running the tests is still only supported when the shared version is built. Support for running the tests against the static library will come in another patch.


Reviewers: jroelofs, mclow.lists, danalbert, compnerd

Reviewed By: danalbert, compnerd

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D8013

llvm-svn: 231075
This commit is contained in:
Eric Fiselier 2015-03-03 15:59:09 +00:00
parent 10d576d8dc
commit 14dbeaadc1
3 changed files with 50 additions and 25 deletions

View File

@ -126,6 +126,11 @@ set(LIBCXXABI_SYSROOT "" CACHE STRING "Sysroot for cross compiling.")
# case of an in tree build, libc++ will prefer a dynamic libc++abi from the
# system over a static libc++abi from the output directory.
option(LIBCXXABI_ENABLE_SHARED "Build libc++abi as a shared library." ON)
option(LIBCXXABI_ENABLE_STATIC "Build libc++abi as a static library." ON)
if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
message(FATAL_ERROR "libc++abi must be built as either a shared or static library.")
endif()
find_path(
LIBCXXABI_LIBCXX_INCLUDES

View File

@ -34,18 +34,6 @@ if (MSVC_IDE OR XCODE)
endif()
endif()
if (LIBCXXABI_ENABLE_SHARED)
add_library(cxxabi SHARED
${LIBCXXABI_SOURCES}
${LIBCXXABI_HEADERS}
)
else()
add_library(cxxabi STATIC
${LIBCXXABI_SOURCES}
${LIBCXXABI_HEADERS}
)
endif()
include_directories("${LIBCXXABI_LIBCXX_INCLUDES}")
if (LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
@ -65,22 +53,23 @@ else()
append_if(libraries LIBCXXABI_HAS_GCC_EH_LIB gcc_eh)
endif()
target_link_libraries(cxxabi ${libraries})
# Setup flags.
append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_FPIC_FLAG -fPIC)
append_if(LIBCXXABI_LINK_FLAGS LIBCXXABI_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
set(LIBCXXABI_SHARED_LINK_FLAGS)
if ( APPLE )
if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" )
list(APPEND LIBCXXABI_COMPILE_FLAGS "-U__STRICT_ANSI__")
list(APPEND LIBCXXABI_LINK_FLAGS
list(APPEND LIBCXXABI_SHARED_LINK_FLAGS
"-compatibility_version 1"
"-current_version 1"
"-install_name /usr/lib/libc++abi.1.dylib"
"/usr/lib/libSystem.B.dylib")
else()
"-install_name /usr/lib/libc++abi.1.dylib")
list(APPEND LIBCXXABI_LINK_FLAGS
"/usr/lib/libSystem.B.dylib")
else()
list(APPEND LIBCXXABI_SHARED_LINK_FLAGS
"-compatibility_version 1"
"-install_name /usr/lib/libc++abi.1.dylib")
endif()
@ -88,17 +77,48 @@ endif()
string(REPLACE ";" " " LIBCXXABI_COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}")
string(REPLACE ";" " " LIBCXXABI_LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}")
string(REPLACE ";" " " LIBCXXABI_SHARED_LINK_FLAGS "${LIBCXXABI_SHARED_LINK_FLAGS}")
set_target_properties(cxxabi
# Add a object library that contains the compiled source files.
add_library(cxxabi_objects OBJECT ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
set_target_properties(cxxabi_objects
PROPERTIES
COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
OUTPUT_NAME "c++abi"
VERSION "1.0"
SOVERSION "1"
)
install(TARGETS cxxabi
set(LIBCXXABI_TARGETS)
# Build the shared library.
if (LIBCXXABI_ENABLE_SHARED)
add_library(cxxabi_shared SHARED $<TARGET_OBJECTS:cxxabi_objects>)
target_link_libraries(cxxabi_shared ${libraries})
set_target_properties(cxxabi_shared
PROPERTIES
LINK_FLAGS "${LIBCXXABI_LINK_FLAGS} ${LIBCXXABI_SHARED_LINK_FLAGS}"
OUTPUT_NAME "c++abi"
VERSION "1.0"
SOVERSION "1"
)
list(APPEND LIBCXXABI_TARGETS "cxxabi_shared")
endif()
# Build the static library.
if (LIBCXXABI_ENABLE_STATIC)
add_library(cxxabi_static STATIC $<TARGET_OBJECTS:cxxabi_objects>)
target_link_libraries(cxxabi_static ${libraries})
set_target_properties(cxxabi_static
PROPERTIES
LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
OUTPUT_NAME "c++abi"
)
list(APPEND LIBCXXABI_TARGETS "cxxabi_static")
endif()
# Add a meta-target for both libraries.
add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS})
install(TARGETS ${LIBCXXABI_TARGETS}
LIBRARY DESTINATION lib${LIBCXXABI_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LIBCXXABI_LIBDIR_SUFFIX}
)

View File

@ -21,7 +21,7 @@ configure_file(
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
@ONLY)
set(LIBCXXABI_TEST_DEPS cxxabi)
set(LIBCXXABI_TEST_DEPS cxxabi_shared)
if (NOT LIBCXXABI_BUILT_STANDALONE)
list(APPEND LIBCXXABI_TEST_DEPS cxx)
endif()