build: support build with libunwind on osx (#162)

macOS provides a libunwind in SDK, so we can skip the library search
process.

---------

Co-authored-by: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com>
This commit is contained in:
lzw 2024-08-31 07:15:38 +08:00 committed by GitHub
parent 231960d472
commit f671819510
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -523,26 +523,28 @@ if(CPPTRACE_UNWIND_WITH_LIBUNWIND)
endif()
endif()
if(NOT libunwind_FOUND)
# set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
# set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS ON)
find_path(LIBUNWIND_INCLUDE_DIRS NAMES "libunwind.h")
find_library(LIBUNWIND NAMES unwind libunwind libunwind8 libunwind.so.8 REQUIRED PATHS "/usr/lib/x86_64-linux-gnu/")
if(LIBUNWIND)
set(libunwind_FOUND TRUE)
if (NOT APPLE)
# set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
# set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS ON)
find_path(LIBUNWIND_INCLUDE_DIRS NAMES "libunwind.h")
find_library(LIBUNWIND NAMES unwind libunwind libunwind8 libunwind.so.8 REQUIRED PATHS "/usr/lib/x86_64-linux-gnu/")
if(LIBUNWIND)
set(libunwind_FOUND TRUE)
endif()
if(NOT libunwind_FOUND)
# message(FATAL_ERROR "Unable to locate libunwind")
# Try to link with it if it's where it should be
# This path can be entered if libunwind was installed via the system package manager, sometimes. I probably messed
# up the find_library above.
set(LIBUNWIND_LDFLAGS "-lunwind")
endif()
if(NOT LIBUNWIND_LDFLAGS)
set(LIBUNWIND_LDFLAGS "${LIBUNWIND}")
endif()
target_compile_options(${target_name} PRIVATE ${LIBUNWIND_CFLAGS_OTHER})
target_include_directories(${target_name} PRIVATE ${LIBUNWIND_INCLUDE_DIRS})
target_link_libraries(${target_name} PRIVATE ${LIBUNWIND_LDFLAGS})
endif()
if(NOT libunwind_FOUND)
# message(FATAL_ERROR "Unable to locate libunwind")
# Try to link with it if it's where it should be
# This path can be entered if libunwind was installed via the system package manager, sometimes. I probably messed
# up the find_library above.
set(LIBUNWIND_LDFLAGS "-lunwind")
endif()
if(NOT LIBUNWIND_LDFLAGS)
set(LIBUNWIND_LDFLAGS "${LIBUNWIND}")
endif()
target_compile_options(${target_name} PRIVATE ${LIBUNWIND_CFLAGS_OTHER})
target_include_directories(${target_name} PRIVATE ${LIBUNWIND_INCLUDE_DIRS})
target_link_libraries(${target_name} PRIVATE ${LIBUNWIND_LDFLAGS})
target_compile_definitions(${target_name} PUBLIC CPPTRACE_UNWIND_WITH_LIBUNWIND UNW_LOCAL_ONLY)
endif()
endif()