3 set(LIBUNWIND_CXX_SOURCES
9 if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
10 list(APPEND LIBUNWIND_CXX_SOURCES
15 set(LIBUNWIND_C_SOURCES
17 UnwindLevel1-gcc-ext.c
21 set_source_files_properties(${LIBUNWIND_C_SOURCES}
23 COMPILE_FLAGS "-std=c99")
25 set(LIBUNWIND_ASM_SOURCES
26 UnwindRegistersRestore.S
46 ../include/libunwind.h
48 ../include/unwind_itanium.h
49 ../include/unwind_arm_ehabi.h
52 list(APPEND LIBUNWIND_HEADERS
53 ../include/mach-o/compact_unwind_encoding.h
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})
64 ${LIBUNWIND_CXX_SOURCES}
65 ${LIBUNWIND_C_SOURCES}
66 ${LIBUNWIND_ASM_SOURCES})
68 # Generate library list.
69 if (LIBUNWIND_USE_COMPILER_RT)
70 add_library_flags("${LIBUNWIND_BUILTINS_LIBRARY}")
72 add_library_flags_if(LIBUNWIND_HAS_GCC_S_LIB gcc_s)
73 add_library_flags_if(LIBUNWIND_HAS_GCC_LIB gcc)
75 if (NOT APPLE) # On Apple platforms, we don't need to link explicitly against system libraries
76 add_library_flags_if(LIBUNWIND_HAS_C_LIB c)
77 add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl)
79 if (LIBUNWIND_ENABLE_THREADS)
80 add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread)
81 add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1)
85 if (LIBUNWIND_ENABLE_THREADS)
86 add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1)
90 add_link_flags_if(CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG --unwindlib=none)
92 # MINGW_LIBRARIES is defined in config-ix.cmake
93 add_library_flags_if(MINGW "${MINGW_LIBRARIES}")
95 if (LIBUNWIND_ENABLE_SHARED AND
96 NOT (CXX_SUPPORTS_FNO_EXCEPTIONS_FLAG AND
97 CXX_SUPPORTS_FUNWIND_TABLES_FLAG))
99 "Compiler doesn't support generation of unwind tables if exception "
100 "support is disabled. Building libunwind DSO with runtime dependency "
101 "on C++ ABI library is not supported.")
105 add_compile_flags("-U__STRICT_ANSI__")
106 add_link_flags("-compatibility_version 1" "-install_name /usr/lib/libunwind.1.dylib")
108 if (CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6")
109 add_link_flags("-current_version ${LIBUNWIND_VERSION}" "/usr/lib/libSystem.B.dylib")
114 add_library_flags_if(LIBUNWIND_HAS_ROOT_LIB root)
116 add_library_flags_if(LIBUNWIND_HAS_BSD_LIB bsd)
117 add_compile_flags_if(LIBUNWIND_HAS_BSD_LIB -D_LIBUNWIND_USE_HAIKU_BSD_LIB=1)
119 add_compile_flags("-D_DEFAULT_SOURCE")
120 add_compile_flags("-DPT_GNU_EH_FRAME=PT_EH_FRAME")
123 string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
124 string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
125 string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
126 string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
128 set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
129 APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}")
130 set_property(SOURCE ${LIBUNWIND_C_SOURCES}
131 APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}")
133 # NOTE: avoid implicit dependencies on C++ runtimes. libunwind uses C++ for
134 # ease, but does not rely on C++ at runtime.
135 set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
137 include(WarningFlags)
139 # Build the shared library.
140 add_library(unwind_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
141 cxx_add_warning_flags(unwind_shared_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})
142 if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
143 target_compile_options(unwind_shared_objects PRIVATE /GR-)
145 target_compile_options(unwind_shared_objects PRIVATE -fno-rtti)
147 target_link_libraries(unwind_shared_objects PRIVATE unwind-headers ${LIBUNWIND_LIBRARIES})
148 target_compile_options(unwind_shared_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}")
149 target_link_libraries(unwind_shared_objects PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}")
150 set_target_properties(unwind_shared_objects
154 CXX_STANDARD_REQUIRED ON
155 COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
157 if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
158 set_target_properties(unwind_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
161 if (LIBUNWIND_ENABLE_SHARED)
162 add_library(unwind_shared SHARED)
163 target_link_libraries(unwind_shared PUBLIC unwind_shared_objects)
164 set_target_properties(unwind_shared
166 LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
168 OUTPUT_NAME "${LIBUNWIND_SHARED_OUTPUT_NAME}"
173 list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
174 if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
175 list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
179 # Build the static library.
180 add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
181 cxx_add_warning_flags(unwind_static_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})
182 if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
183 target_compile_options(unwind_static_objects PRIVATE /GR-)
185 target_compile_options(unwind_static_objects PRIVATE -fno-rtti)
187 target_link_libraries(unwind_static_objects PRIVATE unwind-headers ${LIBUNWIND_LIBRARIES})
188 target_compile_options(unwind_static_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}")
189 target_link_libraries(unwind_static_objects PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}")
190 set_target_properties(unwind_static_objects
194 CXX_STANDARD_REQUIRED ON
195 COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
198 if(LIBUNWIND_HIDE_SYMBOLS)
199 target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility=hidden)
200 target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility-global-new-delete-hidden)
201 target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
204 if (LIBUNWIND_ENABLE_STATIC)
205 add_library(unwind_static STATIC)
206 target_link_libraries(unwind_static PUBLIC unwind_static_objects)
207 set_target_properties(unwind_static
209 LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
211 OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
214 list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
215 if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
216 list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
220 # Add a meta-target for both libraries.
221 add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS})
223 if (LIBUNWIND_INSTALL_LIBRARY)
224 install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}
225 LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
226 ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
227 RUNTIME DESTINATION ${LIBUNWIND_INSTALL_RUNTIME_DIR} COMPONENT unwind)
230 if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
231 add_custom_target(install-unwind
233 COMMAND "${CMAKE_COMMAND}"
234 -DCMAKE_INSTALL_COMPONENT=unwind
235 -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
236 add_custom_target(install-unwind-stripped
238 COMMAND "${CMAKE_COMMAND}"
239 -DCMAKE_INSTALL_COMPONENT=unwind
240 -DCMAKE_INSTALL_DO_STRIP=1
241 -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
242 if(LIBUNWIND_INSTALL_HEADERS)
243 add_dependencies(install-unwind install-unwind-headers)
244 add_dependencies(install-unwind-stripped install-unwind-headers-stripped)