use CMake check_function_exists() for execinfo
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
cc08f45304
commit
7a3adfb741
|
@ -162,11 +162,10 @@ 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.
|
# Check for backtrace_symbols()
|
||||||
try_compile(HAS_EXECINFO
|
include(CheckFunctionExists)
|
||||||
${CMAKE_BINARY_DIR}
|
check_function_exists(backtrace_symbols HAS_EXECINFO)
|
||||||
${CMAKE_SOURCE_DIR}/build-tests/execinfo.c)
|
|
||||||
if(NOT HAS_EXECINFO)
|
if(NOT HAS_EXECINFO)
|
||||||
find_library(LIB_EXECINFO execinfo)
|
find_library(LIB_EXECINFO execinfo)
|
||||||
if(LIB_EXECINFO)
|
if(LIB_EXECINFO)
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue