brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.2 KiB · 514c2fc Raw
242 lines · plain
1# Get sources2 3set(LIBUNWIND_CXX_SOURCES4    libunwind.cpp5    Unwind-EHABI.cpp6    Unwind-seh.cpp7    )8 9if("${CMAKE_SYSTEM_NAME}" MATCHES "AIX")10  list(APPEND LIBUNWIND_CXX_SOURCES11    Unwind_AIXExtras.cpp12    )13endif()14 15set(LIBUNWIND_C_SOURCES16    UnwindLevel1.c17    UnwindLevel1-gcc-ext.c18    Unwind-sjlj.c19    Unwind-wasm.c20    )21set_source_files_properties(${LIBUNWIND_C_SOURCES}22                            PROPERTIES23                              # We need to set `-fexceptions` here so that key24                              # unwinding functions, like25                              # _UNWIND_RaiseException, are not marked as26                              # `nounwind`, which breaks LTO builds of27                              # libunwind.  See #56825 and #120657 for context.28                              COMPILE_FLAGS "-std=c99 -fexceptions")29 30set(LIBUNWIND_ASM_SOURCES31    UnwindRegistersRestore.S32    UnwindRegistersSave.S33    )34 35set(LIBUNWIND_HEADERS36    AddressSpace.hpp37    assembly.h38    CompactUnwinder.hpp39    config.h40    dwarf2.h41    DwarfInstructions.hpp42    DwarfParser.hpp43    EHHeaderParser.hpp44    FrameHeaderCache.hpp45    libunwind_ext.h46    Registers.hpp47    RWMutex.hpp48    shadow_stack_unwind.h49    Unwind-EHABI.h50    UnwindCursor.hpp51    ../include/libunwind.h52    ../include/unwind.h53    ../include/unwind_itanium.h54    ../include/unwind_arm_ehabi.h55    )56if(APPLE)57  list(APPEND LIBUNWIND_HEADERS58    ../include/mach-o/compact_unwind_encoding.h59    )60endif()61 62if (MSVC_IDE)63  # Force them all into the headers dir on MSVC, otherwise they end up at64  # project scope because they don't have extensions.65  source_group("Header Files" FILES ${LIBUNWIND_HEADERS})66endif()67 68set(LIBUNWIND_SOURCES69    ${LIBUNWIND_CXX_SOURCES}70    ${LIBUNWIND_C_SOURCES}71    ${LIBUNWIND_ASM_SOURCES})72 73# Generate library list.74if (NOT APPLE)75  add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl)76endif()77 78if (LIBUNWIND_ENABLE_THREADS AND NOT APPLE)79    add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread)80endif()81 82if (LIBUNWIND_ENABLE_THREADS)83  add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1)84endif()85 86# Setup flags.87add_link_flags_if(CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG --unwindlib=none)88 89# MINGW_LIBRARIES is defined in config-ix.cmake90add_library_flags_if(MINGW "${MINGW_LIBRARIES}")91 92if (LIBUNWIND_ENABLE_SHARED AND93    NOT (CXX_SUPPORTS_FNO_EXCEPTIONS_FLAG AND94         CXX_SUPPORTS_FUNWIND_TABLES_FLAG))95  message(FATAL_ERROR96          "Compiler doesn't support generation of unwind tables if exception "97          "support is disabled.  Building libunwind DSO with runtime dependency "98          "on C++ ABI library is not supported.")99endif()100 101if (HAIKU)102  add_library_flags_if(LIBUNWIND_HAS_ROOT_LIB root)103 104  add_library_flags_if(LIBUNWIND_HAS_BSD_LIB bsd)105  add_compile_flags_if(LIBUNWIND_HAS_BSD_LIB -D_LIBUNWIND_USE_HAIKU_BSD_LIB=1)106 107  add_compile_flags("-D_DEFAULT_SOURCE")108  add_compile_flags("-DPT_GNU_EH_FRAME=PT_EH_FRAME")109endif ()110 111string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")112string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")113string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")114string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")115 116set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}117             APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}")118set_property(SOURCE ${LIBUNWIND_C_SOURCES}119             APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}")120 121# NOTE: avoid implicit dependencies on C++ runtimes.  libunwind uses C++ for122# ease, but does not rely on C++ at runtime.123set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")124 125include(WarningFlags)126 127# Build the shared library.128add_library(unwind_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})129cxx_add_warning_flags(unwind_shared_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})130if(CMAKE_C_COMPILER_ID STREQUAL MSVC)131  target_compile_options(unwind_shared_objects PRIVATE /GR-)132else()133  target_compile_options(unwind_shared_objects PRIVATE -fno-rtti)134endif()135target_compile_options(unwind_shared_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}")136target_link_libraries(unwind_shared_objects137  PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}"138  PRIVATE unwind-headers runtimes-libc-headers ${LIBUNWIND_LIBRARIES})139set_target_properties(unwind_shared_objects140  PROPERTIES141    CXX_EXTENSIONS OFF142    CXX_STANDARD 17143    CXX_STANDARD_REQUIRED ON144    COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"145)146if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)147  set_target_properties(unwind_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library148endif()149 150add_library(unwind_shared SHARED)151target_link_libraries(unwind_shared PUBLIC unwind_shared_objects runtimes-libc-shared)152set_target_properties(unwind_shared153  PROPERTIES154    EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBUNWIND_ENABLE_SHARED}>,FALSE,TRUE>"155    LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"156    LINKER_LANGUAGE C157    OUTPUT_NAME "${LIBUNWIND_SHARED_OUTPUT_NAME}"158    VERSION     "${LIBUNWIND_LIBRARY_VERSION}"159    SOVERSION   "1"160)161 162if (LIBUNWIND_ENABLE_SHARED)163  list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")164endif()165if (LIBUNWIND_INSTALL_SHARED_LIBRARY)166  list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")167endif()168 169# Build the static library.170add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})171cxx_add_warning_flags(unwind_static_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})172if(CMAKE_C_COMPILER_ID STREQUAL MSVC)173  target_compile_options(unwind_static_objects PRIVATE /GR-)174else()175  target_compile_options(unwind_static_objects PRIVATE -fno-rtti)176endif()177target_compile_options(unwind_static_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}")178target_link_libraries(unwind_static_objects179  PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}"180  PRIVATE unwind-headers runtimes-libc-headers ${LIBUNWIND_LIBRARIES})181set_target_properties(unwind_static_objects182  PROPERTIES183    CXX_EXTENSIONS OFF184    CXX_STANDARD 17185    CXX_STANDARD_REQUIRED ON186    COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"187)188 189if(LIBUNWIND_HIDE_SYMBOLS)190  target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility=hidden)191  target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility-global-new-delete=force-hidden)192  if (NOT CXX_SUPPORTS_FVISIBILITY_GLOBAL_NEW_DELETE_EQ_FORCE_HIDDEN_FLAG)193    target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility-global-new-delete-hidden)194  endif()195  target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS)196endif()197 198add_library(unwind_static STATIC)199target_link_libraries(unwind_static PUBLIC unwind_static_objects runtimes-libc-static)200set_target_properties(unwind_static201  PROPERTIES202    EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBUNWIND_ENABLE_STATIC}>,FALSE,TRUE>"203    LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"204    LINKER_LANGUAGE C205    OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"206)207 208if (LIBUNWIND_ENABLE_STATIC)209  list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")210endif()211if (LIBUNWIND_INSTALL_STATIC_LIBRARY)212  list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")213endif()214 215# Add a meta-target for both libraries.216add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS})217 218if (LIBUNWIND_INSTALL_LIBRARY)219  install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}220    LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind221    ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind222    RUNTIME DESTINATION ${LIBUNWIND_INSTALL_RUNTIME_DIR} COMPONENT unwind)223endif()224 225if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)226  add_custom_target(install-unwind227    DEPENDS unwind228    COMMAND "${CMAKE_COMMAND}"229            -DCMAKE_INSTALL_COMPONENT=unwind230            -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")231  add_custom_target(install-unwind-stripped232    DEPENDS unwind233    COMMAND "${CMAKE_COMMAND}"234            -DCMAKE_INSTALL_COMPONENT=unwind235            -DCMAKE_INSTALL_DO_STRIP=1236            -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")237  if(LIBUNWIND_INSTALL_HEADERS)238    add_dependencies(install-unwind install-unwind-headers)239    add_dependencies(install-unwind-stripped install-unwind-headers-stripped)240  endif()241endif()242