Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand All @@ -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}")
Expand Down
Loading