diff --git a/awesomeConfig.cmake b/awesomeConfig.cmake index 25cf6cdb..621c431d 100644 --- a/awesomeConfig.cmake +++ b/awesomeConfig.cmake @@ -167,14 +167,23 @@ endmacro() a_find_library(LIB_EV ev) # GNU libc has and backtrace() stuff. If this is not available, we # need libexecinfo. +message(STATUS "checking for execinfo") try_compile(HAS_EXECINFO ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/build-tests/execinfo.c) if(NOT HAS_EXECINFO) - a_find_library(LIB_EXECINFO execinfo) - set(AWESOME_REQUIRED_LIBRARIES - ${AWESOME_REQUIRED_LIBRARIES} - ${LIB_EXECINFO}) + find_library(LIB_EXECINFO execinfo) + if(LIB_EXECINFO) + set(HAS_EXECINFO 1) + set(AWESOME_REQUIRED_LIBRARIES + ${AWESOME_REQUIRED_LIBRARIES} + ${LIB_EXECINFO}) + endif() +endif() +if(HAS_EXECINFO) + message(STATUS "checking for execinfo -- found") +else() + message(STATUS "checking for execinfo -- not found") endif() # Error check diff --git a/common/backtrace.c b/common/backtrace.c index 96a8f0e0..e0987912 100644 --- a/common/backtrace.c +++ b/common/backtrace.c @@ -19,9 +19,13 @@ * */ -#include +#include "config.h" #include "common/backtrace.h" +#ifdef HAS_EXECINFO +#include +#endif + #define MAX_STACK_SIZE 32 /** Get a backtrace. @@ -30,6 +34,9 @@ void backtrace_get(buffer_t *buf) { + buffer_init(buf); + +#ifdef HAS_EXECINFO void *stack[MAX_STACK_SIZE]; char **bt; int stack_size; @@ -37,7 +44,6 @@ backtrace_get(buffer_t *buf) stack_size = backtrace(stack, countof(stack)); bt = backtrace_symbols(stack, stack_size); - buffer_init(buf); if(bt) { for(int i = 0; i < stack_size; i++) @@ -49,6 +55,7 @@ backtrace_get(buffer_t *buf) p_delete(&bt); } else +#endif buffer_addsl(buf, "Cannot get backtrace symbols."); } diff --git a/config.h.in b/config.h.in index 9241050e..f7d81fd4 100644 --- a/config.h.in +++ b/config.h.in @@ -6,5 +6,6 @@ #define AWESOME_IS_BIG_ENDIAN @AWESOME_IS_BIG_ENDIAN@ #cmakedefine WITH_DBUS +#cmakedefine HAS_EXECINFO #endif //_CONFIG_H_