From 6dae830ea0bff809a747cd3767371f219981b781 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sat, 16 May 2020 12:45:51 +0100 Subject: [PATCH] Use cmake to find backtrace() (#187) On FreeBSD, this notably requires the use of -lexecinfo, as backtrace() is not available in -lc. Rather than testing in C, test in cmake. --- CMakeLists.txt | 8 ++++++++ src/pal/pal_posix.h | 7 +++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a2896dd..221086d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,6 +176,14 @@ if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY) add_compile_options(-march=native) endif() endif() + + find_package(Backtrace) + if(${Backtrace_FOUND}) + target_compile_definitions(snmalloc_lib INTERFACE -DBACKTRACE_HEADER="${Backtrace_HEADER}") + target_link_libraries(snmalloc_lib INTERFACE ${Backtrace_LIBRARIES}) + target_include_directories(snmalloc_lib INTERFACE ${Backtrace_INCLUD_DIRS}) + endif() + endif() macro(subdirlist result curdir) diff --git a/src/pal/pal_posix.h b/src/pal/pal_posix.h index 0f7eb85..260bd3d 100644 --- a/src/pal/pal_posix.h +++ b/src/pal/pal_posix.h @@ -2,9 +2,8 @@ #include "../ds/address.h" #include "../mem/allocconfig.h" -#if __has_include() -# define SNMALLOC_HAS_BACKTRACE 1 -# include +#if defined(BACKTRACE_HEADER) +# include BACKTRACE_HEADER #endif #include #include @@ -42,7 +41,7 @@ namespace snmalloc static void print_stack_trace() { -#ifdef SNMALLOC_HAS_BACKTRACE +#ifdef BACKTRACE_HEADER constexpr int SIZE = 1024; void* buffer[SIZE]; auto nptrs = backtrace(buffer, SIZE);