Skip to content

Making libbacktrace optional #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,29 @@ endif()

target_include_directories(${PROJECT_NAME} PRIVATE ${CURL_INCLUDE_DIRS})

find_package(Backtrace REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ${Backtrace_LIBRARIES})
find_package(Backtrace QUIET)
if (${Backtrace_FOUND})
target_link_libraries(${PROJECT_NAME} PRIVATE ${Backtrace_LIBRARIES})

find_library(DW_LIB NAMES dw)
if (NOT DW_LIB STREQUAL DW_LIB-NOTFOUND)
message("-- Enhanced stack-traces are enabled via libdw: ${DW_LIB}")
target_compile_definitions(${PROJECT_NAME} PRIVATE "BACKWARD_HAS_DW=1")
target_link_libraries(${PROJECT_NAME} PUBLIC "${DW_LIB}")
else()
find_library(BFD_LIB NAMES bfd)
if (NOT BFD_LIB STREQUAL BFD_LIB-NOTFOUND)
message("-- Enhanced stack-traces are enabled via libbfd: ${BFD_LIB}")
target_compile_definitions(${PROJECT_NAME} PRIVATE "BACKWARD_HAS_BFD=1")
target_link_libraries(${PROJECT_NAME} PRIVATE "${BFD_LIB}")
endif()
endif()

else()
message("-- libbacktrace was not installed. Stacktracing will be disabled")
add_definitions(-Dno_backtrace)
endif()


target_compile_options(${PROJECT_NAME} PRIVATE
"-fno-exceptions"
Expand All @@ -61,20 +82,6 @@ target_compile_options(${PROJECT_NAME} PRIVATE
"-Wconversion"
"-Wno-sign-conversion")

find_library(DW_LIB NAMES dw)
if (NOT DW_LIB STREQUAL DW_LIB-NOTFOUND)
message("-- Enhanced stack-traces are enabled via libdw: ${DW_LIB}")
target_compile_definitions(${PROJECT_NAME} PRIVATE "BACKWARD_HAS_DW=1")
target_link_libraries(${PROJECT_NAME} PUBLIC "${DW_LIB}")
else()
find_library(BFD_LIB NAMES bfd)
if (NOT BFD_LIB STREQUAL BFD_LIB-NOTFOUND)
message("-- Enhanced stack-traces are enabled via libbfd: ${BFD_LIB}")
target_compile_definitions(${PROJECT_NAME} PRIVATE "BACKWARD_HAS_BFD=1")
target_link_libraries(${PROJECT_NAME} PRIVATE "${BFD_LIB}")
endif()
endif()

if (LOG_VERBOSITY)
target_compile_definitions(${PROJECT_NAME} PRIVATE "AWS_LAMBDA_LOG=${LOG_VERBOSITY}")
elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
Expand Down
6 changes: 5 additions & 1 deletion src/backward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
// - g++/clang++ -lbfd ...
// #define BACKWARD_HAS_BFD 1

#include "backward.h"
#ifndef no_backtrace

# include "backward.h"

namespace backward {

backward::SignalHandling sh;

} // namespace backward

#endif
6 changes: 6 additions & 0 deletions src/backward.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
# error "It's not going to compile without a C++ compiler..."
#endif

#ifdef no_backtrace
# pragma message "Disabling stacktracing"
#else

#if defined(BACKWARD_CXX11)
#elif defined(BACKWARD_CXX98)
#else
Expand Down Expand Up @@ -4539,4 +4543,6 @@ class SignalHandling {

} // namespace backward

#endif /* no_backtrace */

#endif /* H_GUARD */