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

Eric Fiselier eric at efcs.ca
Tue Mar 3 07:59:09 PST 2015


Author: ericwf
Date: Tue Mar  3 09:59:09 2015
New Revision: 231075

URL: http://llvm.org/viewvc/llvm-project?rev=231075&view=rev
Log:
[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

Modified:
    libcxxabi/trunk/CMakeLists.txt
    libcxxabi/trunk/src/CMakeLists.txt
    libcxxabi/trunk/test/CMakeLists.txt

Modified: libcxxabi/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=231075&r1=231074&r2=231075&view=diff
==============================================================================
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Tue Mar  3 09:59:09 2015
@@ -126,6 +126,11 @@ set(LIBCXXABI_SYSROOT "" CACHE STRING "S
 # 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

Modified: libcxxabi/trunk/src/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/CMakeLists.txt?rev=231075&r1=231074&r2=231075&view=diff
==============================================================================
--- libcxxabi/trunk/src/CMakeLists.txt (original)
+++ libcxxabi/trunk/src/CMakeLists.txt Tue Mar  3 09:59:09 2015
@@ -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}")
+
+# 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_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}
   )

Modified: libcxxabi/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/CMakeLists.txt?rev=231075&r1=231074&r2=231075&view=diff
==============================================================================
--- libcxxabi/trunk/test/CMakeLists.txt (original)
+++ libcxxabi/trunk/test/CMakeLists.txt Tue Mar  3 09:59:09 2015
@@ -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()





More information about the cfe-commits mailing list