From ad2371cfaec238e26a16ad406ef71eff32d9a7c3 Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 19 Jul 2016 15:40:52 +0000 Subject: [PATCH] Unix: compatibility with platforms where backtrace() is not in libc. Also, don't depend on backtrace() when built as libslvs; it is not the responsbility of the library to use it. --- CMakeLists.txt | 1 + src/CMakeLists.txt | 5 +++++ src/platform/unixutil.cpp | 2 ++ 3 files changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cdb0dc9..5dd1844 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -187,6 +187,7 @@ elseif(APPLE) find_package(Freetype REQUIRED) find_library(APPKIT_LIBRARY AppKit REQUIRED) else() # Linux and compatible systems + find_package(Backtrace) find_package(SpaceWare) # Use freedesktop's pkg-config to locate everything. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9ec43b9..4de85d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -216,6 +216,11 @@ if(SPACEWARE_FOUND) ${SPACEWARE_LIBRARIES}) endif() +if(Backtrace_FOUND) + target_link_libraries(solvespace + ${Backtrace_LIBRARIES}) +endif() + if(APPLE) foreach(lib ${platform_BUNDLED_LIBS}) get_filename_component(name ${lib} NAME) diff --git a/src/platform/unixutil.cpp b/src/platform/unixutil.cpp index 31366dd..ed0789a 100644 --- a/src/platform/unixutil.cpp +++ b/src/platform/unixutil.cpp @@ -31,6 +31,7 @@ void assert_failure(const char *file, unsigned line, const char *function, fprintf(stderr, "File %s, line %u, function %s:\n", file, line, function); fprintf(stderr, "Assertion '%s' failed: ((%s) == false).\n", message, condition); +#ifndef LIBRARY static void *ptrs[1024] = {}; size_t nptrs = backtrace(ptrs, sizeof(ptrs) / sizeof(ptrs[0])); char **syms = backtrace_symbols(ptrs, nptrs); @@ -45,6 +46,7 @@ void assert_failure(const char *file, unsigned line, const char *function, fprintf(stderr, "%2zu: %p\n", i, ptrs[i]); } } +#endif abort(); }