|
| 1 | +set(LIBUNWIND_SOURCE_DIR "${CMAKE_SOURCE_DIR}/contrib/libunwind") |
| 2 | + |
| 3 | +set(LIBUNWIND_CXX_SOURCES |
| 4 | + "${LIBUNWIND_SOURCE_DIR}/src/libunwind.cpp" |
| 5 | + "${LIBUNWIND_SOURCE_DIR}/src/Unwind-EHABI.cpp" |
| 6 | + "${LIBUNWIND_SOURCE_DIR}/src/Unwind-seh.cpp") |
| 7 | + |
| 8 | +set(LIBUNWIND_C_SOURCES |
| 9 | + "${LIBUNWIND_SOURCE_DIR}/src/UnwindLevel1.c" |
| 10 | + "${LIBUNWIND_SOURCE_DIR}/src/UnwindLevel1-gcc-ext.c" |
| 11 | + "${LIBUNWIND_SOURCE_DIR}/src/Unwind-sjlj.c" |
| 12 | + # Use unw_backtrace to override libgcc's backtrace symbol for better ABI compatibility |
| 13 | + unwind-override.c) |
| 14 | +set_source_files_properties(${LIBUNWIND_C_SOURCES} PROPERTIES COMPILE_FLAGS "-std=c99") |
| 15 | + |
| 16 | +set(LIBUNWIND_ASM_SOURCES |
| 17 | + "${LIBUNWIND_SOURCE_DIR}/src/UnwindRegistersRestore.S" |
| 18 | + "${LIBUNWIND_SOURCE_DIR}/src/UnwindRegistersSave.S") |
| 19 | + |
| 20 | +enable_language(ASM) |
| 21 | + |
| 22 | +set(LIBUNWIND_SOURCES |
| 23 | + ${LIBUNWIND_CXX_SOURCES} |
| 24 | + ${LIBUNWIND_C_SOURCES} |
| 25 | + ${LIBUNWIND_ASM_SOURCES}) |
| 26 | + |
| 27 | +add_library(unwind ${LIBUNWIND_SOURCES}) |
| 28 | +set_target_properties(unwind PROPERTIES FOLDER "contrib/libunwind-cmake") |
| 29 | + |
| 30 | +target_include_directories(unwind SYSTEM BEFORE PUBLIC $<BUILD_INTERFACE:${LIBUNWIND_SOURCE_DIR}/include>) |
| 31 | +target_compile_definitions(unwind PRIVATE -D_LIBUNWIND_NO_HEAP=1) |
| 32 | +target_compile_definitions(unwind PRIVATE -D_LIBUNWIND_REMEMBER_STACK_ALLOC=1) |
| 33 | +# NOTE: from this macros sizeof(unw_context_t)/sizeof(unw_cursor_t) is depends, so it should be set always |
| 34 | +target_compile_definitions(unwind PUBLIC -D_LIBUNWIND_IS_NATIVE_ONLY) |
| 35 | + |
| 36 | +# We should enable optimizations (otherwise it will be too slow in debug) |
| 37 | +# and disable sanitizers (otherwise infinite loop may happen) |
| 38 | +target_compile_options(unwind PRIVATE -O3 -fno-exceptions -funwind-tables -fno-sanitize=all $<$<COMPILE_LANGUAGE:CXX>:-nostdinc++ -fno-rtti>) |
| 39 | + |
| 40 | +target_compile_options(unwind PRIVATE -Wno-unused-but-set-variable) |
| 41 | + |
| 42 | +# The library is using register variables that are bound to specific registers |
| 43 | +# Example: DwarfInstructions.hpp: register unsigned long long x16 __asm("x16") = cfa; |
| 44 | +target_compile_options(unwind PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:-Wno-register>") |
| 45 | + |
| 46 | +install( |
| 47 | + TARGETS unwind |
| 48 | + EXPORT global |
| 49 | + LIBRARY DESTINATION lib |
| 50 | + ARCHIVE DESTINATION lib |
| 51 | +) |
0 commit comments