Skip to content

Commit b498a7e

Browse files
committed
Add cmake-formatting-check to CI
The literal-comment-pattern arg is to disable comment reformatting
1 parent 95b33e5 commit b498a7e

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

.cmake-format.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# A python-style configuration file for cmake-format
2+
# See their documentation for more information:
3+
# https://cmake-format.readthedocs.io/en/latest/configuration.html
4+
#
5+
# For info on how to run cmake-format, see CONTRIBUTING.md
6+
7+
# ------------------------------------------------
8+
# Options affecting comment reflow and formatting.
9+
# ------------------------------------------------
10+
with section("markup"):
11+
12+
# If comment markup is enabled, don't reflow any comment block which matches
13+
# this (regex) pattern. Default is `None` (disabled).
14+
#
15+
# An empty regex is used to match all comments, and disable comment reflow
16+
literal_comment_pattern = ''

.github/workflows/compilation.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ jobs:
3232
run: |
3333
fdfind . -e .c -e .h -X clang-format-${{ env.clang-format-version }} --dry-run --Werror
3434
35+
cmake-formatting-check:
36+
name: CMake Formatting Check
37+
runs-on: ubuntu-24.04
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Install cmake-format and fd-find
41+
run: |
42+
sudo apt-get update
43+
sudo apt-get -y install cmake-format fd-find
44+
- name: Check cmake-format
45+
run: |
46+
fdfind . -e cmake . -X cmake-format '{}' --in-place --config-files .cmake-format.py
47+
fdfind CMakeLists.txt . -X cmake-format '{}' --in-place --config-files .cmake-format.py
48+
git --no-pager diff --exit-code
49+
3550
# Run unittests on modern-ish versions of gcc and clang.
3651
# -----------------------------------------------------------------------------------------------
3752
unittest:
@@ -75,7 +90,7 @@ jobs:
7590
# Build windows package, release artifact (MSVC)
7691
# -----------------------------------------------------------------------------------------------
7792
build_msvc:
78-
needs: [unittest, formatting-check]
93+
needs: [unittest, formatting-check, cmake-formatting-check]
7994

8095
name: Build windows-amd64 (MSVC)
8196
runs-on: windows-latest
@@ -157,7 +172,7 @@ jobs:
157172
# Build ubuntu package, release artifact
158173
# -----------------------------------------------------------------------------------------------
159174
build_ubuntu:
160-
needs: [unittest, formatting-check]
175+
needs: [unittest, formatting-check, cmake-formatting-check]
161176

162177
name: Build ubuntu-latest
163178
runs-on: ubuntu-latest
@@ -237,7 +252,7 @@ jobs:
237252
# Build macos package, release artifact
238253
# -----------------------------------------------------------------------------------------------
239254
build_macos-arm:
240-
needs: [unittest, formatting-check]
255+
needs: [unittest, formatting-check, cmake-formatting-check]
241256

242257
name: Build macos-14
243258
runs-on: macos-14
@@ -297,7 +312,7 @@ jobs:
297312
# Build windows package, release artifact (mingw-w64)
298313
# -----------------------------------------------------------------------------------------------
299314
build_windows:
300-
needs: [unittest, formatting-check]
315+
needs: [unittest, formatting-check, cmake-formatting-check]
301316

302317
name: Build windows-amd64 (mingw-w64)
303318
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Before making a pull request, please verify via a normal issue ticket
4040
Pull requests:
4141
* must not have any build errors
4242
* must be formatted using clang-format
43+
* must be formatted using cmake-format, when changing the build scripts
4344
* must be verified using clang-tidy
4445

4546
### PR workflow if you don't have merge rights
@@ -68,3 +69,19 @@ Pull requests:
6869
Note that we only give merge rights if you have been involved for a while
6970
and we feel you can be trusted. Therefore we also trust you to know how to do
7071
this and when to bend the rules and when not to.
72+
73+
### Running cmake-format
74+
cmake-format may be available in your system package manager, or can be installed from pip:
75+
```
76+
pip install cmakelang
77+
```
78+
79+
cmake-format can then be run like so, taking care to pass it the config-file argument:
80+
81+
```sh
82+
# Format the main CMakeLists.txt file, making changes in-place
83+
cmake-format --in-place CMakeLists.txt --config-file .cmake-format.py
84+
85+
# Format the cmake-scripts folder, making changes in-place
86+
cmake-format --in-place cmake-scripts/*.cmake --config-file .cmake-format.py
87+
```

0 commit comments

Comments
 (0)