From 443e9d7cf59bb88f8920628405b2e1c6aaf770d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Wed, 15 Sep 2021 22:18:04 +0200 Subject: Add a backtrace function and library detection. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Slávek Banko (cherry picked from commit cf63191672fff12cd57892ba4642ed4f01e9c6a4) --- config.h.cmake | 6 ++++++ kmtrace/CMakeLists.txt | 8 +++++++- kmtrace/ConfigureChecks.cmake | 18 ++++++++++++++++++ kmtrace/ktrace.c | 6 +++++- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 kmtrace/ConfigureChecks.cmake diff --git a/config.h.cmake b/config.h.cmake index f1ac1ba4..d9eac5e5 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -5,3 +5,9 @@ // kbabeldict/modules/dbsearchengine #cmakedefine USE_DB_H_PATH <@USE_DB_H_PATH@> + +/* Define to 1 if GLIBC >= 2.1 compatible backtrace facility exists */ +#cmakedefine HAVE_BACKTRACE 1 +#ifdef HAVE_BACKTRACE +#define BACKTRACE_H <@Backtrace_HEADER@> +#endif diff --git a/kmtrace/CMakeLists.txt b/kmtrace/CMakeLists.txt index c2551b0e..126a1013 100644 --- a/kmtrace/CMakeLists.txt +++ b/kmtrace/CMakeLists.txt @@ -12,6 +12,7 @@ include_directories( ${TDE_INCLUDE_DIR} ${TQT_INCLUDE_DIRS} + ${CMAKE_BINARY_DIR} ) link_directories( @@ -21,6 +22,11 @@ link_directories( set( LD_FLAGS "-Wl,-Bstatic -liberty -Wl,-Bdynamic" ) +##### configure checks ########################## + +include( ConfigureChecks.cmake ) + + ##### other data ################################ configure_file( kminspector.cmake kminspector @ONLY ) @@ -48,7 +54,7 @@ tde_add_library( ktrace_s STATIC tde_add_library( ktrace SHARED SOURCES ksotrace.cpp ktrace.c - LINK dl + LINK ${DL_LIBRARIES} ${Backtrace_LIBRARY} DESTINATION ${LIB_INSTALL_DIR}/kmtrace ) diff --git a/kmtrace/ConfigureChecks.cmake b/kmtrace/ConfigureChecks.cmake new file mode 100644 index 00000000..5c06aac6 --- /dev/null +++ b/kmtrace/ConfigureChecks.cmake @@ -0,0 +1,18 @@ + +##### check if GLIBC >= 2.1 compatible backtrace facility exists + +if ( CMAKE_MAJOR_VERSION LESS "3" ) + check_symbol_exists( backtrace "execinfo.h" HAVE_BACKTRACE ) + if ( HAVE_BACKTRACE ) + set ( Backtrace_LIBRARY "" ) + set ( Backtrace_HEADER "execinfo.h" ) + endif () +else () + find_package( Backtrace ) + if ( Backtrace_FOUND ) + set ( HAVE_BACKTRACE 1 CACHE INTERNAL "" ) + endif () +endif () +if( NOT HAVE_BACKTRACE ) + tde_message_fatal( "bactrace function is required but not available on your system") +endif() diff --git a/kmtrace/ktrace.c b/kmtrace/ktrace.c index e7eee47b..dcc321e5 100644 --- a/kmtrace/ktrace.c +++ b/kmtrace/ktrace.c @@ -25,6 +25,10 @@ or (US mail) as Mike Haertel c/o Free Software Foundation. */ +#ifdef HAVE_CONFIG_H +#include +#endif + #define MALLOC_HOOKS #define _GNU_SOURCE @@ -35,8 +39,8 @@ #include #include #include -#include #include +#include BACKTRACE_H #ifdef USE_IN_LIBIO # include -- cgit v1.2.1