[PATCH] D22716: [libunwind] support building shared lib and static lib simultaneously
Lei Zhang via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 22 18:27:31 PDT 2016
zlei created this revision.
zlei added reviewers: rmaprath, EricWF, cfe-commits.
Currently libunwind can be configured to build either shared lib or static lib, but not both. Downstream package maintainers may want to build/install shared lib and static lib simultaneously, without configuring twice.
This patch enables building static lib along with shared lib.
https://reviews.llvm.org/D22716
Files:
CMakeLists.txt
src/CMakeLists.txt
Index: src/CMakeLists.txt
===================================================================
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -49,20 +49,12 @@
${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,40 @@
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
+set(LIBUNWIND_TARGETS)
+
+if (LIBUNWIND_ENABLE_SHARED)
+ add_library(unwind_shared SHARED ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
+ target_link_libraries(unwind_shared ${libraries})
+ set_target_properties(unwind_shared
+ PROPERTIES
+ COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
+ LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
+ OUTPUT_NAME "unwind"
+ VERSION "1.0"
+ SOVERSION "1")
+ list(APPEND LIBUNWIND_TARGETS "unwind_shared")
+endif ()
+
+if (LIBUNWIND_ENABLE_STATIC)
+ add_library(unwind_static STATIC ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
+ target_link_libraries(unwind_static ${libraries})
+ set_target_properties(unwind_static
+ PROPERTIES
+ COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
+ LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
+ OUTPUT_NAME "unwind")
+ list(APPEND LIBUNWIND_TARGETS "unwind_static")
+endif ()
+
+add_custom_target(unwind DEPENDS ${LIBUNWIND_TARGETS})
+
+install(TARGETS ${LIBUNWIND_TARGETS}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -104,6 +104,7 @@
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." OFF)
option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF)
option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22716.65204.patch
Type: text/x-patch
Size: 3562 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160723/95ccaf4b/attachment.bin>
More information about the cfe-commits
mailing list