• 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
7    )
8if(APPLE)
9  list(APPEND LIBUNWIND_CXX_SOURCES
10    Unwind_AppleExtras.cpp
11    )
12endif()
13
14set(LIBUNWIND_C_SOURCES
15    UnwindLevel1.c
16    UnwindLevel1-gcc-ext.c
17    Unwind-sjlj.c
18    )
19set_source_files_properties(${LIBUNWIND_C_SOURCES}
20                            PROPERTIES
21                              COMPILE_FLAGS "-std=c99")
22
23set(LIBUNWIND_ASM_SOURCES
24    UnwindRegistersRestore.S
25    UnwindRegistersSave.S
26    )
27
28# See add_asm_sources() in compiler-rt for explanation of this workaround.
29if((APPLE AND CMAKE_VERSION VERSION_LESS 3.19) OR (MINGW AND CMAKE_VERSION VERSION_LESS 3.17))
30  set_source_files_properties(${LIBUNWIND_ASM_SOURCES} PROPERTIES LANGUAGE C)
31endif()
32
33set(LIBUNWIND_HEADERS
34    AddressSpace.hpp
35    assembly.h
36    CompactUnwinder.hpp
37    config.h
38    dwarf2.h
39    DwarfInstructions.hpp
40    DwarfParser.hpp
41    EHHeaderParser.hpp
42    FrameHeaderCache.hpp
43    libunwind_ext.h
44    Registers.hpp
45    RWMutex.hpp
46    Unwind-EHABI.h
47    UnwindCursor.hpp
48    ../include/libunwind.h
49    ../include/unwind.h
50    )
51if(APPLE)
52  list(APPEND LIBUNWIND_HEADERS
53    ../include/mach-o/compact_unwind_encoding.h
54    )
55endif()
56
57if (MSVC_IDE)
58  # Force them all into the headers dir on MSVC, otherwise they end up at
59  # project scope because they don't have extensions.
60  source_group("Header Files" FILES ${LIBUNWIND_HEADERS})
61endif()
62
63set(LIBUNWIND_SOURCES
64    ${LIBUNWIND_CXX_SOURCES}
65    ${LIBUNWIND_C_SOURCES}
66    ${LIBUNWIND_ASM_SOURCES})
67
68# Generate library list.
69add_library_flags_if(LIBUNWIND_HAS_C_LIB c)
70if (LIBUNWIND_USE_COMPILER_RT)
71  add_library_flags("${LIBUNWIND_BUILTINS_LIBRARY}")
72else()
73  add_library_flags_if(LIBUNWIND_HAS_GCC_S_LIB gcc_s)
74  add_library_flags_if(LIBUNWIND_HAS_GCC_LIB gcc)
75endif()
76add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl)
77if (LIBUNWIND_ENABLE_THREADS)
78  add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread)
79  add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1)
80endif()
81
82# Setup flags.
83add_link_flags_if_supported(-nodefaultlibs)
84
85# MINGW_LIBRARIES is defined in config-ix.cmake
86add_library_flags_if(MINGW "${MINGW_LIBRARIES}")
87
88if (LIBUNWIND_ENABLE_SHARED AND
89    NOT (LIBUNWIND_SUPPORTS_FNO_EXCEPTIONS_FLAG AND
90         LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG))
91  message(FATAL_ERROR
92          "Compiler doesn't support generation of unwind tables if exception "
93          "support is disabled.  Building libunwind DSO with runtime dependency "
94          "on C++ ABI library is not supported.")
95endif()
96
97if (APPLE)
98  add_compile_flags("-U__STRICT_ANSI__")
99  add_link_flags("-compatibility_version 1" "-install_name /usr/lib/libunwind.1.dylib")
100
101  if (CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6")
102    add_link_flags("-current_version ${LIBUNWIND_VERSION}" "/usr/lib/libSystem.B.dylib")
103  endif ()
104endif ()
105
106string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
107string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
108string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
109string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
110
111set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
112             APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}")
113set_property(SOURCE ${LIBUNWIND_C_SOURCES}
114             APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}")
115
116# NOTE: avoid implicit dependencies on C++ runtimes.  libunwind uses C++ for
117# ease, but does not rely on C++ at runtime.
118set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
119
120# Build the shared library.
121if (LIBUNWIND_ENABLE_SHARED)
122  add_library(unwind_shared SHARED ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
123  if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
124    target_compile_options(unwind_shared PRIVATE /GR-)
125  else()
126    target_compile_options(unwind_shared PRIVATE -fno-rtti)
127  endif()
128  target_link_libraries(unwind_shared PRIVATE ${LIBUNWIND_LIBRARIES})
129  set_target_properties(unwind_shared PROPERTIES
130    CXX_EXTENSIONS OFF
131    CXX_STANDARD 11
132    CXX_STANDARD_REQUIRED ON
133    COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
134    LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
135    LINKER_LANGUAGE C
136    OUTPUT_NAME "unwind"
137    VERSION "1.0"
138    SOVERSION "1")
139  list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
140  if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
141    list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
142  endif()
143endif()
144
145# Build the static library.
146if (LIBUNWIND_ENABLE_STATIC)
147  add_library(unwind_static STATIC ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
148  if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
149    target_compile_options(unwind_static PRIVATE /GR-)
150  else()
151    target_compile_options(unwind_static PRIVATE -fno-rtti)
152  endif()
153  target_link_libraries(unwind_static PRIVATE ${LIBUNWIND_LIBRARIES})
154  set_target_properties(unwind_static PROPERTIES
155    CXX_EXTENSIONS OFF
156    CXX_STANDARD 11
157    CXX_STANDARD_REQUIRED ON
158    COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
159    LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
160    LINKER_LANGUAGE C
161    OUTPUT_NAME "unwind")
162
163  if(LIBUNWIND_HERMETIC_STATIC_LIBRARY)
164    append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility=hidden)
165    append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden)
166    target_compile_options(unwind_static PRIVATE ${UNWIND_STATIC_LIBRARY_FLAGS})
167    target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
168  endif()
169
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}${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
182    ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}${LIBUNWIND_INSTALL_LIBRARY_DIR} 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