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