Skip to content

Commit 07e8c62

Browse files
authored
chore: merge pull request #25 from threeal/cmake-always-fix-format
CMake Always Fix Format and Add Enable Check Options
2 parents f50eaf3 + 4f1eb15 commit 07e8c62

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ jobs:
2121
run: |
2222
cmake ${{ matrix.package }} \
2323
-B ${{ matrix.package }}/build \
24-
-D BUILD_TESTING=ON
25-
26-
- name: Check code formatting
27-
run: |
28-
cmake --build ${{ matrix.package }}/build --target fix-format
29-
git diff --exit-code HEAD
24+
-D BUILD_TESTING=ON \
25+
-D CHECK_FORMAT=ON \
26+
-D CHECK_WARNING=ON \
27+
-D CHECK_COVERAGE=ON
3028
3129
- name: Build project
3230
run: cmake --build ${{ matrix.package }}/build
@@ -43,6 +41,9 @@ jobs:
4341
${{ matrix.package }}/test/*
4442
fail-under-line: 100
4543

44+
- name: Check diff
45+
run: git diff --exit-code HEAD
46+
4647
debug-msvc:
4748
runs-on: windows-latest
4849
strategy:
@@ -57,7 +58,8 @@ jobs:
5758
cmake ${{ matrix.package }} `
5859
-B ${{ matrix.package }}/build `
5960
-D CMAKE_CXX_COMPILER=cl `
60-
-D BUILD_TESTING=ON
61+
-D BUILD_TESTING=ON `
62+
-D CHECK_WARNING=ON
6163
6264
- name: Build project
6365
run: cmake --build ${{ matrix.package }}/build

error/.cmake-format

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"line_width": 120
2+
"line_width": 120,
3+
"max_subgroups_hwrap": 3
34
}

error/CMakeLists.txt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ target_link_libraries(error PUBLIC fmt)
1313

1414
# Check if this project is the main project
1515
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
16+
option(CHECK_FORMAT "Enable source code formatting check" OFF)
17+
option(CHECK_WARNING "Enable static analysis warning check" OFF)
18+
option(CHECK_COVERAGE "Enable test coverage check" OFF)
19+
1620
# Import Format.cmake to format source code
17-
cpmaddpackage("gh:TheLartians/[email protected]")
21+
if(CHECK_FORMAT)
22+
cpmaddpackage("gh:TheLartians/[email protected]")
23+
add_dependencies(error fix-format)
24+
endif()
1825

1926
if(BUILD_TESTING)
2027
enable_testing()
@@ -30,21 +37,20 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
3037
endif()
3138

3239
# Get all targets in this directory
33-
get_property(
34-
TARGETS
35-
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
36-
PROPERTY BUILDSYSTEM_TARGETS)
40+
get_property(TARGETS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS)
3741

3842
foreach(TARGET IN LISTS TARGETS)
3943
# Statically analyze code by checking for warnings
40-
if(MSVC)
41-
target_compile_options(${TARGET} PRIVATE /WX /permissive- /W4 /w14640 /EHsc)
42-
else()
43-
target_compile_options(${TARGET} PRIVATE -Werror -Wall -Wextra -Wnon-virtual-dtor -Wpedantic)
44+
if(CHECK_WARNING)
45+
if(MSVC)
46+
target_compile_options(${TARGET} PRIVATE /WX /permissive- /W4 /w14640 /EHsc)
47+
else()
48+
target_compile_options(${TARGET} PRIVATE -Werror -Wall -Wextra -Wnon-virtual-dtor -Wpedantic)
49+
endif()
4450
endif()
4551

4652
# Enable support to check for test coverage
47-
if(BUILD_TESTING AND NOT MSVC)
53+
if(BUILD_TESTING AND CHECK_COVERAGE AND NOT MSVC)
4854
target_compile_options(${TARGET} PRIVATE --coverage -O0)
4955
target_link_options(${TARGET} PRIVATE --coverage)
5056
endif()

0 commit comments

Comments
 (0)