awesomeConfig: test for execinfo.h/backtrace()

add a test for execinfo.h and backtrace() function which are defined by
GNU libc. If it fails, require libexecinfo.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Alexandre "kAworu" Perrin 2009-10-26 23:07:35 +01:00 committed by Uli Schlachter
parent 02cd1cbda3
commit 23d5b27206
2 changed files with 53 additions and 0 deletions

View File

@ -165,6 +165,17 @@ endmacro()
# Check for libev # Check for libev
a_find_library(LIB_EV ev) a_find_library(LIB_EV ev)
# GNU libc has <execinfo.h> and backtrace() stuff. If this is not available, we
# need libexecinfo.
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})
endif()
# Error check # Error check
if(NOT LUA51_FOUND AND NOT LUA50_FOUND) # This is a workaround to a cmake bug if(NOT LUA51_FOUND AND NOT LUA50_FOUND) # This is a workaround to a cmake bug

42
build-tests/execinfo.c Normal file
View File

@ -0,0 +1,42 @@
/*
* build-tests/execinfo.c
* stolen from http://www.gnu.org/s/libc/manual/html_node/Backtraces.html
*/
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
/* Obtain a backtrace and print it to stdout. */
void
print_trace (void)
{
void *array[10];
size_t size;
char **strings;
size_t i;
size = backtrace (array, 10);
strings = backtrace_symbols (array, size);
printf ("Obtained %zd stack frames.\n", size);
for (i = 0; i < size; i++)
printf ("%s\n", strings[i]);
free (strings);
}
/* A dummy function to make the backtrace more interesting. */
void
dummy_function (void)
{
print_trace ();
}
int
main (void)
{
dummy_function ();
return 0;
}