summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2021-09-15 22:18:04 +0200
committerSlávek Banko <slavek.banko@axis.cz>2021-09-15 22:42:00 +0200
commitcf63191672fff12cd57892ba4642ed4f01e9c6a4 (patch)
tree4464031464fe01f04c0f24bbc1181246519e1505
parentf4582480b472d7551d8f867bae4c99a96c9d588d (diff)
downloadtdesdk-cf63191672fff12cd57892ba4642ed4f01e9c6a4.tar.gz
tdesdk-cf63191672fff12cd57892ba4642ed4f01e9c6a4.zip
Add a backtrace function and library detection.
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
-rw-r--r--config.h.cmake6
-rw-r--r--kmtrace/CMakeLists.txt8
-rw-r--r--kmtrace/ConfigureChecks.cmake18
-rw-r--r--kmtrace/ktrace.c6
4 files changed, 36 insertions, 2 deletions
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 <config.h>
+#endif
+
#define MALLOC_HOOKS
#define _GNU_SOURCE
@@ -35,8 +39,8 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <execinfo.h>
#include <unistd.h>
+#include BACKTRACE_H
#ifdef USE_IN_LIBIO
# include <libio/iolibio.h>