Skip to content

Commit f3dfc8e

Browse files
Levi ArmstrongLevi-Armstrong
Levi Armstrong
authored andcommitted
Add cmake format
1 parent c87a94f commit f3dfc8e

File tree

32 files changed

+1580
-575
lines changed

32 files changed

+1580
-575
lines changed

.cmake-format

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

.github/workflows/benchmarking.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
OS_CODE_NAME: focal,
1717
ROS_DISTRO: noetic,
1818
ROS_REPO: main,
19-
UPSTREAM_WORKSPACE: 'dependencies.rosinstall'
19+
UPSTREAM_WORKSPACE: 'dependencies.rosinstall',
2020
ROSDEP_SKIP_KEYS: "bullet ros_industrial_cmake_boilerplate fcl iwyu",
2121
DOCKER_IMAGE: "rosindustrial/tesseract:noetic",
2222
CCACHE_DIR: "/home/runner/work/tesseract/tesseract/Focal-Benchmark/.ccache",

.github/workflows/cmake_format.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: CMake-Format
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
schedule:
9+
- cron: '0 5 * * *'
10+
11+
jobs:
12+
cmake_lang:
13+
name: Format
14+
runs-on: ubuntu-20.04
15+
steps:
16+
- uses: actions/checkout@v1
17+
18+
- name: Run CMake Lang Format Check
19+
run: |
20+
sudo pip3 install cmakelang
21+
./.run-cmake-format
22+
output=$(git diff)
23+
if [ -n "$output" ]; then exit 1; else exit 0; fi

.run-cmake-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
find . \( -name CMakeLists.txt -o -name \*.cmake \) -exec cmake-format -i {} \;

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Linux (Focal) | [![Build Status](https://github.com/ros-industrial-consor
1010
Linux (Bionic) | [![Build Status](https://github.com/ros-industrial-consortium/tesseract/workflows/Bionic-Build/badge.svg)](https://github.com/ros-industrial-consortium/tesseract/actions)
1111
Windows | [![Build Status](https://github.com/ros-industrial-consortium/tesseract/workflows/Windows-Noetic-Build/badge.svg)](https://github.com/ros-industrial-consortium/tesseract/actions)
1212
Lint (Clang-Format) | [![Build Status](https://github.com/ros-industrial-consortium/tesseract/workflows/Clang-Format/badge.svg)](https://github.com/ros-industrial-consortium/tesseract/actions)
13+
Lint (CMake-Format) | [![Build Status](https://github.com/ros-industrial-consortium/tesseract/workflows/CMake-Format/badge.svg)](https://github.com/ros-industrial-consortium/tesseract/actions)
1314
Lint (Clang-Tidy) | [![Build Status](https://github.com/ros-industrial-consortium/tesseract/workflows/Clang-Tidy/badge.svg)](https://github.com/ros-industrial-consortium/tesseract/actions)
1415
Lint (CodeCov) | [![Build Status](https://github.com/ros-industrial-consortium/tesseract/workflows/CodeCov/badge.svg)](https://github.com/ros-industrial-consortium/tesseract/actions)
1516

0 commit comments

Comments
 (0)