Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -126,6 +126,11 @@ # 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 Index: src/CMakeLists.txt =================================================================== --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -34,18 +34,6 @@ 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 @@ 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 @@ 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}") + +# Add a object library that contains the compiled source files. +add_library(cxxabi_objects OBJECT ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS}) -set_target_properties(cxxabi +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_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_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} ) Index: test/CMakeLists.txt =================================================================== --- test/CMakeLists.txt +++ test/CMakeLists.txt @@ -21,7 +21,7 @@ ${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()