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 14if(${CMAKE_SYSTEM_NAME} MATCHES "AIX") 15 list(APPEND LIBUNWIND_CXX_SOURCES 16 Unwind_AIXExtras.cpp 17 ) 18endif() 19 20set(LIBUNWIND_C_SOURCES 21 UnwindLevel1.c 22 UnwindLevel1-gcc-ext.c 23 Unwind-sjlj.c 24 ) 25set_source_files_properties(${LIBUNWIND_C_SOURCES} 26 PROPERTIES 27 COMPILE_FLAGS "-std=c99") 28 29set(LIBUNWIND_ASM_SOURCES 30 UnwindRegistersRestore.S 31 UnwindRegistersSave.S 32 ) 33 34# See add_asm_sources() in compiler-rt for explanation of this workaround. 35# CMake doesn't work correctly with assembly on AIX. Workaround by compiling 36# as C files as well. 37if((APPLE AND CMAKE_VERSION VERSION_LESS 3.19) OR 38 (MINGW AND CMAKE_VERSION VERSION_LESS 3.17) OR 39 (${CMAKE_SYSTEM_NAME} MATCHES "AIX")) 40 set_source_files_properties(${LIBUNWIND_ASM_SOURCES} PROPERTIES LANGUAGE C) 41endif() 42 43set(LIBUNWIND_HEADERS 44 AddressSpace.hpp 45 assembly.h 46 CompactUnwinder.hpp 47 cet_unwind.h 48 config.h 49 dwarf2.h 50 DwarfInstructions.hpp 51 DwarfParser.hpp 52 EHHeaderParser.hpp 53 FrameHeaderCache.hpp 54 libunwind_ext.h 55 Registers.hpp 56 RWMutex.hpp 57 Unwind-EHABI.h 58 UnwindCursor.hpp 59 ../include/libunwind.h 60 ../include/unwind.h 61 ../include/unwind_itanium.h 62 ../include/unwind_arm_ehabi.h 63 ) 64if(APPLE) 65 list(APPEND LIBUNWIND_HEADERS 66 ../include/mach-o/compact_unwind_encoding.h 67 ) 68endif() 69 70if (MSVC_IDE) 71 # Force them all into the headers dir on MSVC, otherwise they end up at 72 # project scope because they don't have extensions. 73 source_group("Header Files" FILES ${LIBUNWIND_HEADERS}) 74endif() 75 76set(LIBUNWIND_SOURCES 77 ${LIBUNWIND_CXX_SOURCES} 78 ${LIBUNWIND_C_SOURCES} 79 ${LIBUNWIND_ASM_SOURCES}) 80 81# Generate library list. 82add_library_flags_if(LIBUNWIND_HAS_C_LIB c) 83if (LIBUNWIND_USE_COMPILER_RT) 84 add_library_flags("${LIBUNWIND_BUILTINS_LIBRARY}") 85else() 86 add_library_flags_if(LIBUNWIND_HAS_GCC_S_LIB gcc_s) 87 add_library_flags_if(LIBUNWIND_HAS_GCC_LIB gcc) 88endif() 89add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl) 90if (LIBUNWIND_ENABLE_THREADS) 91 add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread) 92 add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1) 93endif() 94 95# Setup flags. 96add_link_flags_if(CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG --unwindlib=none) 97if (CXX_SUPPORTS_NOSTDLIBXX_FLAG) 98 add_link_flags_if_supported(-nostdlib++) 99else() 100 add_link_flags_if_supported(-nodefaultlibs) 101endif() 102 103# MINGW_LIBRARIES is defined in config-ix.cmake 104add_library_flags_if(MINGW "${MINGW_LIBRARIES}") 105 106if (LIBUNWIND_ENABLE_SHARED AND 107 NOT (CXX_SUPPORTS_FNO_EXCEPTIONS_FLAG AND 108 CXX_SUPPORTS_FUNWIND_TABLES_FLAG)) 109 message(FATAL_ERROR 110 "Compiler doesn't support generation of unwind tables if exception " 111 "support is disabled. Building libunwind DSO with runtime dependency " 112 "on C++ ABI library is not supported.") 113endif() 114 115if (APPLE) 116 add_compile_flags("-U__STRICT_ANSI__") 117 add_link_flags("-compatibility_version 1" "-install_name /usr/lib/libunwind.1.dylib") 118 119 if (CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6") 120 add_link_flags("-current_version ${LIBUNWIND_VERSION}" "/usr/lib/libSystem.B.dylib") 121 endif () 122endif () 123 124string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}") 125string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}") 126string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}") 127string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}") 128 129set_property(SOURCE ${LIBUNWIND_CXX_SOURCES} 130 APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}") 131set_property(SOURCE ${LIBUNWIND_C_SOURCES} 132 APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}") 133 134# NOTE: avoid implicit dependencies on C++ runtimes. libunwind uses C++ for 135# ease, but does not rely on C++ at runtime. 136set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") 137 138# Build the shared library. 139add_library(unwind_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS}) 140if(CMAKE_C_COMPILER_ID STREQUAL MSVC) 141 target_compile_options(unwind_shared_objects PRIVATE /GR-) 142else() 143 target_compile_options(unwind_shared_objects PRIVATE -fno-rtti) 144endif() 145target_link_libraries(unwind_shared_objects PRIVATE unwind-headers ${LIBUNWIND_LIBRARIES}) 146set_target_properties(unwind_shared_objects 147 PROPERTIES 148 CXX_EXTENSIONS OFF 149 CXX_STANDARD 11 150 CXX_STANDARD_REQUIRED ON 151 COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}" 152) 153if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE) 154 set_target_properties(unwind_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library 155endif() 156 157if (LIBUNWIND_ENABLE_SHARED) 158 add_library(unwind_shared SHARED) 159 target_link_libraries(unwind_shared PUBLIC unwind_shared_objects) 160 set_target_properties(unwind_shared 161 PROPERTIES 162 LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}" 163 LINKER_LANGUAGE C 164 OUTPUT_NAME "${LIBUNWIND_SHARED_OUTPUT_NAME}" 165 VERSION "1.0" 166 SOVERSION "1" 167 ) 168 169 list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared") 170 if (LIBUNWIND_INSTALL_SHARED_LIBRARY) 171 list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared") 172 endif() 173endif() 174 175# Build the static library. 176add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS}) 177if(CMAKE_C_COMPILER_ID STREQUAL MSVC) 178 target_compile_options(unwind_static_objects PRIVATE /GR-) 179else() 180 target_compile_options(unwind_static_objects PRIVATE -fno-rtti) 181endif() 182target_link_libraries(unwind_static_objects PRIVATE unwind-headers ${LIBUNWIND_LIBRARIES}) 183set_target_properties(unwind_static_objects 184 PROPERTIES 185 CXX_EXTENSIONS OFF 186 CXX_STANDARD 11 187 CXX_STANDARD_REQUIRED ON 188 COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}" 189) 190 191if(LIBUNWIND_HIDE_SYMBOLS) 192 target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility=hidden) 193 target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility-global-new-delete-hidden) 194 target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS) 195endif() 196 197if (LIBUNWIND_ENABLE_STATIC) 198 add_library(unwind_static STATIC) 199 target_link_libraries(unwind_static PUBLIC unwind_static_objects) 200 set_target_properties(unwind_static 201 PROPERTIES 202 LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}" 203 LINKER_LANGUAGE C 204 OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}" 205 ) 206 207 list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static") 208 if (LIBUNWIND_INSTALL_STATIC_LIBRARY) 209 list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static") 210 endif() 211endif() 212 213# Add a meta-target for both libraries. 214add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS}) 215 216if (LIBUNWIND_INSTALL_LIBRARY) 217 install(TARGETS ${LIBUNWIND_INSTALL_TARGETS} 218 LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind 219 ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind 220 RUNTIME DESTINATION ${LIBUNWIND_INSTALL_RUNTIME_DIR} COMPONENT unwind) 221endif() 222 223if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY) 224 add_custom_target(install-unwind 225 DEPENDS unwind 226 COMMAND "${CMAKE_COMMAND}" 227 -DCMAKE_INSTALL_COMPONENT=unwind 228 -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake") 229 add_custom_target(install-unwind-stripped 230 DEPENDS unwind 231 COMMAND "${CMAKE_COMMAND}" 232 -DCMAKE_INSTALL_COMPONENT=unwind 233 -DCMAKE_INSTALL_DO_STRIP=1 234 -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake") 235 if(LIBUNWIND_INSTALL_HEADERS) 236 add_dependencies(install-unwind install-unwind-headers) 237 add_dependencies(install-unwind-stripped install-unwind-headers-stripped) 238 endif() 239endif() 240