summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitlab/ci/configure_debian12_ninja_common.cmake1
-rw-r--r--.gitlab/ci/configure_fedora39_makefiles.cmake1
-rw-r--r--Help/release/dev/FindBacktrace-imported-library.rst4
-rw-r--r--Modules/FindBacktrace.cmake22
-rw-r--r--Tests/CMakeLists.txt1
-rw-r--r--Tests/FindBacktrace/CMakeLists.txt10
-rw-r--r--Tests/FindBacktrace/Test/CMakeLists.txt11
-rw-r--r--Tests/FindBacktrace/Test/backtrace.c53
8 files changed, 103 insertions, 0 deletions
diff --git a/.gitlab/ci/configure_debian12_ninja_common.cmake b/.gitlab/ci/configure_debian12_ninja_common.cmake
index 8cebd01..65c1996 100644
--- a/.gitlab/ci/configure_debian12_ninja_common.cmake
+++ b/.gitlab/ci/configure_debian12_ninja_common.cmake
@@ -8,6 +8,7 @@ if (NOT "$ENV{CMAKE_CI_NIGHTLY}" STREQUAL "")
endif()
set(CMake_TEST_FindALSA "ON" CACHE BOOL "")
+set(CMake_TEST_FindBacktrace "ON" CACHE BOOL "")
set(CMake_TEST_FindBLAS "All;static=1;Generic" CACHE STRING "")
set(CMake_TEST_FindBoost "ON" CACHE BOOL "")
set(CMake_TEST_FindBoost_Python "ON" CACHE BOOL "")
diff --git a/.gitlab/ci/configure_fedora39_makefiles.cmake b/.gitlab/ci/configure_fedora39_makefiles.cmake
index 9cee918..b79972c 100644
--- a/.gitlab/ci/configure_fedora39_makefiles.cmake
+++ b/.gitlab/ci/configure_fedora39_makefiles.cmake
@@ -8,6 +8,7 @@ endif()
set(CMake_TEST_ASM_NASM "ON" CACHE BOOL "")
set(CMake_TEST_FindALSA "ON" CACHE BOOL "")
+set(CMake_TEST_FindBacktrace "ON" CACHE BOOL "")
set(CMake_TEST_FindBLAS "All;static=1;Generic" CACHE STRING "")
set(CMake_TEST_FindBoost "ON" CACHE BOOL "")
set(CMake_TEST_FindBoost_Python "ON" CACHE BOOL "")
diff --git a/Help/release/dev/FindBacktrace-imported-library.rst b/Help/release/dev/FindBacktrace-imported-library.rst
new file mode 100644
index 0000000..ffb8d66
--- /dev/null
+++ b/Help/release/dev/FindBacktrace-imported-library.rst
@@ -0,0 +1,4 @@
+FindBacktrace-imported-library
+------------------------------
+
+* The :module:`FindBacktrace` module now provides an imported target.
diff --git a/Modules/FindBacktrace.cmake b/Modules/FindBacktrace.cmake
index 46b62d2..4d3186c 100644
--- a/Modules/FindBacktrace.cmake
+++ b/Modules/FindBacktrace.cmake
@@ -36,6 +36,17 @@ with the contents like the following::
#endif
And then reference that generated header file in actual source.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+.. versionadded:: 3.30
+
+This module defines the following :prop_tgt:`IMPORTED` targets:
+
+``Backtrace::Backtrace``
+ An interface library providing usage requirements for the found components.
+
#]=======================================================================]
include(CMakePushCheckState)
@@ -89,3 +100,14 @@ set(Backtrace_HEADER "${_Backtrace_HEADER_TRY}" CACHE STRING "Header providing b
find_package_handle_standard_args(Backtrace FOUND_VAR Backtrace_FOUND REQUIRED_VARS ${_Backtrace_STD_ARGS})
mark_as_advanced(Backtrace_HEADER Backtrace_INCLUDE_DIR Backtrace_LIBRARY)
+
+if(Backtrace_FOUND AND NOT TARGET Backtrace::Backtrace)
+ if(Backtrace_LIBRARY)
+ add_library(Backtrace::Backtrace UNKNOWN IMPORTED)
+ set_property(TARGET Backtrace::Backtrace PROPERTY IMPORTED_LOCATION "${Backtrace_LIBRARY}")
+ else()
+ add_library(Backtrace::Backtrace INTERFACE IMPORTED)
+ target_link_libraries(Backtrace::Backtrace INTERFACE ${Backtrace_LIBRARIES})
+ endif()
+ target_include_directories(Backtrace::Backtrace INTERFACE ${Backtrace_INCLUDE_DIRS})
+endif()
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 96beecc..68f1d69 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1447,6 +1447,7 @@ if(BUILD_TESTING)
_mod
IN ITEMS
ALSA
+ Backtrace
BLAS
Boost
BZip2
diff --git a/Tests/FindBacktrace/CMakeLists.txt b/Tests/FindBacktrace/CMakeLists.txt
new file mode 100644
index 0000000..8ee2a4d
--- /dev/null
+++ b/Tests/FindBacktrace/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindBacktrace.Test COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindBacktrace/Test"
+ "${CMake_BINARY_DIR}/Tests/FindBacktrace/Test"
+ ${build_generator_args}
+ --build-project TestFindBacktrace
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+ )
diff --git a/Tests/FindBacktrace/Test/CMakeLists.txt b/Tests/FindBacktrace/Test/CMakeLists.txt
new file mode 100644
index 0000000..7f5d8ec
--- /dev/null
+++ b/Tests/FindBacktrace/Test/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.29)
+project(TestFindBLAS C)
+include(CTest)
+
+find_package(Backtrace REQUIRED)
+
+add_executable(test_tgt backtrace.c)
+target_link_libraries(test_tgt Backtrace::Backtrace)
+target_compile_options(test_tgt PUBLIC -rdynamic -fno-omit-frame-pointer)
+target_link_options(test_tgt PUBLIC -rdynamic -fno-omit-frame-pointer)
+add_test(NAME test_tgt COMMAND test_tgt)
diff --git a/Tests/FindBacktrace/Test/backtrace.c b/Tests/FindBacktrace/Test/backtrace.c
new file mode 100644
index 0000000..1a60b14
--- /dev/null
+++ b/Tests/FindBacktrace/Test/backtrace.c
@@ -0,0 +1,53 @@
+/* This is the code from `man backtrace_symbols`, reformatted, and without
+ * requiring a command-line argument */
+
+#include <execinfo.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define BT_BUF_SIZE 100
+
+void myfunc3(void)
+{
+ int nptrs;
+ void* buffer[BT_BUF_SIZE];
+ char** strings;
+
+ nptrs = backtrace(buffer, BT_BUF_SIZE);
+ printf("backtrace() returned %d addresses\n", nptrs);
+
+ /* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO)
+ would produce similar output to the following: */
+
+ strings = backtrace_symbols(buffer, nptrs);
+ if (strings == NULL) {
+ perror("backtrace_symbols");
+ exit(EXIT_FAILURE);
+ }
+
+ for (size_t j = 0; j < nptrs; j++)
+ printf("%s\n", strings[j]);
+
+ free(strings);
+}
+
+static void /* "static" means don't export the symbol... */
+myfunc2(void)
+{
+ myfunc3();
+}
+
+void myfunc(int ncalls)
+{
+ if (ncalls > 1)
+ myfunc(ncalls - 1);
+ else
+ myfunc2();
+}
+
+int main(int argc, char* argv[])
+{
+ myfunc(5);
+ exit(EXIT_SUCCESS);
+}