diff options
author | David Faure <faure@kde.org> | 2024-04-05 23:43:33 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-04-15 17:27:23 (GMT) |
commit | 9433755e5dda33d078f8ca7070ba1f9113448b99 (patch) | |
tree | 8837cbb5332fd54577410c00a18480c57f599a20 /Tests | |
parent | aefd952085b54089e20b51fabf2ebf926e886fa9 (diff) | |
download | CMake-9433755e5dda33d078f8ca7070ba1f9113448b99.zip CMake-9433755e5dda33d078f8ca7070ba1f9113448b99.tar.gz CMake-9433755e5dda33d078f8ca7070ba1f9113448b99.tar.bz2 |
FindBacktrace: Add imported library
This is to avoid (a future version of) Qt from having to wrap
FindBacktrace like [1].
[1] https://code.qt.io/cgit/qt/qtbase.git/tree/cmake/FindWrapBacktrace.cmake
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/FindBacktrace/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Tests/FindBacktrace/Test/CMakeLists.txt | 11 | ||||
-rw-r--r-- | Tests/FindBacktrace/Test/backtrace.c | 53 |
4 files changed, 75 insertions, 0 deletions
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); +} |