diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ec5b78e..d75f76d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,12 +21,10 @@ jobs: run: | cmake ${{ matrix.package }} \ -B ${{ matrix.package }}/build \ - -D BUILD_TESTING=ON - - - name: Check code formatting - run: | - cmake --build ${{ matrix.package }}/build --target fix-format - git diff --exit-code HEAD + -D BUILD_TESTING=ON \ + -D CHECK_FORMAT=ON \ + -D CHECK_WARNING=ON \ + -D CHECK_COVERAGE=ON - name: Build project run: cmake --build ${{ matrix.package }}/build @@ -43,6 +41,9 @@ jobs: ${{ matrix.package }}/test/* fail-under-line: 100 + - name: Check diff + run: git diff --exit-code HEAD + debug-msvc: runs-on: windows-latest strategy: @@ -57,7 +58,8 @@ jobs: cmake ${{ matrix.package }} ` -B ${{ matrix.package }}/build ` -D CMAKE_CXX_COMPILER=cl ` - -D BUILD_TESTING=ON + -D BUILD_TESTING=ON ` + -D CHECK_WARNING=ON - name: Build project run: cmake --build ${{ matrix.package }}/build diff --git a/error/.cmake-format b/error/.cmake-format index ceb0afb..a6b2f16 100644 --- a/error/.cmake-format +++ b/error/.cmake-format @@ -1,3 +1,4 @@ { - "line_width": 120 + "line_width": 120, + "max_subgroups_hwrap": 3 } diff --git a/error/CMakeLists.txt b/error/CMakeLists.txt index 500ddc1..3ed1fc8 100644 --- a/error/CMakeLists.txt +++ b/error/CMakeLists.txt @@ -13,8 +13,15 @@ target_link_libraries(error PUBLIC fmt) # Check if this project is the main project if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + option(CHECK_FORMAT "Enable source code formatting check" OFF) + option(CHECK_WARNING "Enable static analysis warning check" OFF) + option(CHECK_COVERAGE "Enable test coverage check" OFF) + # Import Format.cmake to format source code - cpmaddpackage("gh:TheLartians/Format.cmake@1.7.3") + if(CHECK_FORMAT) + cpmaddpackage("gh:TheLartians/Format.cmake@1.7.3") + add_dependencies(error fix-format) + endif() if(BUILD_TESTING) enable_testing() @@ -30,21 +37,20 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) endif() # Get all targets in this directory - get_property( - TARGETS - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - PROPERTY BUILDSYSTEM_TARGETS) + get_property(TARGETS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS) foreach(TARGET IN LISTS TARGETS) # Statically analyze code by checking for warnings - if(MSVC) - target_compile_options(${TARGET} PRIVATE /WX /permissive- /W4 /w14640 /EHsc) - else() - target_compile_options(${TARGET} PRIVATE -Werror -Wall -Wextra -Wnon-virtual-dtor -Wpedantic) + if(CHECK_WARNING) + if(MSVC) + target_compile_options(${TARGET} PRIVATE /WX /permissive- /W4 /w14640 /EHsc) + else() + target_compile_options(${TARGET} PRIVATE -Werror -Wall -Wextra -Wnon-virtual-dtor -Wpedantic) + endif() endif() # Enable support to check for test coverage - if(BUILD_TESTING AND NOT MSVC) + if(BUILD_TESTING AND CHECK_COVERAGE AND NOT MSVC) target_compile_options(${TARGET} PRIVATE --coverage -O0) target_link_options(${TARGET} PRIVATE --coverage) endif()