3 set(LIBUNWIND_CXX_SOURCES
9 list(APPEND LIBUNWIND_CXX_SOURCES
10 Unwind_AppleExtras.cpp
14 set(LIBUNWIND_C_SOURCES
16 UnwindLevel1-gcc-ext.c
19 set_source_files_properties(${LIBUNWIND_C_SOURCES}
21 COMPILE_FLAGS "-std=c99")
23 set(LIBUNWIND_ASM_SOURCES
24 UnwindRegistersRestore.S
28 # See add_asm_sources() in compiler-rt for explanation of this workaround.
29 if((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)
49 ../include/libunwind.h
51 ../include/unwind_itanium.h
52 ../include/unwind_arm_ehabi.h
55 list(APPEND LIBUNWIND_HEADERS
56 ../include/mach-o/compact_unwind_encoding.h
61 # Force them all into the headers dir on MSVC, otherwise they end up at
62 # project scope because they don't have extensions.
63 source_group("Header Files" FILES ${LIBUNWIND_HEADERS})
67 ${LIBUNWIND_CXX_SOURCES}
68 ${LIBUNWIND_C_SOURCES}
69 ${LIBUNWIND_ASM_SOURCES})
71 # Generate library list.
72 add_library_flags_if(LIBUNWIND_HAS_C_LIB c)
73 if (LIBUNWIND_USE_COMPILER_RT)
74 add_library_flags("${LIBUNWIND_BUILTINS_LIBRARY}")
76 add_library_flags_if(LIBUNWIND_HAS_GCC_S_LIB gcc_s)
77 add_library_flags_if(LIBUNWIND_HAS_GCC_LIB gcc)
79 add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl)
80 if (LIBUNWIND_ENABLE_THREADS)
81 add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread)
82 add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1)
86 if (LIBUNWIND_SUPPORTS_NOSTDLIBXX_FLAG)
87 add_link_flags_if_supported(-nostdlib++)
89 add_link_flags_if_supported(-nodefaultlibs)
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 (LIBUNWIND_SUPPORTS_FNO_EXCEPTIONS_FLAG AND
97 LIBUNWIND_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")
113 string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
114 string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
115 string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
116 string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
118 set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
119 APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}")
120 set_property(SOURCE ${LIBUNWIND_C_SOURCES}
121 APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}")
123 # NOTE: avoid implicit dependencies on C++ runtimes. libunwind uses C++ for
124 # ease, but does not rely on C++ at runtime.
125 set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
127 # Build the shared library.
128 if (LIBUNWIND_ENABLE_SHARED)
129 add_library(unwind_shared SHARED ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
130 if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
131 target_compile_options(unwind_shared PRIVATE /GR-)
133 target_compile_options(unwind_shared PRIVATE -fno-rtti)
135 target_link_libraries(unwind_shared PRIVATE ${LIBUNWIND_LIBRARIES})
136 set_target_properties(unwind_shared
140 CXX_STANDARD_REQUIRED ON
141 COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
142 LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
147 POSITION_INDEPENDENT_CODE ON
149 list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
150 if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
151 list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
155 # Build the static library.
156 if (LIBUNWIND_ENABLE_STATIC)
157 add_library(unwind_static STATIC ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
158 if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
159 target_compile_options(unwind_static PRIVATE /GR-)
161 target_compile_options(unwind_static PRIVATE -fno-rtti)
163 target_link_libraries(unwind_static PRIVATE ${LIBUNWIND_LIBRARIES})
164 set_target_properties(unwind_static
168 CXX_STANDARD_REQUIRED ON
169 COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
170 LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
173 POSITION_INDEPENDENT_CODE ON
176 if(LIBUNWIND_HIDE_SYMBOLS)
177 append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility=hidden)
178 append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden)
179 target_compile_options(unwind_static PRIVATE ${UNWIND_STATIC_LIBRARY_FLAGS})
180 target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
183 list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
184 if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
185 list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
189 # Add a meta-target for both libraries.
190 add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS})
192 if (LIBUNWIND_INSTALL_LIBRARY)
193 install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}
194 LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
195 ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
196 RUNTIME DESTINATION ${LIBUNWIND_INSTALL_RUNTIME_DIR} COMPONENT unwind)
199 if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
200 add_custom_target(install-unwind
202 COMMAND "${CMAKE_COMMAND}"
203 -DCMAKE_INSTALL_COMPONENT=unwind
204 -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
205 add_custom_target(install-unwind-stripped
207 COMMAND "${CMAKE_COMMAND}"
208 -DCMAKE_INSTALL_COMPONENT=unwind
209 -DCMAKE_INSTALL_DO_STRIP=1
210 -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")