From 671a5f8be74edb5c422b024e400c04a6299bd98d Mon Sep 17 00:00:00 2001 From: badaix Date: Sun, 9 Jun 2024 20:35:28 +0200 Subject: [PATCH] Treat warnings as errors --- .github/workflows/ci.yml | 10 +++++----- CMakeLists.txt | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2aafab..c62e2f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,9 +94,9 @@ jobs: - name: print environment run: env - name: configure - run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + run: cmake -S . -B build -DWERROR=ON -DCMAKE_BUILD_TYPE=Release - name: build - run: cmake --build build --parallel 3 + run: cmake --build build --parallel 8 env: CC: ${{ matrix.cc }} CXX: ${{ matrix.cxx }} @@ -157,11 +157,11 @@ jobs: - name: print environment run: env - name: configure - run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + run: cmake -S . -B build -DWERROR=ON -DCMAKE_BUILD_TYPE=Release env: DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer - name: build - run: cmake --build build --parallel 3 --verbose + run: cmake --build build --parallel 8 --verbose - name: test run: ./build/test/jsonrpcpp_test @@ -195,6 +195,6 @@ jobs: -DVCPKG_TARGET_TRIPLET="x64-windows" ` -DCMAKE_BUILD_TYPE=Release `" - name: build - run: cmake --build build --config Release --parallel 3 --verbose + run: cmake --build build --config Release --parallel 8 --verbose - name: test run: .\build\test\Release\jsonrpcpp_test.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index 0027254..82fbc35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ set(PROJECT_URL "https://github.com/badaix/jsonrpcpp") option(BUILD_EXAMPLE "Build example (build jsonrpcpp_example demo)" ON) option(BUILD_TESTS "Build tests" ON) +option(WERROR "Treat warnings as errors" OFF) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_EXTENSIONS OFF) @@ -35,6 +36,25 @@ include_directories( install(FILES include/jsonrpcpp.hpp include/json.hpp DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/jsonrpcpp") +if(MSVC) + # warning level 4 and all warnings as errors warning C4505: 'getArch': + # unreferenced local function has been removed warning C4458: declaration of + # 'size' hides class member warning C4459: declaration of 'query' hides global + # declaration + add_compile_options(/W4 /wd4458 /wd4459 /wd4505) + if(WERROR) + add_compile_options(/WX) + endif() +else() + # lots of warnings and all warnings as errors + add_compile_options(-Wall -Wextra -pedantic) + + if(WERROR) + add_compile_options(-Werror) + endif() +endif() + + if (BUILD_EXAMPLE) add_subdirectory(example) endif (BUILD_EXAMPLE)