From 48170d10ae83d6d604ee086f5fd64d1e40c0ae38 Mon Sep 17 00:00:00 2001 From: SunBlack Date: Fri, 13 Nov 2026 14:46:33 +0100 Subject: [PATCH] Add option to enable/disable warning as error --- CMakeLists.txt | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 281cde08e..f1183ef17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ option(BTCPP_SQLITE_LOGGING "Add SQLite logging." ON) option(BTCPP_ENABLE_ASAN "Enable Address Sanitizer" OFF) option(BTCPP_ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF) option(BTCPP_ENABLE_TSAN "Enable Thread Sanitizer" OFF) +option(BTCPP_ENABLE_WARNING_AS_ERROR "Specify whether to treat warnings on compile as errors." ON) option(USE_V3_COMPATIBLE_NAMES "Use some alias to compile more easily old 3.x code" OFF) option(ENABLE_FUZZING "Enable fuzzing builds" OFF) @@ -294,17 +295,19 @@ endif() add_library(BT::${BTCPP_LIBRARY} ALIAS ${BTCPP_LIBRARY}) -# Downstream projects (e.g. Nav2) compile our public headers with -Werror, so -# the library and every target below that instantiates them must be -# warning-free (issue #1288). -Wnull-dereference only fires with optimization. -# Set after the 3rdparty subdirectories, so vendored code is not affected. -if(MSVC) - # C4702 (unreachable code) is a code-generation warning that fires on - # instantiation-dependent `if constexpr` tails; GCC/Clang have no - # equivalent in -Wall -Wextra. - set(BTCPP_WARNING_FLAGS /W4 /WX /permissive- /wd4702) -else() - set(BTCPP_WARNING_FLAGS -Wall -Wextra -Wpedantic -Wnull-dereference -Werror) +if(BTCPP_ENABLE_WARNING_AS_ERROR) + # Downstream projects (e.g. Nav2) compile our public headers with -Werror, so + # the library and every target below that instantiates them must be + # warning-free (issue #1288). -Wnull-dereference only fires with optimization. + # Set after the 3rdparty subdirectories, so vendored code is not affected. + if(MSVC) + # C4702 (unreachable code) is a code-generation warning that fires on + # instantiation-dependent `if constexpr` tails; GCC/Clang have no + # equivalent in -Wall -Wextra. + set(BTCPP_WARNING_FLAGS /W4 /WX /permissive- /wd4702) + else() + set(BTCPP_WARNING_FLAGS -Wall -Wextra -Wpedantic -Wnull-dereference -Werror) + endif() endif() target_compile_options(${BTCPP_LIBRARY} PRIVATE ${BTCPP_WARNING_FLAGS}) add_compile_options(${BTCPP_WARNING_FLAGS})