Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 48be36f

Browse files
cmake: add USE_LIBUNWIND option to allow switching off that library
1 parent 9f17a83 commit 48be36f

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ option(CHECK_CPP_STYLE "check code style of C++ sources" OFF)
7878
option(TRACE_TESTS "more verbose test outputs" OFF)
7979
option(USE_ASAN "enable AddressSanitizer (debugging)" OFF)
8080
option(USE_UBSAN "enable UndefinedBehaviorSanitizer (debugging)" OFF)
81+
option(USE_LIBUNWIND "use libunwind for more reliable stack traces from tests (if available)" ON)
8182
option(USE_CCACHE "use ccache if it is available in the system" ON)
8283

8384
option(TESTS_USE_FORCED_PMEM "run tests with PMEM_IS_PMEM_FORCE=1 - it speeds up tests execution on emulated pmem" OFF)

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ include(tbb)
8181

8282
add_library(test_backtrace STATIC test_backtrace.c)
8383
if(LIBUNWIND_FOUND)
84-
target_compile_definitions(test_backtrace PUBLIC USE_LIBUNWIND=1)
84+
target_compile_definitions(test_backtrace PUBLIC LIBUNWIND_ENABLED=1)
8585
endif()
8686

8787
add_library(valgrind_internal STATIC valgrind_internal.cpp)

tests/ctest_helpers.cmake

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ function(find_packages)
3434
find_package(Curses QUIET)
3535
endif()
3636

37-
if(PKG_CONFIG_FOUND)
38-
pkg_check_modules(LIBUNWIND QUIET libunwind)
39-
else()
40-
find_package(LIBUNWIND QUIET)
41-
endif()
42-
if(NOT LIBUNWIND_FOUND)
43-
message(WARNING "libunwind not found. Stack traces from tests will not be reliable")
37+
if (USE_LIBUNWIND)
38+
if(PKG_CONFIG_FOUND)
39+
pkg_check_modules(LIBUNWIND QUIET libunwind)
40+
else()
41+
find_package(LIBUNWIND QUIET)
42+
endif()
43+
if(NOT LIBUNWIND_FOUND)
44+
message(WARNING "libunwind not found. Stack traces from tests will not be reliable")
45+
else()
46+
message(STATUS "Found libunwind: ${LIBUNWIND_LIBDIR} (version: ${LIBUNWIND_VERSION})")
47+
endif()
4448
endif()
4549

4650
find_gdb()

tests/test_backtrace.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2-
/* Copyright 2015-2019, Intel Corporation */
2+
/* Copyright 2015-2021, Intel Corporation */
33

44
/*
55
* backtrace.c -- backtrace reporting routines
@@ -16,7 +16,7 @@
1616
#include <stdlib.h>
1717
#include <string.h>
1818

19-
#ifdef USE_LIBUNWIND
19+
#ifdef LIBUNWIND_ENABLED
2020

2121
#define UNW_LOCAL_ONLY
2222
#include <dlfcn.h>
@@ -90,7 +90,7 @@ test_dump_backtrace(void)
9090
unw_strerror(ret), ret);
9191
}
9292
}
93-
#else /* USE_LIBUNWIND */
93+
#else /* LIBUNWIND_ENABLED */
9494

9595
#define BSIZE 100
9696

@@ -162,7 +162,7 @@ test_dump_backtrace(void)
162162

163163
#endif /* _WIN32 */
164164

165-
#endif /* USE_LIBUNWIND */
165+
#endif /* LIBUNWIND_ENABLED */
166166

167167
/*
168168
* test_sighandler -- fatal signal handler

0 commit comments

Comments
 (0)