Don't fail if execinfo is not available

Previously, cmake aborted when execinfo was not found. With this commit the
backtrace code is just disabled when execinfo is not available.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-08-12 20:14:56 +02:00
parent 23d5b27206
commit 0116d739b5
3 changed files with 23 additions and 6 deletions

View File

@ -167,14 +167,23 @@ endmacro()
a_find_library(LIB_EV ev)
# GNU libc has <execinfo.h> 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)
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

View File

@ -19,9 +19,13 @@
*
*/
#include <execinfo.h>
#include "config.h"
#include "common/backtrace.h"
#ifdef HAS_EXECINFO
#include <execinfo.h>
#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.");
}

View File

@ -6,5 +6,6 @@
#define AWESOME_IS_BIG_ENDIAN @AWESOME_IS_BIG_ENDIAN@
#cmakedefine WITH_DBUS
#cmakedefine HAS_EXECINFO
#endif //_CONFIG_H_