backward-cpp
backward-cpp copied to clipboard
How to suppress clang-tidy warnings
I'm trying to suppress clang-tidy warnings from this library.
I'm getting.
[31/79] Building CXX object _deps/backward-build/CMakeFiles/backward.dir/backward.cpp.o
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.cpp:40:1: warning: static objects are disallowed; if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
40 | backward::SignalHandling sh;
| ^
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.cpp:40:26: warning: initialization of 'sh' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
40 | backward::SignalHandling sh;
| ^
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.hpp:4159:3: note: possibly throwing constructor declared here
4159 | SignalHandling(const std::vector<int> &posix_signals = make_default_signals())
| ^
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.cpp:40:26: warning: variable 'sh' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
40 | backward::SignalHandling sh;
| ^
[33/79] Building CXX object _deps/backward-build/CMakeFiles/backward_object.dir/backward.cpp.o
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.cpp:40:1: warning: static objects are disallowed; if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
40 | backward::SignalHandling sh;
| ^
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.cpp:40:26: warning: initialization of 'sh' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
40 | backward::SignalHandling sh;
| ^
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.hpp:4159:3: note: possibly throwing constructor declared here
4159 | SignalHandling(const std::vector<int> &posix_signals = make_default_signals())
| ^
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.cpp:40:26: warning: variable 'sh' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
40 | backward::SignalHandling sh;
|
My relevant CMakeLists.txt lines are:
# Clang Tidy
option(ENABLE_CLANG_TIDY "Enable clang-tidy checks during compilation" OFF)
if(ENABLE_CLANG_TIDY)
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable"
)
set(CLANG_TIDY_COLORS 1)
if(NOT CLANG_TIDY_EXE)
message(WARNING "clang-tidy not found!")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
endif()
endif()
# Backtrace-cpp
# Also requires one of: libbfd (gnu binutils), libdwarf, libdw (elfutils)
if(CMAKE_BUILD_TYPE MATCHES Debug)
FetchContent_Declare(backward
GIT_REPOSITORY https://github.com/bombela/backward-cpp
GIT_TAG v1.6)
FetchContent_MakeAvailable(backward)
endif()
function(setup_backward target)
if(CMAKE_BUILD_TYPE MATCHES Debug)
add_backward(${target})
target_link_libraries(${target} bfd dl)
target_compile_definitions(${target} PRIVATE BACKWARD_HAS_BFD=1)
endif()
endfunction()
I'm using setup_backward
to wrap add_backward
so that it only runs on Debug. Idk if that's important or not.
This makes it a bit better but I think it just prevents it from repeating itself. This has worked for all my other libraries.
# Backtrace-cpp
# Also requires one of: libbfd (gnu binutils), libdwarf, libdw (elfutils)
if(CMAKE_BUILD_TYPE MATCHES Debug)
FetchContent_Declare(backward
GIT_REPOSITORY https://github.com/bombela/backward-cpp
GIT_TAG v1.6)
FetchContent_GetProperties(backward)
# Exclude warnings from backward
if(NOT backward_POPULATED)
FetchContent_Populate(backward)
add_subdirectory(${backward_SOURCE_DIR} ${backward_BINARY_DIR} EXCLUDE_FROM_ALL)
target_compile_options(backward INTERFACE -w)
endif()
endif()