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 bc815b5..6fb3fbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ project(StreamLib C) 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) include(FetchContent) @@ -48,7 +49,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() @@ -66,7 +75,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}")