Set -Werror / /WX via target_compile_options to force warnings as errors

This commit is contained in:
Tim Wojtulewicz 2023-12-15 14:35:53 -07:00
parent 3f70998896
commit bbcc4b00fb
5 changed files with 35 additions and 8 deletions

View file

@ -10,13 +10,13 @@ btest_jobs: &BTEST_JOBS 4
btest_retries: &BTEST_RETRIES 2 btest_retries: &BTEST_RETRIES 2
memory: &MEMORY 16GB memory: &MEMORY 16GB
config: &CONFIG --build-type=release --disable-broker-tests --prefix=$CIRRUS_WORKING_DIR/install --ccache config: &CONFIG --build-type=release --disable-broker-tests --prefix=$CIRRUS_WORKING_DIR/install --ccache --enable-werror
no_spicy_config: &NO_SPICY_CONFIG --build-type=release --disable-broker-tests --disable-spicy --prefix=$CIRRUS_WORKING_DIR/install --ccache no_spicy_config: &NO_SPICY_CONFIG --build-type=release --disable-broker-tests --disable-spicy --prefix=$CIRRUS_WORKING_DIR/install --ccache --enable-werror
static_config: &STATIC_CONFIG --build-type=release --disable-broker-tests --enable-static-broker --enable-static-binpac --prefix=$CIRRUS_WORKING_DIR/install --ccache static_config: &STATIC_CONFIG --build-type=release --disable-broker-tests --enable-static-broker --enable-static-binpac --prefix=$CIRRUS_WORKING_DIR/install --ccache --enable-werror
asan_sanitizer_config: &ASAN_SANITIZER_CONFIG --build-type=debug --disable-broker-tests --sanitizers=address --enable-fuzzers --enable-coverage --disable-spicy --ccache asan_sanitizer_config: &ASAN_SANITIZER_CONFIG --build-type=debug --disable-broker-tests --sanitizers=address --enable-fuzzers --enable-coverage --disable-spicy --ccache --enable-werror
ubsan_sanitizer_config: &UBSAN_SANITIZER_CONFIG --build-type=debug --disable-broker-tests --sanitizers=undefined --enable-fuzzers --disable-spicy --ccache ubsan_sanitizer_config: &UBSAN_SANITIZER_CONFIG --build-type=debug --disable-broker-tests --sanitizers=undefined --enable-fuzzers --disable-spicy --ccache --enable-werror
tsan_sanitizer_config: &TSAN_SANITIZER_CONFIG --build-type=debug --disable-broker-tests --sanitizers=thread --enable-fuzzers --disable-spicy --ccache tsan_sanitizer_config: &TSAN_SANITIZER_CONFIG --build-type=debug --disable-broker-tests --sanitizers=thread --enable-fuzzers --disable-spicy --ccache --enable-werror
openssl30_config: &OPENSSL30_CONFIG --build-type=release --disable-broker-tests --with-openssl=/opt/openssl --prefix=$CIRRUS_WORKING_DIR/install --ccache openssl30_config: &OPENSSL30_CONFIG --build-type=release --disable-broker-tests --with-openssl=/opt/openssl --prefix=$CIRRUS_WORKING_DIR/install --ccache --enable-werror
resources_template: &RESOURCES_TEMPLATE resources_template: &RESOURCES_TEMPLATE
cpu: *CPUS cpu: *CPUS

View file

@ -165,8 +165,18 @@ if (MSVC)
# Disable Spicy as it is not yet supported in Windows. # Disable Spicy as it is not yet supported in Windows.
set(DISABLE_SPICY true) set(DISABLE_SPICY true)
if (BUILD_WITH_WERROR)
# TODO: This is disabled for now because there a bunch of known
# compiler warnings on Windows that we don't have good fixes for.
#set(WERROR_FLAG "/WX")
#set(WERROR_FLAG "/WX")
endif ()
else () else ()
include(GNUInstallDirs) include(GNUInstallDirs)
if (BUILD_WITH_WERROR)
set(WERROR_FLAG "-Werror")
endif ()
endif () endif ()
include(cmake/CommonCMakeConfig.cmake) include(cmake/CommonCMakeConfig.cmake)
@ -254,6 +264,7 @@ endif ()
foreach (name zeek_exe zeek_lib zeek_fuzzer_shared) foreach (name zeek_exe zeek_lib zeek_fuzzer_shared)
if (TARGET ${name}) if (TARGET ${name})
target_compile_definitions(${name} PRIVATE ZEEK_CONFIG_SKIP_VERSION_H) target_compile_definitions(${name} PRIVATE ZEEK_CONFIG_SKIP_VERSION_H)
target_compile_options(${name} PRIVATE ${WERROR_FLAG})
endif () endif ()
endforeach () endforeach ()
@ -347,6 +358,7 @@ function (zeek_add_subdir_library name)
add_dependencies(${target_name} zeek_autogen_files) add_dependencies(${target_name} zeek_autogen_files)
target_link_libraries(${target_name} PRIVATE $<BUILD_INTERFACE:zeek_internal>) target_link_libraries(${target_name} PRIVATE $<BUILD_INTERFACE:zeek_internal>)
add_clang_tidy_files(${FN_ARGS_SOURCES}) add_clang_tidy_files(${FN_ARGS_SOURCES})
target_compile_options(${target_name} PRIVATE ${WERROR_FLAG})
# Take care of compiling BIFs. # Take care of compiling BIFs.
if (FN_ARGS_BIFS) if (FN_ARGS_BIFS)

2
cmake

@ -1 +1 @@
Subproject commit 507d1201213a7b308298e0c5d6ac0c9f870e2bb8 Subproject commit 01fcb683005e3c3a71ae867aa983b772a77e32d1

4
configure vendored
View file

@ -64,6 +64,7 @@ Usage: $0 [OPTION]... [VAR=VALUE]...
--enable-perftools-debug use Google's perftools for debugging --enable-perftools-debug use Google's perftools for debugging
--enable-static-binpac build binpac statically (ignored if --with-binpac is specified) --enable-static-binpac build binpac statically (ignored if --with-binpac is specified)
--enable-static-broker build Broker statically (ignored if --with-broker is specified) --enable-static-broker build Broker statically (ignored if --with-broker is specified)
--enable-werror build with -Werror
--disable-af-packet don't include native AF_PACKET support (Linux only) --disable-af-packet don't include native AF_PACKET support (Linux only)
--disable-archiver don't build or install zeek-archiver tool --disable-archiver don't build or install zeek-archiver tool
--disable-auxtools don't build or install auxiliary tools --disable-auxtools don't build or install auxiliary tools
@ -275,6 +276,9 @@ while [ $# -ne 0 ]; do
--enable-static-broker) --enable-static-broker)
append_cache_entry BUILD_STATIC_BROKER BOOL true append_cache_entry BUILD_STATIC_BROKER BOOL true
;; ;;
--enable-werror)
append_cache_entry BUILD_WITH_WERROR BOOL true
;;
--disable-af-packet) --disable-af-packet)
append_cache_entry DISABLE_AF_PACKET BOOL true append_cache_entry DISABLE_AF_PACKET BOOL true
;; ;;

View file

@ -41,8 +41,16 @@ set(BISON_FLAGS "--debug")
if (MSVC) if (MSVC)
set(SIGN_COMPARE_FLAG "/wd4018") set(SIGN_COMPARE_FLAG "/wd4018")
if (BUILD_WITH_WERROR)
# TODO: This is disabled for now because there a bunch of known
# compiler warnings on Windows that we don't have good fixes for.
#set(WERROR_FLAG "/WX")
endif ()
else () else ()
set(SIGN_COMPARE_FLAG "-Wno-sign-compare") set(SIGN_COMPARE_FLAG "-Wno-sign-compare")
if (BUILD_WITH_WERROR)
set(WERROR_FLAG "-Werror")
endif ()
endif () endif ()
# Rule parser/scanner # Rule parser/scanner
@ -517,6 +525,7 @@ collect_headers(zeek_HEADERS ${zeek_SRCS})
add_library(zeek_objs OBJECT ${zeek_SRCS}) add_library(zeek_objs OBJECT ${zeek_SRCS})
target_compile_features(zeek_objs PRIVATE ${ZEEK_CXX_STD}) target_compile_features(zeek_objs PRIVATE ${ZEEK_CXX_STD})
target_compile_options(zeek_objs PRIVATE ${WERROR_FLAG})
set_target_properties(zeek_objs PROPERTIES CXX_EXTENSIONS OFF) set_target_properties(zeek_objs PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(zeek_objs PRIVATE $<BUILD_INTERFACE:zeek_internal>) target_link_libraries(zeek_objs PRIVATE $<BUILD_INTERFACE:zeek_internal>)
target_compile_definitions(zeek_objs PRIVATE ZEEK_CONFIG_SKIP_VERSION_H) target_compile_definitions(zeek_objs PRIVATE ZEEK_CONFIG_SKIP_VERSION_H)
@ -530,6 +539,7 @@ endif ()
if (TARGET zeek_exe) if (TARGET zeek_exe)
target_sources(zeek_exe PRIVATE main.cc ${zeek_HEADERS}) target_sources(zeek_exe PRIVATE main.cc ${zeek_HEADERS})
target_compile_options(zeek_exe PRIVATE ${WERROR_FLAG})
# npcap/winpcap need to be loaded in delayed mode so that we can set the load # npcap/winpcap need to be loaded in delayed mode so that we can set the load
# path correctly at runtime. See # path correctly at runtime. See
@ -553,6 +563,7 @@ endif ()
if (TARGET zeek_lib) if (TARGET zeek_lib)
target_sources(zeek_lib PRIVATE ${zeek_HEADERS}) target_sources(zeek_lib PRIVATE ${zeek_HEADERS})
target_compile_options(zeek_lib PRIVATE ${WERROR_FLAG})
target_link_libraries(zeek_lib PUBLIC ${zeekdeps} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) target_link_libraries(zeek_lib PUBLIC ${zeekdeps} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
endif () endif ()