diff options
author | Petr Hosek <phosek@chromium.org> | 2018-07-23 04:19:55 +0000 |
---|---|---|
committer | Petr Hosek <phosek@chromium.org> | 2018-07-23 04:19:55 +0000 |
commit | cf7b0dec301ce2e3bbe0ddaa72bbe3266b0d10a5 (patch) | |
tree | 8c637243c5bad4a19f0f7523c30a625cc2962ab3 /libcxxabi/src | |
parent | 59e91a956805707352cba4853e7632861f2d8e75 (diff) |
[CMake] Support statically linking dependencies only to shared or static library
Currently it's possible to select whether to statically link unwinder
or the C++ ABI library, but this option applies to both the shared
and static library. However, in some scenarios it may be desirable to
only statically link unwinder and C++ ABI library into static C++
library since for shared C++ library we can rely on dynamic linking
and linker scripts. This change enables selectively enabling or
disabling statically linking only to shared or static library.
Differential Revision: https://reviews.llvm.org/D49502
Diffstat (limited to 'libcxxabi/src')
-rw-r--r-- | libcxxabi/src/CMakeLists.txt | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt index 5a929cff170..75c7e6d92ed 100644 --- a/libcxxabi/src/CMakeLists.txt +++ b/libcxxabi/src/CMakeLists.txt @@ -61,19 +61,27 @@ if (LIBCXXABI_USE_LLVM_UNWINDER) # Prefer using the in-tree version of libunwind, either shared or static. If # none are found fall back to using -lunwind. # FIXME: Is it correct to prefer the static version of libunwind? - if (NOT LIBCXXABI_ENABLE_STATIC_UNWINDER AND (TARGET unwind_shared OR HAVE_LIBUNWIND)) - list(APPEND LIBCXXABI_LIBRARIES unwind_shared) - elseif (LIBCXXABI_ENABLE_STATIC_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND)) - list(APPEND LIBCXXABI_LIBRARIES unwind_static) + if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND)) + list(APPEND LIBCXXABI_SHARED_LIBRARIES unwind_shared) + elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND)) + list(APPEND LIBCXXABI_SHARED_LIBRARIES unwind_static) else() - list(APPEND LIBCXXABI_LIBRARIES unwind) + list(APPEND LIBCXXABI_SHARED_LIBRARIES unwind) + endif() + if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND)) + list(APPEND LIBCXXABI_STATIC_LIBRARIES unwind_shared) + elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND)) + # We handle this by directly merging libunwind objects into libc++abi. + else() + list(APPEND LIBCXXABI_STATIC_LIBRARIES unwind) endif() else() add_library_flags_if(LIBCXXABI_HAS_GCC_S_LIB gcc_s) endif() if (MINGW) # MINGW_LIBRARIES is defined in config-ix.cmake - list(APPEND LIBCXXABI_LIBRARIES ${MINGW_LIBRARIES}) + list(APPEND LIBCXXABI_SHARED_LIBRARIES ${MINGW_LIBRARIES}) + list(APPEND LIBCXXABI_STATIC_LIBRARIES ${MINGW_LIBRARIES}) endif() # Setup flags. @@ -130,7 +138,7 @@ if (LIBCXXABI_ENABLE_SHARED) if(COMMAND llvm_setup_rpath) llvm_setup_rpath(cxxabi_shared) endif() - target_link_libraries(cxxabi_shared ${LIBCXXABI_LIBRARIES}) + target_link_libraries(cxxabi_shared ${LIBCXXABI_SHARED_LIBRARIES}) set_target_properties(cxxabi_shared PROPERTIES CXX_EXTENSIONS @@ -155,13 +163,13 @@ endif() # Build the static library. if (LIBCXXABI_ENABLE_STATIC) set(cxxabi_static_sources $<TARGET_OBJECTS:cxxabi_objects>) - if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_ENABLE_STATIC_UNWINDER) + if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY) if (TARGET unwind_static OR HAVE_LIBUNWIND) list(APPEND cxxabi_static_sources $<TARGET_OBJECTS:unwind_objects>) endif() endif() add_library(cxxabi_static STATIC ${cxxabi_static_sources}) - target_link_libraries(cxxabi_static ${LIBCXXABI_LIBRARIES}) + target_link_libraries(cxxabi_static ${LIBCXXABI_STATIC_LIBRARIES}) set_target_properties(cxxabi_static PROPERTIES CXX_EXTENSIONS |