From b8d377f7f032e2bb27cc51d77bc9c627fc37edea Mon Sep 17 00:00:00 2001 From: Christopher Bazley <119876938+chrisbazley@users.noreply.github.com> Date: Mon, 28 Sep 2026 15:20:56 +0100 Subject: [PATCH] Make CI diagnostics fatal --- .github/workflows/cmake-multi-platform.yml | 2 ++ CMakeLists.txt | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 91dd64f..f600594 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -58,6 +58,7 @@ jobs: cmake -B ${{ steps.strings.outputs.build-output-dir }} -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -DWARNINGS_AS_ERRORS=ON -DUSE_OPTIONAL=OFF -DUSE_FORTIFY=${{ matrix.build_type == 'Debug' && matrix.c_compiler != 'clang' }} -S ${{ github.workspace }} @@ -151,6 +152,7 @@ jobs: -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ -DCMAKE_C_COMPILER="$OPTIONAL_CLANG_ROOT/bin/clang" \ -DCLANG_TIDY_EXE="$OPTIONAL_CLANG_ROOT/bin/clang-tidy" \ + -DWARNINGS_AS_ERRORS=ON \ -DUSE_OPTIONAL=ON \ -DUSE_FORTIFY=${{ matrix.use_fortify }} \ -DENABLE_CLANG_TIDY=ON diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a877fd..2f686ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ include(FetchContent) option(USE_OPTIONAL "Enable the _Optional qualifier" OFF) option(USE_FORTIFY "Enable Fortify memory-allocation checking" OFF) option(ENABLE_CLANG_TIDY "Run clang-tidy during compilation" OFF) +option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF) FetchContent_Declare(CBUtil GIT_REPOSITORY https://github.com/chrisbazley/CBUtilLib.git GIT_TAG main) @@ -46,7 +47,15 @@ else() add_compile_options(-Wall -Wextra -Wsign-compare -pedantic) endif() -if(ENABLE_CLANG_TIDY) +if(WARNINGS_AS_ERRORS AND CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + if(MSVC) + add_compile_options(/WX) + else() + add_compile_options(-Werror) + endif() +endif() + +if(ENABLE_CLANG_TIDY AND CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang|AppleClang") message(FATAL_ERROR "ENABLE_CLANG_TIDY requires Clang") endif() @@ -64,7 +73,7 @@ if(ENABLE_CLANG_TIDY) set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY_EXE}" "--checks=-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.*" - "--warnings-as-errors=clang-analyzer-optionality.*" + "--warnings-as-errors=clang-analyzer-*" ) message(STATUS "clang-tidy: ${CLANG_TIDY_EXE}")