[libcxx] Add support for linking libc++ against a static ABI library.
Summary:
This patch add the CMake option `LIBCXX_ENABLE_STATIC_ABI_LIBRARY` which, when enabled, will link libc++ against the static version of the ABI library.
Reviewers: mclow.lists, jroelofs, danalbert
Reviewed By: danalbert
Subscribers: compnerd, cfe-commits
Differential Revision: http://reviews.llvm.org/D8017
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@231076 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index fb09c63..d50b2cc 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -34,22 +34,33 @@
)
endif()
+#if LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path.
+if (DEFINED LIBCXX_CXX_ABI_LIBRARY_PATH)
+ target_link_libraries(cxx "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}")
+endif()
+
if (DEFINED LIBCXX_CXX_ABI_DEPS)
add_dependencies(cxx LIBCXX_CXX_ABI_DEPS)
endif()
+set(libraries "")
+if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
+ # TODO(ericwf): Remove these GNU specific linker flags and let CMake do the
+ # configuration. This will be more portable.
+ list(APPEND libraries "-Wl,--whole-archive" "-Wl,-Bstatic")
+ list(APPEND libraries "${LIBCXX_CXX_ABI_LIBRARY}")
+ list(APPEND libraries "-Wl,-Bdynamic" "-Wl,--no-whole-archive")
+else()
+ list(APPEND libraries "${LIBCXX_CXX_ABI_LIBRARY}")
+endif()
+
# Generate library list.
-set(libraries ${LIBCXX_CXX_ABI_LIBRARY})
append_if(libraries LIBCXX_HAS_PTHREAD_LIB pthread)
append_if(libraries LIBCXX_HAS_C_LIB c)
append_if(libraries LIBCXX_HAS_M_LIB m)
append_if(libraries LIBCXX_HAS_RT_LIB rt)
append_if(libraries LIBCXX_HAS_GCC_S_LIB gcc_s)
-#if LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path.
-if (DEFINED LIBCXX_CXX_ABI_LIBRARY_PATH)
- target_link_libraries(cxx "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}")
-endif()
target_link_libraries(cxx ${libraries})
# Setup flags.