Skip to content

Commit cf77a10

Browse files
authored
style: Adopt cmake-format from xrpld (#2938)
1 parent 437168a commit cf77a10

30 files changed

+827
-897
lines changed

.cmake-format.yaml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@ _help_parse: Options affecting listfile parsing
22
parse:
33
_help_additional_commands:
44
- Specify structure for custom cmake functions
5-
additional_commands:
6-
foo:
7-
flags:
8-
- BAR
9-
- BAZ
10-
kwargs:
11-
HEADERS: "*"
12-
SOURCES: "*"
13-
DEPENDS: "*"
145
_help_override_spec:
156
- Override configurations per-command where available
167
override_spec: {}
@@ -30,7 +21,7 @@ format:
3021
line_width: 120
3122
_help_tab_size:
3223
- How many spaces to tab for indent
33-
tab_size: 2
24+
tab_size: 4
3425
_help_use_tabchars:
3526
- If true, lines are indented using tab characters (utf-8
3627
- 0x09) instead of <tab_size> space characters (utf-8 0x20).
@@ -70,19 +61,19 @@ format:
7061
_help_dangle_parens:
7162
- If a statement is wrapped to more than one line, than dangle
7263
- the closing parenthesis on its own line.
73-
dangle_parens: true
64+
dangle_parens: false
7465
_help_dangle_align:
7566
- If the trailing parenthesis must be 'dangled' on its on
7667
- "line, then align it to this reference: `prefix`: the start"
77-
- "of the statement, `prefix-indent`: the start of the"
78-
- "statement, plus one indentation level, `child`: align to"
68+
- "of the statement, `prefix-indent`: the start of the"
69+
- "statement, plus one indentation level, `child`: align to"
7970
- the column of the arguments
8071
dangle_align: prefix
8172
_help_min_prefix_chars:
8273
- If the statement spelling length (including space and
8374
- parenthesis) is smaller than this amount, then force reject
8475
- nested layouts.
85-
min_prefix_chars: 4
76+
min_prefix_chars: 18
8677
_help_max_prefix_chars:
8778
- If the statement spelling length (including space and
8879
- parenthesis) is larger than the tab width by more than this
@@ -127,7 +118,7 @@ _help_markup: Options affecting comment reflow and formatting.
127118
markup:
128119
_help_bullet_char:
129120
- What character to use for bulleted lists
130-
bullet_char: "*"
121+
bullet_char: "-"
131122
_help_enum_char:
132123
- What character to use as punctuation after numerals in an
133124
- enumerated list

CMakeLists.txt

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
cmake_minimum_required(VERSION 3.20)
22

33
project(clio VERSION ${CLIO_VERSION} HOMEPAGE_URL "https://github.com/XRPLF/clio"
4-
DESCRIPTION "An XRP Ledger API Server"
5-
)
4+
DESCRIPTION "An XRP Ledger API Server")
65

76
# =========================== Options ====================================== #
87
option(verbose "Verbose build" FALSE)
@@ -36,7 +35,7 @@ target_compile_features(clio_options INTERFACE cxx_std_23) # Clio needs c++23 bu
3635
target_include_directories(clio_options INTERFACE ${CMAKE_SOURCE_DIR}/src)
3736

3837
if (verbose)
39-
set(CMAKE_VERBOSE_MAKEFILE TRUE)
38+
set(CMAKE_VERBOSE_MAKEFILE TRUE)
4039
endif ()
4140

4241
# Clio tweaks and checks
@@ -58,36 +57,36 @@ add_subdirectory(src)
5857
add_subdirectory(tests)
5958

6059
if (benchmark)
61-
add_subdirectory(benchmarks)
60+
add_subdirectory(benchmarks)
6261
endif ()
6362

6463
# Enable selected sanitizer if enabled via `san`
6564
if (san)
66-
set(SUPPORTED_SANITIZERS "address" "thread" "memory" "undefined")
67-
if (NOT san IN_LIST SUPPORTED_SANITIZERS)
68-
message(FATAL_ERROR "Error: Unsupported sanitizer '${san}'. Supported values are: ${SUPPORTED_SANITIZERS}.")
69-
endif ()
70-
71-
# Sanitizers recommend minimum of -O1 for reasonable performance so we enable it for debug builds
72-
set(SAN_OPTIMIZATION_FLAG "")
73-
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
74-
set(SAN_OPTIMIZATION_FLAG -O1)
75-
endif ()
76-
target_compile_options(clio_options INTERFACE ${SAN_OPTIMIZATION_FLAG} ${SAN_FLAG} -fno-omit-frame-pointer)
77-
78-
target_link_libraries(clio_options INTERFACE ${SAN_FLAG} ${SAN_LIB})
65+
set(SUPPORTED_SANITIZERS "address" "thread" "memory" "undefined")
66+
if (NOT san IN_LIST SUPPORTED_SANITIZERS)
67+
message(FATAL_ERROR "Error: Unsupported sanitizer '${san}'. Supported values are: ${SUPPORTED_SANITIZERS}.")
68+
endif ()
69+
70+
# Sanitizers recommend minimum of -O1 for reasonable performance so we enable it for debug builds
71+
set(SAN_OPTIMIZATION_FLAG "")
72+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
73+
set(SAN_OPTIMIZATION_FLAG -O1)
74+
endif ()
75+
target_compile_options(clio_options INTERFACE ${SAN_OPTIMIZATION_FLAG} ${SAN_FLAG} -fno-omit-frame-pointer)
76+
77+
target_link_libraries(clio_options INTERFACE ${SAN_FLAG} ${SAN_LIB})
7978
endif ()
8079

8180
# Generate `docs` target for doxygen documentation if enabled Note: use `make docs` to generate the documentation
8281
if (docs)
83-
add_subdirectory(docs)
82+
add_subdirectory(docs)
8483
endif ()
8584

8685
include(install/install)
8786
if (package)
88-
include(ClioPackage)
87+
include(ClioPackage)
8988
endif ()
9089

9190
if (snapshot)
92-
add_subdirectory(tools/snapshot)
91+
add_subdirectory(tools/snapshot)
9392
endif ()

benchmarks/CMakeLists.txt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
add_executable(clio_benchmark)
22

3-
target_sources(
4-
clio_benchmark
5-
PRIVATE # Common
6-
Main.cpp
7-
Playground.cpp
8-
# ExecutionContext
9-
util/async/ExecutionContextBenchmarks.cpp
10-
# Logger
11-
util/log/LoggerBenchmark.cpp
12-
# WorkQueue
13-
rpc/WorkQueueBenchmarks.cpp
14-
)
3+
target_sources(clio_benchmark
4+
PRIVATE # Common
5+
Main.cpp
6+
Playground.cpp
7+
# ExecutionContext
8+
util/async/ExecutionContextBenchmarks.cpp
9+
# Logger
10+
util/log/LoggerBenchmark.cpp
11+
# WorkQueue
12+
rpc/WorkQueueBenchmarks.cpp)
1513

1614
include(deps/gbench)
1715

cmake/Ccache.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
find_program(CCACHE_PATH "ccache")
22
if (CCACHE_PATH)
3-
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PATH}")
4-
message(STATUS "Using ccache: ${CCACHE_PATH}")
3+
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PATH}")
4+
message(STATUS "Using ccache: ${CCACHE_PATH}")
55
endif ()

cmake/CheckCompiler.cmake

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
2-
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16)
3-
message(FATAL_ERROR "Clang 16+ required for building clio")
4-
endif ()
5-
set(is_clang TRUE)
2+
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16)
3+
message(FATAL_ERROR "Clang 16+ required for building clio")
4+
endif ()
5+
set(is_clang TRUE)
66
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
7-
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15)
8-
message(FATAL_ERROR "AppleClang 15+ required for building clio")
9-
endif ()
10-
set(is_appleclang TRUE)
7+
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15)
8+
message(FATAL_ERROR "AppleClang 15+ required for building clio")
9+
endif ()
10+
set(is_appleclang TRUE)
1111
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
12-
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
13-
message(FATAL_ERROR "GCC 12+ required for building clio")
14-
endif ()
15-
set(is_gcc TRUE)
12+
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
13+
message(FATAL_ERROR "GCC 12+ required for building clio")
14+
endif ()
15+
set(is_gcc TRUE)
1616
else ()
17-
message(FATAL_ERROR "Supported compilers: AppleClang 15+, Clang 16+, GCC 12+")
17+
message(FATAL_ERROR "Supported compilers: AppleClang 15+, Clang 16+, GCC 12+")
1818
endif ()
1919

2020
if (san)
21-
string(TOLOWER ${san} san)
22-
set(SAN_FLAG "-fsanitize=${san}")
23-
set(SAN_LIB "")
24-
if (is_gcc)
25-
if (san STREQUAL "address")
26-
set(SAN_LIB "asan")
27-
elseif (san STREQUAL "thread")
28-
set(SAN_LIB "tsan")
29-
elseif (san STREQUAL "memory")
30-
set(SAN_LIB "msan")
31-
elseif (san STREQUAL "undefined")
32-
set(SAN_LIB "ubsan")
21+
string(TOLOWER ${san} san)
22+
set(SAN_FLAG "-fsanitize=${san}")
23+
set(SAN_LIB "")
24+
if (is_gcc)
25+
if (san STREQUAL "address")
26+
set(SAN_LIB "asan")
27+
elseif (san STREQUAL "thread")
28+
set(SAN_LIB "tsan")
29+
elseif (san STREQUAL "memory")
30+
set(SAN_LIB "msan")
31+
elseif (san STREQUAL "undefined")
32+
set(SAN_LIB "ubsan")
33+
endif ()
34+
endif ()
35+
set(_saved_CRL ${CMAKE_REQUIRED_LIBRARIES})
36+
set(CMAKE_REQUIRED_LIBRARIES "${SAN_FLAG};${SAN_LIB}")
37+
check_cxx_compiler_flag(${SAN_FLAG} COMPILER_SUPPORTS_SAN)
38+
set(CMAKE_REQUIRED_LIBRARIES ${_saved_CRL})
39+
if (NOT COMPILER_SUPPORTS_SAN)
40+
message(FATAL_ERROR "${san} sanitizer does not seem to be supported by your compiler")
3341
endif ()
34-
endif ()
35-
set(_saved_CRL ${CMAKE_REQUIRED_LIBRARIES})
36-
set(CMAKE_REQUIRED_LIBRARIES "${SAN_FLAG};${SAN_LIB}")
37-
check_cxx_compiler_flag(${SAN_FLAG} COMPILER_SUPPORTS_SAN)
38-
set(CMAKE_REQUIRED_LIBRARIES ${_saved_CRL})
39-
if (NOT COMPILER_SUPPORTS_SAN)
40-
message(FATAL_ERROR "${san} sanitizer does not seem to be supported by your compiler")
41-
endif ()
4242
endif ()

cmake/ClangTidy.cmake

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
if (lint)
22

3-
# Find clang-tidy binary
4-
if (DEFINED ENV{CLIO_CLANG_TIDY_BIN})
5-
set(_CLANG_TIDY_BIN $ENV{CLIO_CLANG_TIDY_BIN})
6-
if ((NOT EXISTS ${_CLANG_TIDY_BIN}) OR IS_DIRECTORY ${_CLANG_TIDY_BIN})
7-
message(FATAL_ERROR "$ENV{CLIO_CLANG_TIDY_BIN} no such file. Check CLIO_CLANG_TIDY_BIN env variable")
3+
# Find clang-tidy binary
4+
if (DEFINED ENV{CLIO_CLANG_TIDY_BIN})
5+
set(_CLANG_TIDY_BIN $ENV{CLIO_CLANG_TIDY_BIN})
6+
if ((NOT EXISTS ${_CLANG_TIDY_BIN}) OR IS_DIRECTORY ${_CLANG_TIDY_BIN})
7+
message(FATAL_ERROR "$ENV{CLIO_CLANG_TIDY_BIN} no such file. Check CLIO_CLANG_TIDY_BIN env variable")
8+
endif ()
9+
message(STATUS "Using clang-tidy from CLIO_CLANG_TIDY_BIN")
10+
else ()
11+
find_program(_CLANG_TIDY_BIN NAMES "clang-tidy-20" "clang-tidy" REQUIRED)
812
endif ()
9-
message(STATUS "Using clang-tidy from CLIO_CLANG_TIDY_BIN")
10-
else ()
11-
find_program(_CLANG_TIDY_BIN NAMES "clang-tidy-20" "clang-tidy" REQUIRED)
12-
endif ()
1313

14-
if (NOT _CLANG_TIDY_BIN)
15-
message(
16-
FATAL_ERROR
17-
"clang-tidy binary not found. Please set the CLIO_CLANG_TIDY_BIN environment variable or install clang-tidy."
18-
)
19-
endif ()
14+
if (NOT _CLANG_TIDY_BIN)
15+
message(FATAL_ERROR "clang-tidy binary not found. Please set the CLIO_CLANG_TIDY_BIN environment variable or install clang-tidy."
16+
)
17+
endif ()
2018

21-
# Support for https://github.com/matus-chochlik/ctcache
22-
find_program(CLANG_TIDY_CACHE_PATH NAMES "clang-tidy-cache")
23-
if (CLANG_TIDY_CACHE_PATH)
24-
set(_CLANG_TIDY_CMD "${CLANG_TIDY_CACHE_PATH};${_CLANG_TIDY_BIN}"
25-
CACHE STRING "A combined command to run clang-tidy with caching wrapper"
26-
)
27-
else ()
28-
set(_CLANG_TIDY_CMD "${_CLANG_TIDY_BIN}")
29-
endif ()
19+
# Support for https://github.com/matus-chochlik/ctcache
20+
find_program(CLANG_TIDY_CACHE_PATH NAMES "clang-tidy-cache")
21+
if (CLANG_TIDY_CACHE_PATH)
22+
set(_CLANG_TIDY_CMD "${CLANG_TIDY_CACHE_PATH};${_CLANG_TIDY_BIN}"
23+
CACHE STRING "A combined command to run clang-tidy with caching wrapper")
24+
else ()
25+
set(_CLANG_TIDY_CMD "${_CLANG_TIDY_BIN}")
26+
endif ()
3027

31-
set(CMAKE_CXX_CLANG_TIDY "${_CLANG_TIDY_CMD};--quiet")
32-
message(STATUS "Using clang-tidy: ${CMAKE_CXX_CLANG_TIDY}")
28+
set(CMAKE_CXX_CLANG_TIDY "${_CLANG_TIDY_CMD};--quiet")
29+
message(STATUS "Using clang-tidy: ${CMAKE_CXX_CLANG_TIDY}")
3330
endif ()

cmake/ClioVersion.cmake

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,41 @@
11
find_package(Git REQUIRED)
22

33
if (DEFINED ENV{GITHUB_BRANCH_NAME})
4-
set(GIT_BUILD_BRANCH $ENV{GITHUB_BRANCH_NAME})
5-
set(GIT_COMMIT_HASH $ENV{GITHUB_HEAD_SHA})
4+
set(GIT_BUILD_BRANCH $ENV{GITHUB_BRANCH_NAME})
5+
set(GIT_COMMIT_HASH $ENV{GITHUB_HEAD_SHA})
66
else ()
7-
set(GIT_COMMAND branch --show-current)
8-
execute_process(
9-
COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE GIT_BUILD_BRANCH
10-
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY
11-
)
12-
13-
set(GIT_COMMAND rev-parse HEAD)
14-
execute_process(
15-
COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE GIT_COMMIT_HASH
16-
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY
17-
)
7+
set(GIT_COMMAND branch --show-current)
8+
execute_process(COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
9+
OUTPUT_VARIABLE GIT_BUILD_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY)
10+
11+
set(GIT_COMMAND rev-parse HEAD)
12+
execute_process(COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
13+
OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY)
1814
endif ()
1915

20-
execute_process(
21-
COMMAND date +%Y%m%d%H%M%S WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE BUILD_DATE
22-
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY
23-
)
16+
execute_process(COMMAND date +%Y%m%d%H%M%S WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE BUILD_DATE
17+
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY)
2418

2519
message(STATUS "Git branch: ${GIT_BUILD_BRANCH}")
2620
message(STATUS "Git commit hash: ${GIT_COMMIT_HASH}")
2721
message(STATUS "Build date: ${BUILD_DATE}")
2822

2923
if (DEFINED ENV{FORCE_CLIO_VERSION} AND NOT "$ENV{FORCE_CLIO_VERSION}" STREQUAL "")
30-
message(STATUS "Using explicitly provided '${FORCE_CLIO_VERSION}' as Clio version")
24+
message(STATUS "Using explicitly provided '${FORCE_CLIO_VERSION}' as Clio version")
3125

32-
set(CLIO_VERSION "$ENV{FORCE_CLIO_VERSION}")
33-
set(DOC_CLIO_VERSION "$ENV{FORCE_CLIO_VERSION}")
26+
set(CLIO_VERSION "$ENV{FORCE_CLIO_VERSION}")
27+
set(DOC_CLIO_VERSION "$ENV{FORCE_CLIO_VERSION}")
3428
else ()
35-
message(STATUS "Using 'YYYYMMDDHMS-<branch>-<git short rev>' as Clio version")
29+
message(STATUS "Using 'YYYYMMDDHMS-<branch>-<git short rev>' as Clio version")
3630

37-
string(SUBSTRING ${GIT_COMMIT_HASH} 0 7 GIT_COMMIT_HASH_SHORT)
31+
string(SUBSTRING ${GIT_COMMIT_HASH} 0 7 GIT_COMMIT_HASH_SHORT)
3832

39-
set(CLIO_VERSION "${BUILD_DATE}-${GIT_BUILD_BRANCH}-${GIT_COMMIT_HASH_SHORT}")
40-
set(DOC_CLIO_VERSION "develop")
33+
set(CLIO_VERSION "${BUILD_DATE}-${GIT_BUILD_BRANCH}-${GIT_COMMIT_HASH_SHORT}")
34+
set(DOC_CLIO_VERSION "develop")
4135
endif ()
4236

4337
if (CMAKE_BUILD_TYPE MATCHES Debug)
44-
set(CLIO_VERSION "${CLIO_VERSION}+DEBUG")
38+
set(CLIO_VERSION "${CLIO_VERSION}+DEBUG")
4539
endif ()
4640

4741
message(STATUS "Build version: ${CLIO_VERSION}")

0 commit comments

Comments
 (0)