Skip to content

Commit f324ac1

Browse files
committed
cmake formatting
This is still using cmake-format from cmakelang, despite it not being active in 4 years. Will consider switching to something else.
1 parent b2bf73b commit f324ac1

16 files changed

+263
-180
lines changed

.cmake-format.yaml

Lines changed: 111 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,113 @@
1-
bullet_char: '*'
2-
dangle_parens: true
3-
enum_char: .
4-
line_ending: unix
5-
line_width: 80
6-
max_pargs_hwrap: 3
1+
disable : false
2+
3+
# How wide to allow formatted cmake files
4+
line_width: 110
5+
6+
# How many spaces to tab for indent
7+
tab_size: 4
8+
9+
# If true, lines are indented using tab characters (utf-8 0x09) instead of
10+
# <tab_size> space characters (utf-8 0x20). In cases where the layout would
11+
# require a fractional tab character, the behavior of the fractional
12+
# indentation is governed by <fractional_tab_policy>
13+
use_tabchars: false
14+
15+
# If an argument group contains more than this many sub-groups (parg or kwarg
16+
# groups) then force it to a vertical layout.
17+
max_subgroups_hwrap: 2
18+
19+
# If a positional argument group contains more than this many arguments, then
20+
# force it to a vertical layout.
21+
max_pargs_hwrap: 6
22+
23+
# If a cmdline positional group consumes more than this many lines without
24+
# nesting, then invalidate the layout (and nest)
25+
max_rows_cmdline: 2
26+
27+
# If true, separate flow control names from their parentheses with a space
728
separate_ctrl_name_with_space: true
29+
30+
# If true, separate function names from parentheses with a space
831
separate_fn_name_with_space: false
9-
tab_size: 4
32+
33+
# If a statement is wrapped to more than one line, than dangle the closing
34+
# parenthesis on its own line.
35+
dangle_parens: true
36+
37+
# If the trailing parenthesis must be 'dangled' on its own line, then align it
38+
# to this reference: `prefix`: the start of the statement, `prefix-indent`:
39+
# the start of the statement, plus one indentation level, `child`: align to
40+
# the column of the arguments
41+
dangle_align: "prefix"
42+
43+
# If the statement spelling length (including space and parenthesis) is smaller
44+
# than this amount, then force reject nested layouts.
45+
min_prefix_chars: 4
46+
47+
# If the statement spelling length (including space and parenthesis) is larger
48+
# than the tab width by more than this amount, then force reject un-nested
49+
# layouts.
50+
max_prefix_chars: 10
51+
52+
# If a candidate layout is wrapped horizontally but it exceeds this many lines,
53+
# then reject the layout.
54+
max_lines_hwrap: 2
55+
56+
# What style line endings to use in the output.
57+
line_ending: 'unix'
58+
59+
# Format command names consistently as 'lower' or 'upper' case
60+
command_case: 'canonical' # TODO
61+
62+
# Format keywords consistently as 'lower' or 'upper' case
63+
keyword_case: 'unchanged' # TODO
64+
65+
# A list of command names which should always be wrapped
66+
always_wrap: []
67+
68+
# If true, the argument lists which are known to be sortable will be sorted
69+
# lexicographicall
70+
enable_sort: true
71+
72+
# If true, the parsers may infer whether or not an argument list is sortable
73+
# (without annotation).
74+
autosort: false
75+
76+
# By default, if cmake-format cannot successfully fit everything into the
77+
# desired linewidth it will apply the last, most agressive attempt that it
78+
# made. If this flag is True, however, cmake-format will print error, exit with
79+
# non-zero status code, and write-out nothing
80+
require_valid_layout: false
81+
82+
# ------------------------------------------------
83+
# Options affecting comment reflow and formatting.
84+
# ------------------------------------------------
85+
86+
# What character to use for bulleted lists
87+
bullet_char: '*'
88+
89+
# What character to use as punctuation after numerals in an enumerated list
90+
enum_char: '.'
91+
92+
# If comment markup is enabled, don't reflow the first comment block in each
93+
# listfile. Use this to preserve formatting of your copyright/license
94+
# statements.
95+
first_comment_is_literal: false
96+
97+
# If comment markup is enabled, don't reflow any comment block which matches
98+
# this (regex) pattern. Default is `None` (disabled).
99+
literal_comment_pattern: null
100+
101+
explicit_trailing_pattern: "#<"
102+
103+
# If a comment line starts with at least this many consecutive hash characters,
104+
# then don't lstrip() them off. This allows for lazy hash rulers where the
105+
# first hash char is not separated by space
106+
hashruler_min_length: 10
107+
108+
# If true, then insert a space between the first hash char and remaining hash
109+
# chars in a hash ruler, and normalize its length to fill the column
110+
canonicalize_hashrulers: true
111+
112+
# enable comment markup parsing and reflow
113+
enable_markup: true

CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ cmake_minimum_required(VERSION 3.25)
22
include(cmake/setup_pkg.cmake)
33
project(
44
${THIS_PROJECT_NAME}
5-
VERSION ${THIS_PROJECT_VERSION}
6-
${THIS_PROJECT_DESCRIPTION}
7-
${THIS_PROJECT_HOMEPAGE_URL}
5+
VERSION ${THIS_PROJECT_VERSION} ${THIS_PROJECT_DESCRIPTION} ${THIS_PROJECT_HOMEPAGE_URL}
86
LANGUAGES CXX
97
)
108

@@ -23,6 +21,6 @@ include(cmake/coverage.cmake)
2321
add_subdirectory(src)
2422
add_subdirectory(project_config)
2523

26-
if(BUILD_TESTING)
24+
if (BUILD_TESTING)
2725
add_subdirectory(tests)
28-
endif()
26+
endif ()

cmake/always_include.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
function(target_always_include target access file)
1+
function (target_always_include target access file)
22
if (MSVC)
33
target_compile_options(${target} ${access} "/FI${file}")
4-
else()
4+
else ()
55
target_compile_options(${target} ${access} "-include${file}")
6-
endif()
7-
endfunction()
6+
endif ()
7+
endfunction ()

cmake/cache.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ function (_enable_cache)
88
find_program(cache_bin ${CACHE_PROGRAM})
99
if (cache_bin)
1010
message(STATUS "${CACHE_PROGRAM} found and enabled")
11-
set(CMAKE_CXX_COMPILER_LAUNCHER ${cache_bin} CACHE STRING "cmake compiler launcher")
11+
set(CMAKE_CXX_COMPILER_LAUNCHER
12+
${cache_bin}
13+
CACHE STRING "cmake compiler launcher"
14+
)
1215
else ()
1316
message(WARNING "${CACHE_PROGRAM} is enabled but was not found. Not using it")
1417
endif ()

cmake/compile_commands.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ function (link_compile_commands name)
88

99
set(cmd_target "${CMAKE_CURRENT_LIST_DIR}/${name}")
1010
add_custom_command(
11-
OUTPUT ${cmd_target}
12-
COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_BINARY_DIR}/${name}"
13-
"${CMAKE_CURRENT_LIST_DIR}/${name}"
11+
OUTPUT ${cmd_target} #
12+
COMMAND ${CMAKE_COMMAND} -E #
13+
create_symlink "${CMAKE_BINARY_DIR}/${name}" "${CMAKE_CURRENT_LIST_DIR}/${name}"
1414
)
1515

1616
add_custom_target(${_dir}_${name} ALL DEPENDS ${cmd_target})

cmake/compiler_warnings.cmake

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ function (set_target_warnings project_name #[[access]])
88
macro (gnu_add_no_error warn_list warn)
99
list(APPEND ${warn_list} "-W${warn}")
1010
list(APPEND ${warn_list} "-Wno-error=${warn}")
11-
endmacro()
11+
endmacro ()
1212

1313
optional_args(acc DEFAULTS "PRIVATE" ARGS ${ARGN})
1414
set(MSVC_WARNINGS
1515
/W4 # Baseline reasonable warnings
1616
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data
1717
/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
1818
/w14263 # 'function': member function does not override any base class virtual member function
19-
/w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may
20-
# not be destructed correctly
19+
/w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this
20+
# class may not be destructed correctly
2121
/w14287 # 'operator': unsigned/negative constant mismatch
22-
/we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside
23-
# the for-loop scope
22+
/we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is
23+
# used outside the for-loop scope
2424
/w14296 # 'operator': expression is always 'boolean_value'
2525
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
2626
/w14545 # expression before comma evaluates to a function which is missing an argument list
@@ -30,19 +30,21 @@ function (set_target_warnings project_name #[[access]])
3030
/w14555 # expression has no effect; expected expression with side- effect
3131
/w14619 # pragma warning: there is no warning number 'number'
3232
/w14640 # Enable warning on thread un-safe static member initialization
33-
/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior.
33+
/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime
34+
# behavior.
3435
/w14905 # wide string literal cast to 'LPSTR'
3536
/w14906 # string literal cast to 'LPWSTR'
36-
/w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied
37+
/w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly
38+
# applied
3739
/permissive- # standards conformance mode for MSVC compiler.
3840
)
3941

4042
set(COMMON_WARNINGS
4143
-Wall
4244
-Wextra # reasonable and standard
4345
-Wshadow # warn the user if a variable declaration shadows one from a parent context
44-
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps
45-
# catch hard to track down memory errors
46+
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor.
47+
# This helps catch hard to track down memory errors
4648
-Wold-style-cast # warn for c-style casts
4749
-Wcast-align # warn for potential performance problem casts
4850
-Wunused # warn on anything being unused
@@ -87,9 +89,8 @@ function (set_target_warnings project_name #[[access]])
8789
-Wunused-const-variable=1 # using level 1, because default (set above) also accounts for headers
8890
)
8991

90-
set(CLANG_WARNINGS
91-
${COMMON_WARNINGS}
92-
-Wused-but-marked-unused # this is only for [[gnu::unused]], not [[maybe_unused]]
92+
set(CLANG_WARNINGS #
93+
${COMMON_WARNINGS} -Wused-but-marked-unused #< this is only for [[gnu::unused]], not [[maybe_unused]]
9394
)
9495
gnu_add_no_error(CLANG_WARNINGS unused-private-field)
9596
gnu_add_no_error(CLANG_WARNINGS unused-comparison)

cmake/coverage.cmake

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
include(${CMAKE_SOURCE_DIR}/cmake/find_with_nix.cmake)
2-
function(target_add_coverage target access)
3-
if(NOT ENABLE_COVERAGE)
4-
return ()
5-
endif()
6-
if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"))
2+
function (target_add_coverage target access)
3+
if (NOT ENABLE_COVERAGE)
4+
return()
5+
endif ()
6+
if (NOT (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"))
77
message(FATAL_ERROR "Can only run coverage on GNU or Clang compilers")
88
return()
9-
endif()
10-
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
9+
endif ()
10+
if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
1111
message(FATAL_ERROR "Can only run coverage with build type Debug, got ${CMAKE_BUILD_TYPE}")
1212
return()
13-
endif()
13+
endif ()
1414
message(STATUS "Building with coverage")
1515
target_compile_options(${target} ${access} -O0 -g --coverage)
1616
target_link_options(${target} ${access} --coverage)
@@ -19,38 +19,35 @@ function(target_add_coverage target access)
1919

2020
set(OBJDIR ${CMAKE_BINARY_DIR}/src/CMakeFiles/${OBJLIB_NAME}.dir/)
2121

22-
add_custom_target(coverage
22+
add_custom_target(
23+
coverage
2324
COMMENT "Generating coverage report"
2425
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
25-
26-
COMMAND ${LCOV_EXE}
27-
--directory ${OBJDIR}
28-
--zerocounters
29-
30-
COMMAND ctest --test-dir ${CMAKE_BINARY_DIR}/tests --output-on-failure
31-
32-
COMMAND ${LCOV_EXE}
33-
--ignore-errors inconsistent
34-
--ignore-errors unused
35-
--capture
36-
--directory ${OBJDIR}
37-
--base-directory ${CMAKE_SOURCE_DIR}/src
38-
--output-file ${OBJDIR}/coverage.info
39-
40-
COMMAND ${LCOV_EXE}
41-
--ignore-errors inconsistent
42-
--ignore-errors unused
43-
--remove ${OBJDIR}/coverage.info
44-
/usr/**/*
45-
${FETCHCONTENT_BASE_DIR}/**/*
46-
${CMAKE_BINARY_DIR}/vcpkg_installed/**/*
47-
--output-file ${OBJDIR}/coverage.cleaned.info
48-
49-
COMMAND ${LCOV_EXE}
50-
--list ${OBJDIR}/coverage.cleaned.info
51-
26+
COMMAND #
27+
${LCOV_EXE} --directory ${OBJDIR} --zerocounters
28+
COMMAND #
29+
ctest --test-dir ${CMAKE_BINARY_DIR}/tests --output-on-failure
30+
COMMAND
31+
${LCOV_EXE} #
32+
--ignore-errors inconsistent #
33+
--ignore-errors unused #
34+
--capture #
35+
--directory ${OBJDIR} #
36+
--base-directory ${CMAKE_SOURCE_DIR}/src #
37+
--output-file ${OBJDIR}/coverage.info
38+
COMMAND
39+
${LCOV_EXE} --ignore-errors inconsistent #
40+
--ignore-errors unused #
41+
--remove ${OBJDIR}/coverage.info #
42+
/usr/**/* #
43+
${FETCHCONTENT_BASE_DIR}/**/* #
44+
${CMAKE_BINARY_DIR}/vcpkg_installed/**/* #
45+
--output-file ${OBJDIR}/coverage.cleaned.info
46+
COMMAND #
47+
${LCOV_EXE} --list ${OBJDIR}/coverage.cleaned.info
5248
VERBATIM
53-
)
54-
add_dependencies(coverage ${TEST_NAME})
49+
)
50+
51+
add_dependencies(coverage ${TEST_NAME})
5552

56-
endfunction()
53+
endfunction ()

cmake/find_with_nix.cmake

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,26 @@
77
NIX_NAME <name> argument can be used if the nixpkgs version of the program
88
differs from the one specified by the regular name argument.
99
]]
10-
function(find_program_nix var name)
10+
function (find_program_nix var name)
1111
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "NIX_NAME" "")
1212
list(REMOVE_ITEM ARG_UNPARSED_ARGUMENTS "REQUIRED")
1313
find_program(${var} ${name} ${ARG_UNPARSED_ARGUMENTS})
1414
if (NOT ("${${var}}" STREQUAL "${var}-NOTFOUND"))
1515
return()
16-
endif()
17-
if("REQUIRED" IN_LIST "${ARGV}")
16+
endif ()
17+
if ("REQUIRED" IN_LIST "${ARGV}")
1818
find_program(NIX_EXE nix REQUIRED)
19-
else()
19+
else ()
2020
find_program(NIX_EXE nix)
21-
if(NIX_EXE-NOTFOUND)
21+
if (NIX_EXE-NOTFOUND)
2222
return()
23-
endif()
24-
endif()
25-
if(NOT ARG_NIX_NAME)
23+
endif ()
24+
endif ()
25+
if (NOT ARG_NIX_NAME)
2626
set(ARG_NIX_NAME ${name})
27-
endif()
28-
set(${var} "${NIX_EXE} run nixpkgs#${ARG_NIX_NAME} -- " CACHE STRING "nix wrapped ${name} executable" FORCE)
29-
endfunction()
27+
endif ()
28+
set(${var}
29+
"${NIX_EXE} run nixpkgs#${ARG_NIX_NAME} -- "
30+
CACHE STRING "nix wrapped ${name} executable" FORCE
31+
)
32+
endfunction ()

cmake/macro_prefix.cmake

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
include(${CMAKE_SOURCE_DIR}/cmake/misc.cmake)
22

3-
function(set_macro_prefix project_name #[[access]])
4-
if(ENABLE_COVERAGE)
3+
function (set_macro_prefix project_name #[[access]])
4+
if (ENABLE_COVERAGE)
55
return()
6-
endif()
6+
endif ()
77
if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
88
optional_args(acc DEFAULTS "PRIVATE" ARGS ${ARGN})
99

10-
target_compile_options(${project_name} ${acc_0}
10+
target_compile_options(
11+
${project_name} ${acc_0} #
1112
"-fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=${MACRO_PREFIX}"
1213
"-ffile-prefix-map=${CMAKE_SOURCE_DIR}/=${MACRO_PREFIX}"
1314
)
14-
endif()
15-
endfunction()
15+
endif ()
16+
endfunction ()

0 commit comments

Comments
 (0)