diff options
-rw-r--r-- | libunwind/CMakeLists.txt | 5 | ||||
-rw-r--r-- | libunwind/src/CMakeLists.txt | 53 |
2 files changed, 42 insertions, 16 deletions
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index ecbdff00b1e..bebf4adb5df 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -104,6 +104,7 @@ option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode. option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) option(LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON) +option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON) option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF) option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF) @@ -111,6 +112,10 @@ set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling." set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.") set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.") +if (NOT LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_STATIC) + message(FATAL_ERROR "libunwind must be built as either a shared or static library.") +endif() + # Check that we can build with 32 bits if requested. if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) if (LIBUNWIND_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt index b7c2d63e8ac..e01eb496654 100644 --- a/libunwind/src/CMakeLists.txt +++ b/libunwind/src/CMakeLists.txt @@ -49,20 +49,12 @@ set(LIBUNWIND_SOURCES ${LIBUNWIND_C_SOURCES} ${LIBUNWIND_ASM_SOURCES}) -if (LIBUNWIND_ENABLE_SHARED) - add_library(unwind SHARED ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS}) -else() - add_library(unwind STATIC ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS}) -endif () - # Generate library list. set(libraries ${LIBUNWINDCXX_ABI_LIBRARIES}) append_if(libraries LIBUNWIND_HAS_C_LIB c) append_if(libraries LIBUNWIND_HAS_DL_LIB dl) append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread) -target_link_libraries(unwind ${libraries}) - # Setup flags. append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_FPIC_FLAG -fPIC) append_if(LIBUNWIND_CXX_FLAGS LIBUNWIND_HAS_NO_RTTI_FLAG -fno-rtti) @@ -97,19 +89,48 @@ string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}") string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}") string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}") -set_target_properties(unwind - PROPERTIES - COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}" - LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}" - OUTPUT_NAME "unwind" - VERSION "1.0" - SOVERSION "1") set_property(SOURCE ${LIBUNWIND_CXX_SOURCES} APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_CXX_FLAGS} ${LIBUNWIND_CXX_FLAGS}") set_property(SOURCE ${LIBUNWIND_C_SOURCES} APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_C_FLAGS} ${LIBUNWIND_C_FLAGS}") -install(TARGETS unwind +# Add a object library that contains the compiled source files. +add_library(unwind_objects OBJECT ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS}) + +set_target_properties(unwind_objects + PROPERTIES + COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}") + +set(LIBUNWIND_TARGETS) + +# Build the shared library. +if (LIBUNWIND_ENABLE_SHARED) + add_library(unwind_shared SHARED $<TARGET_OBJECTS:unwind_objects>) + target_link_libraries(unwind_shared ${libraries}) + set_target_properties(unwind_shared + PROPERTIES + LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}" + OUTPUT_NAME "unwind" + VERSION "1.0" + SOVERSION "1") + list(APPEND LIBUNWIND_TARGETS "unwind_shared") +endif() + +# Build the static library. +if (LIBUNWIND_ENABLE_STATIC) + add_library(unwind_static STATIC $<TARGET_OBJECTS:unwind_objects>) + target_link_libraries(unwind_static ${libraries}) + set_target_properties(unwind_static + PROPERTIES + LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}" + OUTPUT_NAME "unwind") + list(APPEND LIBUNWIND_TARGETS "unwind_static") +endif() + +# Add a meta-target for both libraries. +add_custom_target(unwind DEPENDS ${LIBUNWIND_TARGETS}) + +install(TARGETS ${LIBUNWIND_TARGETS} LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |