• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Get sources
2
3set(LIBUNWIND_CXX_SOURCES
4    libunwind.cpp
5    Unwind-EHABI.cpp)
6append_if(LIBUNWIND_CXX_SOURCES APPLE Unwind_AppleExtras.cpp)
7
8set(LIBUNWIND_C_SOURCES
9    UnwindLevel1.c
10    UnwindLevel1-gcc-ext.c
11    Unwind-sjlj.c)
12set_source_files_properties(${LIBUNWIND_C_SOURCES}
13                            PROPERTIES
14                              COMPILE_FLAGS "-std=c99")
15
16set(LIBUNWIND_ASM_SOURCES
17    UnwindRegistersRestore.S
18    UnwindRegistersSave.S)
19set_source_files_properties(${LIBUNWIND_ASM_SOURCES}
20                            PROPERTIES
21                              LANGUAGE C)
22
23set(LIBUNWIND_HEADERS
24    AddressSpace.hpp
25    assembly.h
26    CompactUnwinder.hpp
27    config.h
28    dwarf2.h
29    DwarfInstructions.hpp
30    DwarfParser.hpp
31    libunwind_ext.h
32    Registers.hpp
33    RWMutex.hpp
34    UnwindCursor.hpp
35    ${CMAKE_CURRENT_SOURCE_DIR}/../include/libunwind.h
36    ${CMAKE_CURRENT_SOURCE_DIR}/../include/unwind.h)
37
38append_if(LIBUNWIND_HEADERS APPLE
39          "${CMAKE_CURRENT_SOURCE_DIR}/../include/mach-o/compact_unwind_encoding.h")
40
41if (MSVC_IDE)
42  # Force them all into the headers dir on MSVC, otherwise they end up at
43  # project scope because they don't have extensions.
44  source_group("Header Files" FILES ${LIBUNWIND_HEADERS})
45endif()
46
47set(LIBUNWIND_SOURCES
48    ${LIBUNWIND_CXX_SOURCES}
49    ${LIBUNWIND_C_SOURCES}
50    ${LIBUNWIND_ASM_SOURCES})
51
52# Generate library list.
53set(libraries ${LIBUNWINDCXX_ABI_LIBRARIES})
54append_if(libraries LIBUNWIND_HAS_C_LIB c)
55append_if(libraries LIBUNWIND_HAS_DL_LIB dl)
56if (LIBUNWIND_ENABLE_THREADS)
57  append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)
58endif()
59
60# Setup flags.
61append_if(LIBUNWIND_CXX_FLAGS LIBUNWIND_HAS_NO_RTTI_FLAG -fno-rtti)
62
63append_if(LIBUNWIND_LINK_FLAGS LIBUNWIND_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
64
65if (LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG AND LIBUNWIND_HAS_FUNWIND_TABLES)
66  list(APPEND LIBUNWIND_COMPILE_FLAGS -fno-exceptions)
67  list(APPEND LIBUNWIND_COMPILE_FLAGS -funwind-tables)
68elseif (LIBUNWIND_ENABLE_SHARED)
69  message(FATAL_ERROR
70          "Compiler doesn't support generation of unwind tables if exception "
71          "support is disabled.  Building libunwind DSO with runtime dependency "
72          "on C++ ABI library is not supported.")
73endif()
74
75if (APPLE)
76  list(APPEND LIBUNWIND_COMPILE_FLAGS "-U__STRICT_ANSI__")
77  list(APPEND LIBUNWIND_LINK_FLAGS
78       "-compatibility_version 1"
79       "-install_name /usr/lib/libunwind.1.dylib")
80
81  if (CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6")
82    list(APPEND LIBUNWIND_LINK_FLAGS
83         "-current_version ${LIBUNWIND_VERSION}"
84         "/usr/lib/libSystem.B.dylib")
85  endif ()
86endif ()
87
88string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
89string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
90string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
91string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
92
93set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
94             APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_CXX_FLAGS} ${LIBUNWIND_CXX_FLAGS}")
95set_property(SOURCE ${LIBUNWIND_C_SOURCES}
96             APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_C_FLAGS} ${LIBUNWIND_C_FLAGS}")
97
98# Add a object library that contains the compiled source files.
99add_library(unwind_objects OBJECT ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
100
101set_target_properties(unwind_objects
102                      PROPERTIES
103                        COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
104                        POSITION_INDEPENDENT_CODE ON)
105
106set(LIBUNWIND_TARGETS)
107
108# Build the shared library.
109if (LIBUNWIND_ENABLE_SHARED)
110  add_library(unwind_shared SHARED $<TARGET_OBJECTS:unwind_objects>)
111  target_link_libraries(unwind_shared ${libraries})
112  set_target_properties(unwind_shared
113                        PROPERTIES
114                          LINK_FLAGS    "${LIBUNWIND_LINK_FLAGS}"
115                          OUTPUT_NAME   "unwind"
116                          VERSION       "1.0"
117                          SOVERSION     "1")
118  list(APPEND LIBUNWIND_TARGETS "unwind_shared")
119endif()
120
121# Build the static library.
122if (LIBUNWIND_ENABLE_STATIC)
123  add_library(unwind_static STATIC $<TARGET_OBJECTS:unwind_objects>)
124  target_link_libraries(unwind_static ${libraries})
125  set_target_properties(unwind_static
126                        PROPERTIES
127                          LINK_FLAGS    "${LIBUNWIND_LINK_FLAGS}"
128                          OUTPUT_NAME   "unwind")
129  list(APPEND LIBUNWIND_TARGETS "unwind_static")
130endif()
131
132# Add a meta-target for both libraries.
133add_custom_target(unwind DEPENDS ${LIBUNWIND_TARGETS})
134
135if (LIBUNWIND_INSTALL_LIBRARY)
136  install(TARGETS ${LIBUNWIND_TARGETS}
137    LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind
138    ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind)
139endif()
140
141if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
142  add_custom_target(install-unwind
143    DEPENDS unwind
144    COMMAND "${CMAKE_COMMAND}"
145            -DCMAKE_INSTALL_COMPONENT=unwind
146            -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
147  add_custom_target(install-unwind-stripped
148    DEPENDS unwind
149    COMMAND "${CMAKE_COMMAND}"
150            -DCMAKE_INSTALL_COMPONENT=unwind
151            -DCMAKE_INSTALL_DO_STRIP=1
152            -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
153endif()
154