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
20 set_source_files_properties(${LIBUNWIND_C_SOURCES}
22 COMPILE_FLAGS "-std=c99")
24 set(LIBUNWIND_ASM_SOURCES
25 UnwindRegistersRestore.S
45 ../include/libunwind.h
47 ../include/unwind_itanium.h
48 ../include/unwind_arm_ehabi.h
51 list(APPEND LIBUNWIND_HEADERS
52 ../include/mach-o/compact_unwind_encoding.h
57 # Force them all into the headers dir on MSVC, otherwise they end up at
58 # project scope because they don't have extensions.
59 source_group("Header Files" FILES ${LIBUNWIND_HEADERS})
63 ${LIBUNWIND_CXX_SOURCES}
64 ${LIBUNWIND_C_SOURCES}
65 ${LIBUNWIND_ASM_SOURCES})
67 # Generate library list.
68 add_library_flags_if(LIBUNWIND_HAS_C_LIB c)
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 add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl)
76 if (LIBUNWIND_ENABLE_THREADS)
77 add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread)
78 add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1)
82 add_link_flags_if(CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG --unwindlib=none)
84 # MINGW_LIBRARIES is defined in config-ix.cmake
85 add_library_flags_if(MINGW "${MINGW_LIBRARIES}")
87 if (LIBUNWIND_ENABLE_SHARED AND
88 NOT (CXX_SUPPORTS_FNO_EXCEPTIONS_FLAG AND
89 CXX_SUPPORTS_FUNWIND_TABLES_FLAG))
91 "Compiler doesn't support generation of unwind tables if exception "
92 "support is disabled. Building libunwind DSO with runtime dependency "
93 "on C++ ABI library is not supported.")
97 add_compile_flags("-U__STRICT_ANSI__")
98 add_link_flags("-compatibility_version 1" "-install_name /usr/lib/libunwind.1.dylib")
100 if (CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6")
101 add_link_flags("-current_version ${LIBUNWIND_VERSION}" "/usr/lib/libSystem.B.dylib")
106 add_library_flags_if(LIBUNWIND_HAS_ROOT_LIB root)
108 add_library_flags_if(LIBUNWIND_HAS_BSD_LIB bsd)
109 add_compile_flags_if(LIBUNWIND_HAS_BSD_LIB -D_LIBUNWIND_USE_HAIKU_BSD_LIB=1)
111 add_compile_flags("-D_DEFAULT_SOURCE")
112 add_compile_flags("-DPT_GNU_EH_FRAME=PT_EH_FRAME")
115 string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
116 string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
117 string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
118 string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
120 set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
121 APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}")
122 set_property(SOURCE ${LIBUNWIND_C_SOURCES}
123 APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}")
125 # NOTE: avoid implicit dependencies on C++ runtimes. libunwind uses C++ for
126 # ease, but does not rely on C++ at runtime.
127 set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
129 include(WarningFlags)
131 # Build the shared library.
132 add_library(unwind_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
133 cxx_add_warning_flags(unwind_shared_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})
134 if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
135 target_compile_options(unwind_shared_objects PRIVATE /GR-)
137 target_compile_options(unwind_shared_objects PRIVATE -fno-rtti)
139 target_link_libraries(unwind_shared_objects PRIVATE unwind-headers ${LIBUNWIND_LIBRARIES})
140 target_compile_options(unwind_shared_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}")
141 target_link_libraries(unwind_shared_objects PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}")
142 set_target_properties(unwind_shared_objects
146 CXX_STANDARD_REQUIRED ON
147 COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
149 if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
150 set_target_properties(unwind_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
153 if (LIBUNWIND_ENABLE_SHARED)
154 add_library(unwind_shared SHARED)
155 target_link_libraries(unwind_shared PUBLIC unwind_shared_objects)
156 set_target_properties(unwind_shared
158 LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
160 OUTPUT_NAME "${LIBUNWIND_SHARED_OUTPUT_NAME}"
165 list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
166 if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
167 list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
171 # Build the static library.
172 add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
173 cxx_add_warning_flags(unwind_static_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})
174 if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
175 target_compile_options(unwind_static_objects PRIVATE /GR-)
177 target_compile_options(unwind_static_objects PRIVATE -fno-rtti)
179 target_link_libraries(unwind_static_objects PRIVATE unwind-headers ${LIBUNWIND_LIBRARIES})
180 target_compile_options(unwind_static_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}")
181 target_link_libraries(unwind_static_objects PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}")
182 set_target_properties(unwind_static_objects
186 CXX_STANDARD_REQUIRED ON
187 COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
190 if(LIBUNWIND_HIDE_SYMBOLS)
191 target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility=hidden)
192 target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility-global-new-delete-hidden)
193 target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
196 if (LIBUNWIND_ENABLE_STATIC)
197 add_library(unwind_static STATIC)
198 target_link_libraries(unwind_static PUBLIC unwind_static_objects)
199 set_target_properties(unwind_static
201 LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
203 OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
206 list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
207 if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
208 list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
212 # Add a meta-target for both libraries.
213 add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS})
215 if (LIBUNWIND_INSTALL_LIBRARY)
216 install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}
217 LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
218 ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
219 RUNTIME DESTINATION ${LIBUNWIND_INSTALL_RUNTIME_DIR} COMPONENT unwind)
222 if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
223 add_custom_target(install-unwind
225 COMMAND "${CMAKE_COMMAND}"
226 -DCMAKE_INSTALL_COMPONENT=unwind
227 -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
228 add_custom_target(install-unwind-stripped
230 COMMAND "${CMAKE_COMMAND}"
231 -DCMAKE_INSTALL_COMPONENT=unwind
232 -DCMAKE_INSTALL_DO_STRIP=1
233 -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
234 if(LIBUNWIND_INSTALL_HEADERS)
235 add_dependencies(install-unwind install-unwind-headers)
236 add_dependencies(install-unwind-stripped install-unwind-headers-stripped)