Skip to content

Commit 3d0db46

Browse files
committed
added a cmake-format
1 parent d167782 commit 3d0db46

File tree

2 files changed

+146
-28
lines changed

2 files changed

+146
-28
lines changed

.cmake-format.yaml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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
28+
separate_ctrl_name_with_space: true
29+
30+
# If true, separate function names from parentheses with a space
31+
separate_fn_name_with_space: false
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

tests/CMakeLists.txt

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ include(Catch)
55
include(CheckSourceCompiles)
66

77
set(cxx_17_files
8-
${CMAKE_CURRENT_SOURCE_DIR}/add_noexcept.cpp
9-
${CMAKE_CURRENT_SOURCE_DIR}/check.cpp
10-
${CMAKE_CURRENT_SOURCE_DIR}/constexpr_hash.cpp
11-
${CMAKE_CURRENT_SOURCE_DIR}/defer.cpp
12-
${CMAKE_CURRENT_SOURCE_DIR}/pack_loops.cpp
13-
${CMAKE_CURRENT_SOURCE_DIR}/breakpoint.cpp
8+
${CMAKE_CURRENT_SOURCE_DIR}/add_noexcept.cpp #
9+
${CMAKE_CURRENT_SOURCE_DIR}/check.cpp #
10+
${CMAKE_CURRENT_SOURCE_DIR}/constexpr_hash.cpp #
11+
${CMAKE_CURRENT_SOURCE_DIR}/defer.cpp #
12+
${CMAKE_CURRENT_SOURCE_DIR}/pack_loops.cpp #
13+
${CMAKE_CURRENT_SOURCE_DIR}/breakpoint.cpp #
1414
)
1515
set(cxx_20_files
1616
${cxx_17_files}
@@ -30,39 +30,42 @@ set(cxx_20_files
3030
)
3131

3232
set(cxx_23_files
33-
${cxx_20_files}
34-
${CMAKE_CURRENT_SOURCE_DIR}/err.cpp
35-
${CMAKE_CURRENT_SOURCE_DIR}/switchboard.cpp
36-
${CMAKE_CURRENT_SOURCE_DIR}/traced_error.cpp
33+
${cxx_20_files} #
34+
${CMAKE_CURRENT_SOURCE_DIR}/err.cpp #
35+
${CMAKE_CURRENT_SOURCE_DIR}/switchboard.cpp #
36+
${CMAKE_CURRENT_SOURCE_DIR}/traced_error.cpp #
3737
)
3838

3939
block(SCOPE_FOR VARIABLES)
40-
if(MSVC)
41-
set(CMAKE_REQUIRED_FLAGS /Zc:__cplusplus /std:c++latest)
42-
else()
43-
set(CMAKE_REQUIRED_FLAGS -std=c++23)
44-
endif()
45-
check_source_compiles(CXX "
40+
if (MSVC)
41+
set(CMAKE_REQUIRED_FLAGS /Zc:__cplusplus /std:c++latest)
42+
else ()
43+
set(CMAKE_REQUIRED_FLAGS -std=c++23)
44+
endif ()
45+
check_source_compiles(
46+
CXX
47+
"
4648
int main(void){
4749
static_assert(__cplusplus >= 202302L);
4850
}
4951
"
50-
HAS_CXX_23)
52+
HAS_CXX_23
53+
)
5154
endblock()
5255

53-
function(setup_target target)
56+
function (setup_target target)
5457
target_link_libraries(${target} PRIVATE UT::all)
5558
set_target_warnings(${target})
5659
target_link_libraries(${target} PRIVATE Catch2::Catch2WithMain)
5760
target_precompile_headers(${target} PRIVATE <catch.hpp>)
58-
if(NOT MSVC)
61+
if (NOT MSVC)
5962
target_compile_options(${target} PUBLIC "-fsanitize=address" "-Og" "-g")
6063
target_link_options(${target} PUBLIC "-fsanitize=address" "-lg")
61-
else()
64+
else ()
6265
target_compile_options(${target} PUBLIC "/Zc:__cplusplus")
63-
endif()
66+
endif ()
6467
catch_discover_tests(${target})
65-
endfunction()
68+
endfunction ()
6669

6770
add_executable(libut_tests_17 ${cxx_17_files})
6871
add_executable(libut_tests_20 ${cxx_20_files})
@@ -73,14 +76,16 @@ target_compile_features(libut_tests_20 PUBLIC cxx_std_20)
7376
setup_target(libut_tests_17)
7477
setup_target(libut_tests_20)
7578

76-
if(HAS_CXX_23)
79+
if (HAS_CXX_23)
7780
add_executable(libut_tests_23 ${cxx_23_files})
7881
target_compile_features(libut_tests_23 PUBLIC cxx_std_23)
7982
setup_target(libut_tests_23)
80-
if(NOT MSVC)
83+
if (NOT MSVC)
8184
target_link_libraries(libut_tests_23 PUBLIC stdc++exp)
82-
endif()
83-
else()
85+
endif ()
86+
else ()
8487
get_filename_component(compiler_name ${CMAKE_CXX_COMPILER} NAME)
85-
message(WARNING "${compiler_name} ${CMAKE_CXX_COMPILER_VERSION} does not support C++23, tests will not run")
86-
endif()
88+
message(
89+
WARNING "${compiler_name} ${CMAKE_CXX_COMPILER_VERSION} does not support C++23, tests will not run"
90+
)
91+
endif ()

0 commit comments

Comments
 (0)