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
27 set_source_files_properties(${LIBUNWIND_ASM_SOURCES}
43 ../include/libunwind.h
47 list(APPEND LIBUNWIND_HEADERS
48 ../include/mach-o/compact_unwind_encoding.h
53 # Force them all into the headers dir on MSVC, otherwise they end up at
54 # project scope because they don't have extensions.
55 source_group("Header Files" FILES ${LIBUNWIND_HEADERS})
59 ${LIBUNWIND_CXX_SOURCES}
60 ${LIBUNWIND_C_SOURCES}
61 ${LIBUNWIND_ASM_SOURCES})
63 # Generate library list.
64 add_library_flags_if(LIBUNWIND_HAS_C_LIB c)
65 if (LIBUNWIND_USE_COMPILER_RT)
66 add_library_flags("${LIBUNWIND_BUILTINS_LIBRARY}")
68 add_library_flags_if(LIBUNWIND_HAS_GCC_S_LIB gcc_s)
69 add_library_flags_if(LIBUNWIND_HAS_GCC_LIB gcc)
71 add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl)
72 if (LIBUNWIND_ENABLE_THREADS)
73 add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread)
74 add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1)
78 add_link_flags_if_supported(-nodefaultlibs)
80 # MINGW_LIBRARIES is defined in config-ix.cmake
81 add_library_flags_if(MINGW "${MINGW_LIBRARIES}")
83 if (LIBUNWIND_ENABLE_SHARED AND
84 NOT (LIBUNWIND_SUPPORTS_FNO_EXCEPTIONS_FLAG AND
85 LIBUNWIND_SUPPORTS_FUNWIND_TABLES_FLAG))
87 "Compiler doesn't support generation of unwind tables if exception "
88 "support is disabled. Building libunwind DSO with runtime dependency "
89 "on C++ ABI library is not supported.")
93 add_compile_flags("-U__STRICT_ANSI__")
94 add_link_flags("-compatibility_version 1" "-install_name /usr/lib/libunwind.1.dylib")
96 if (CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6")
97 add_link_flags("-current_version ${LIBUNWIND_VERSION}" "/usr/lib/libSystem.B.dylib")
101 string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
102 string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
103 string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
104 string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
106 set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
107 APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}")
108 set_property(SOURCE ${LIBUNWIND_C_SOURCES}
109 APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}")
111 # NOTE: avoid implicit dependencies on C++ runtimes. libunwind uses C++ for
112 # ease, but does not rely on C++ at runtime.
113 set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
115 # Build the shared library.
116 if (LIBUNWIND_ENABLE_SHARED)
117 add_library(unwind_shared SHARED ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
118 if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
119 target_compile_options(unwind_shared PRIVATE /GR-)
121 target_compile_options(unwind_shared PRIVATE -fno-rtti)
123 if(COMMAND llvm_setup_rpath)
124 llvm_setup_rpath(unwind_shared)
126 target_link_libraries(unwind_shared PRIVATE ${LIBUNWIND_LIBRARIES})
127 set_target_properties(unwind_shared PROPERTIES
130 CXX_STANDARD_REQUIRED ON
131 COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
132 LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
137 list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
138 if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
139 list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
143 # Build the static library.
144 if (LIBUNWIND_ENABLE_STATIC)
145 add_library(unwind_static STATIC ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
146 if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
147 target_compile_options(unwind_static PRIVATE /GR-)
149 target_compile_options(unwind_static PRIVATE -fno-rtti)
151 target_link_libraries(unwind_static PRIVATE ${LIBUNWIND_LIBRARIES})
152 set_target_properties(unwind_static PROPERTIES
155 CXX_STANDARD_REQUIRED ON
156 COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
157 LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
159 OUTPUT_NAME "unwind")
161 if(LIBUNWIND_HERMETIC_STATIC_LIBRARY)
162 append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility=hidden)
163 append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden)
164 target_compile_options(unwind_static PRIVATE ${UNWIND_STATIC_LIBRARY_FLAGS})
165 target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
168 list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
169 if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
170 list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
174 # Add a meta-target for both libraries.
175 add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS})
177 if (LIBUNWIND_INSTALL_LIBRARY)
178 install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}
179 LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
180 ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind)
183 if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
184 add_custom_target(install-unwind
186 COMMAND "${CMAKE_COMMAND}"
187 -DCMAKE_INSTALL_COMPONENT=unwind
188 -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
189 add_custom_target(install-unwind-stripped
191 COMMAND "${CMAKE_COMMAND}"
192 -DCMAKE_INSTALL_COMPONENT=unwind
193 -DCMAKE_INSTALL_DO_STRIP=1
194 -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")