Skip to content

Commit a1a2ef1

Browse files
authored
Merge pull request #73 from SC-SGS/cmake_format
Add automatic CMakeLists formatting similar to current clang-format.
2 parents ac80299 + c723ca6 commit a1a2ef1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1306
-927
lines changed

.cmake-format

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
# ----------------------------------
2+
# Options affecting listfile parsing
3+
# ----------------------------------
4+
with section("parse"):
5+
6+
# Specify structure for custom cmake functions
7+
additional_commands = { 'foo': { 'flags': ['BAR', 'BAZ'],
8+
'kwargs': {'DEPENDS': '*', 'HEADERS': '*', 'SOURCES': '*'}}}
9+
10+
# Override configurations per-command where available
11+
override_spec = {}
12+
13+
# Specify variable tags.
14+
vartags = []
15+
16+
# Specify property tags.
17+
proptags = []
18+
19+
# -----------------------------
20+
# Options affecting formatting.
21+
# -----------------------------
22+
with section("format"):
23+
24+
# Disable formatting entirely, making cmake-format a no-op
25+
disable = False
26+
27+
# How wide to allow formatted cmake files
28+
line_width = 160
29+
30+
# How many spaces to tab for indent
31+
tab_size = 4
32+
33+
# If true, lines are indented using tab characters (utf-8 0x09) instead of
34+
# <tab_size> space characters (utf-8 0x20). In cases where the layout would
35+
# require a fractional tab character, the behavior of the fractional
36+
# indentation is governed by <fractional_tab_policy>
37+
use_tabchars = False
38+
39+
# If <use_tabchars> is True, then the value of this variable indicates how
40+
# fractional indentions are handled during whitespace replacement. If set to
41+
# 'use-space', fractional indentation is left as spaces (utf-8 0x20). If set
42+
# to `round-up` fractional indentation is replaced with a single tab character
43+
# (utf-8 0x09) effectively shifting the column to the next tabstop
44+
fractional_tab_policy = 'use-space'
45+
46+
# If an argument group contains more than this many sub-groups (parg or kwarg
47+
# groups) then force it to a vertical layout.
48+
max_subgroups_hwrap = 3
49+
50+
# If a positional argument group contains more than this many arguments, then
51+
# force it to a vertical layout.
52+
max_pargs_hwrap = 4
53+
54+
# If a cmdline positional group consumes more than this many lines without
55+
# nesting, then invalidate the layout (and nest)
56+
max_rows_cmdline = 3
57+
58+
# If true, separate flow control names from their parentheses with a space
59+
separate_ctrl_name_with_space = True
60+
61+
# If true, separate function names from parentheses with a space
62+
separate_fn_name_with_space = False
63+
64+
# If a statement is wrapped to more than one line, than dangle the closing
65+
# parenthesis on its own line.
66+
dangle_parens = True
67+
68+
# If the trailing parenthesis must be 'dangled' on its on line, then align it
69+
# to this reference: `prefix`: the start of the statement, `prefix-indent`:
70+
# the start of the statement, plus one indentation level, `child`: align to
71+
# the column of the arguments
72+
dangle_align = 'prefix'
73+
74+
# If the statement spelling length (including space and parenthesis) is
75+
# smaller than this amount, then force reject nested layouts.
76+
min_prefix_chars = 4
77+
78+
# If the statement spelling length (including space and parenthesis) is larger
79+
# than the tab width by more than this amount, then force reject un-nested
80+
# layouts.
81+
max_prefix_chars = 12
82+
83+
# If a candidate layout is wrapped horizontally but it exceeds this many
84+
# lines, then reject the layout.
85+
max_lines_hwrap = 12
86+
87+
# What style line endings to use in the output.
88+
line_ending = 'unix'
89+
90+
# Format command names consistently as 'lower' or 'upper' case
91+
command_case = 'canonical'
92+
93+
# Format keywords consistently as 'lower' or 'upper' case
94+
keyword_case = 'unchanged'
95+
96+
# A list of command names which should always be wrapped
97+
always_wrap = [
98+
"FetchContent_Declare",
99+
"add_custom_target",
100+
"find_path",
101+
"gtest_discover_tests",
102+
"execute_process",
103+
"configure_package_config_file",
104+
"write_basic_package_version_file"
105+
]
106+
107+
# If true, the argument lists which are known to be sortable will be sorted
108+
# lexicographicall
109+
enable_sort = False
110+
111+
# If true, the parsers may infer whether or not an argument list is sortable
112+
# (without annotation).
113+
autosort = False
114+
115+
# By default, if cmake-format cannot successfully fit everything into the
116+
# desired linewidth it will apply the last, most agressive attempt that it
117+
# made. If this flag is True, however, cmake-format will print error, exit
118+
# with non-zero status code, and write-out nothing
119+
require_valid_layout = False
120+
121+
# A dictionary mapping layout nodes to a list of wrap decisions. See the
122+
# documentation for more information.
123+
layout_passes = {}
124+
125+
# ------------------------------------------------
126+
# Options affecting comment reflow and formatting.
127+
# ------------------------------------------------
128+
with section("markup"):
129+
130+
# What character to use for bulleted lists
131+
bullet_char = '-'
132+
133+
# What character to use as punctuation after numerals in an enumerated list
134+
enum_char = '.'
135+
136+
# If comment markup is enabled, don't reflow the first comment block in each
137+
# listfile. Use this to preserve formatting of your copyright/license
138+
# statements.
139+
first_comment_is_literal = True
140+
141+
# If comment markup is enabled, don't reflow any comment block which matches
142+
# this (regex) pattern. Default is `None` (disabled).
143+
literal_comment_pattern = '^[##]+'
144+
145+
# Regular expression to match preformat fences in comments default=
146+
# ``r'^\s*([`~]{3}[`~]*)(.*)$'``
147+
ruler_pattern = '^\s*([`~]{3}[`~]*)(.*)$'
148+
149+
# Regular expression to match rulers in comments default=
150+
# ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'``
151+
ruler_pattern = '^\s*[^\w\s]{3}.*[^\w\s]{3}$'
152+
153+
# If a comment line matches starts with this pattern then it is explicitly a
154+
# trailing comment for the preceeding argument. Default is '#<'
155+
explicit_trailing_pattern = '#<'
156+
157+
# If a comment line starts with at least this many consecutive hash
158+
# characters, then don't lstrip() them off. This allows for lazy hash rulers
159+
# where the first hash char is not separated by space
160+
hashruler_min_length = 10
161+
162+
# If true, then insert a space between the first hash char and remaining hash
163+
# chars in a hash ruler, and normalize its length to fill the column
164+
canonicalize_hashrulers = False
165+
166+
# enable comment markup parsing and reflow
167+
enable_markup = True
168+
169+
# ----------------------------
170+
# Options affecting the linter
171+
# ----------------------------
172+
with section("lint"):
173+
174+
# a list of lint codes to disable
175+
disabled_codes = []
176+
177+
# regular expression pattern describing valid function names
178+
function_pattern = '[0-9a-z_]+'
179+
180+
# regular expression pattern describing valid macro names
181+
macro_pattern = '[0-9A-Z_]+'
182+
183+
# regular expression pattern describing valid names for variables with global
184+
# (cache) scope
185+
global_var_pattern = '[A-Z][0-9A-Z_]+'
186+
187+
# regular expression pattern describing valid names for variables with global
188+
# scope (but internal semantic)
189+
internal_var_pattern = '_[A-Z][0-9A-Z_]+'
190+
191+
# regular expression pattern describing valid names for variables with local
192+
# scope
193+
local_var_pattern = '[a-z][a-z0-9_]+'
194+
195+
# regular expression pattern describing valid names for privatedirectory
196+
# variables
197+
private_var_pattern = '_[0-9a-z_]+'
198+
199+
# regular expression pattern describing valid names for public directory
200+
# variables
201+
public_var_pattern = '[A-Z][0-9A-Z_]+'
202+
203+
# regular expression pattern describing valid names for function/macro
204+
# arguments and loop variables.
205+
argument_var_pattern = '[a-z][a-z0-9_]+'
206+
207+
# regular expression pattern describing valid names for keywords used in
208+
# functions or macros
209+
keyword_pattern = '[A-Z][0-9A-Z_]+'
210+
211+
# In the heuristic for C0201, how many conditionals to match within a loop in
212+
# before considering the loop a parser.
213+
max_conditionals_custom_parser = 2
214+
215+
# Require at least this many newlines between statements
216+
min_statement_spacing = 1
217+
218+
# Require no more than this many newlines between statements
219+
max_statement_spacing = 2
220+
max_returns = 6
221+
max_branches = 12
222+
max_arguments = 5
223+
max_localvars = 15
224+
max_statements = 50
225+
226+
# -------------------------------
227+
# Options affecting file encoding
228+
# -------------------------------
229+
with section("encode"):
230+
231+
# If true, emit the unicode byte-order mark (BOM) at the start of the file
232+
emit_byteorder_mark = False
233+
234+
# Specify the encoding of the input file. Defaults to utf-8
235+
input_encoding = 'utf-8'
236+
237+
# Specify the encoding of the output file. Defaults to utf-8. Note that cmake
238+
# only claims to support utf-8 so be careful when using anything else
239+
output_encoding = 'utf-8'
240+
241+
# -------------------------------------
242+
# Miscellaneous configurations options.
243+
# -------------------------------------
244+
with section("misc"):
245+
246+
# A dictionary containing any per-command configuration overrides. Currently
247+
# only `command_case` is supported.
248+
per_command = {}
249+

.github/workflows/clang_format.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

.github/workflows/format.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Formatting via cmake- and clang-format
2+
3+
# only trigger this action on specific events
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
10+
jobs:
11+
format:
12+
runs-on: ubuntu-24.04
13+
steps:
14+
# checkout repository
15+
- name: "Checkout PLSSVM"
16+
uses: actions/[email protected]
17+
with:
18+
path: PLSSVM
19+
# install dependencies
20+
- name: "Dependencies"
21+
run: |
22+
sudo apt install libomp-dev clang-format
23+
pip install "git+https://github.com/vancraar/cmake_format@master"
24+
# install new CMake version
25+
- name: "Install cmake 3.31.0"
26+
uses: lukka/[email protected]
27+
# configure project via CMake
28+
- name: "Configure"
29+
run: |
30+
cd PLSSVM
31+
cmake --preset all -DPLSSVM_TARGET_PLATFORMS="cpu" -DPLSSVM_ENABLE_FORMATTING=ON
32+
# check source file formatting
33+
- name: "Check source file formatting via clang-format"
34+
run: |
35+
set +e
36+
cd PLSSVM
37+
cmake --build --preset all --target check-clang-format
38+
status=$?
39+
if [ $status -ne 0 ]; then
40+
echo "clang-format formatting errors found!"
41+
cmake --build --preset all --target clang-format > clang-format-patch.txt 2>&1
42+
exit $status
43+
else
44+
echo "No clang-format formatting errors found!"
45+
fi
46+
# upload the clang-format git patch, if available
47+
- name: "Upload clang-format patch"
48+
if: always()
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: clang-format-patch
52+
path: PLSSVM/clang-format-patch.txt
53+
if-no-files-found: ignore
54+
# check CMake formatting
55+
- name: "Check CMake formatting via cmake-format"
56+
run: |
57+
set +e
58+
cd PLSSVM
59+
cmake --build --preset all --target check-cmake-format
60+
status=$?
61+
if [ $status -ne 0 ]; then
62+
echo "cmake-format formatting errors found!"
63+
cmake --build --preset all --target cmake-format > cmake-format-patch.txt 2>&1
64+
exit $status
65+
else
66+
echo "No cmake-format formatting errors found!"
67+
fi
68+
# upload the cmake-format git patch, if available
69+
- name: "Upload cmake-format patch"
70+
if: always()
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: cmake-format-patch
74+
path: PLSSVM/cmake-format-patch.txt
75+
if-no-files-found: ignore

0 commit comments

Comments
 (0)