Skip to content

Enable Format, Warning, and Coverage by Default #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 14, 2023
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
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ jobs:
run: |
cmake . \
-B build \
-D BUILD_TESTING=ON \
-D CHECK_FORMAT=ON \
-D CHECK_WARNING=ON \
-D CHECK_COVERAGE=ON
-D BUILD_TESTING=ON

- name: Check formatting
run: |
cmake --build build --target fix-format
git diff --exit-code HEAD

- name: Build project
run: cmake --build build
Expand Down Expand Up @@ -49,8 +51,7 @@ jobs:
cmake . `
-B build `
-D CMAKE_CXX_COMPILER=cl `
-D BUILD_TESTING=ON `
-D CHECK_WARNING=ON
-D BUILD_TESTING=ON

- name: Build project
run: cmake --build build
Expand Down
20 changes: 6 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@ target_compile_features(errors PRIVATE cxx_std_20)

# 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)
option(BUILD_DOCS "Enable documentations build" OFF)

# Import Format.cmake to format source code
if(CHECK_FORMAT)
cpmaddpackage("gh:threeal/Format.cmake#auto-install-cmake-format")
add_dependencies(errors fix-format)
endif()
cpmaddpackage("gh:threeal/Format.cmake#auto-install-cmake-format")

if(BUILD_TESTING)
enable_testing()
Expand All @@ -43,16 +37,14 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)

foreach(TARGET IN LISTS TARGETS)
# Statically analyze code by checking for warnings
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()
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()

# Enable support to check for test coverage
if(BUILD_TESTING AND CHECK_COVERAGE AND NOT MSVC)
if(BUILD_TESTING AND NOT MSVC)
target_compile_options(${TARGET} PRIVATE --coverage -O0)
target_link_options(${TARGET} PRIVATE --coverage)
endif()
Expand Down