diff --git a/.cmake-format.yaml b/.cmake-format.yaml deleted file mode 100644 index 1c4d6684e..000000000 --- a/.cmake-format.yaml +++ /dev/null @@ -1,236 +0,0 @@ -_help_parse: Options affecting listfile parsing -parse: - _help_additional_commands: - - Specify structure for custom cmake functions - _help_override_spec: - - Override configurations per-command where available - override_spec: {} - _help_vartags: - - Specify variable tags. - vartags: [] - _help_proptags: - - Specify property tags. - proptags: [] -_help_format: Options affecting formatting. -format: - _help_disable: - - Disable formatting entirely, making cmake-format a no-op - disable: false - _help_line_width: - - How wide to allow formatted cmake files - line_width: 120 - _help_tab_size: - - How many spaces to tab for indent - tab_size: 4 - _help_use_tabchars: - - If true, lines are indented using tab characters (utf-8 - - 0x09) instead of space characters (utf-8 0x20). - - In cases where the layout would require a fractional tab - - character, the behavior of the fractional indentation is - - governed by - use_tabchars: false - _help_fractional_tab_policy: - - If is True, then the value of this variable - - indicates how fractional indentions are handled during - - whitespace replacement. If set to 'use-space', fractional - - indentation is left as spaces (utf-8 0x20). If set to - - "`round-up` fractional indentation is replaced with a single" - - tab character (utf-8 0x09) effectively shifting the column - - to the next tabstop - fractional_tab_policy: use-space - _help_max_subgroups_hwrap: - - If an argument group contains more than this many sub-groups - - (parg or kwarg groups) then force it to a vertical layout. - max_subgroups_hwrap: 4 - _help_max_pargs_hwrap: - - If a positional argument group contains more than this many - - arguments, then force it to a vertical layout. - max_pargs_hwrap: 5 - _help_max_rows_cmdline: - - If a cmdline positional group consumes more than this many - - lines without nesting, then invalidate the layout (and nest) - max_rows_cmdline: 2 - _help_separate_ctrl_name_with_space: - - If true, separate flow control names from their parentheses - - with a space - separate_ctrl_name_with_space: true - _help_separate_fn_name_with_space: - - If true, separate function names from parentheses with a - - space - separate_fn_name_with_space: false - _help_dangle_parens: - - If a statement is wrapped to more than one line, than dangle - - the closing parenthesis on its own line. - dangle_parens: false - _help_dangle_align: - - If the trailing parenthesis must be 'dangled' on its on - - "line, then align it to this reference: `prefix`: the start" - - "of the statement, `prefix-indent`: the start of the" - - "statement, plus one indentation level, `child`: align to" - - the column of the arguments - dangle_align: prefix - _help_min_prefix_chars: - - If the statement spelling length (including space and - - parenthesis) is smaller than this amount, then force reject - - nested layouts. - min_prefix_chars: 18 - _help_max_prefix_chars: - - If the statement spelling length (including space and - - parenthesis) is larger than the tab width by more than this - - amount, then force reject un-nested layouts. - max_prefix_chars: 10 - _help_max_lines_hwrap: - - If a candidate layout is wrapped horizontally but it exceeds - - this many lines, then reject the layout. - max_lines_hwrap: 2 - _help_line_ending: - - What style line endings to use in the output. - line_ending: unix - _help_command_case: - - Format command names consistently as 'lower' or 'upper' case - command_case: canonical - _help_keyword_case: - - Format keywords consistently as 'lower' or 'upper' case - keyword_case: unchanged - _help_always_wrap: - - A list of command names which should always be wrapped - always_wrap: [] - _help_enable_sort: - - If true, the argument lists which are known to be sortable - - will be sorted lexicographicall - enable_sort: true - _help_autosort: - - If true, the parsers may infer whether or not an argument - - list is sortable (without annotation). - autosort: true - _help_require_valid_layout: - - By default, if cmake-format cannot successfully fit - - everything into the desired linewidth it will apply the - - last, most aggressive attempt that it made. If this flag is - - True, however, cmake-format will print error, exit with non- - - zero status code, and write-out nothing - require_valid_layout: false - _help_layout_passes: - - A dictionary mapping layout nodes to a list of wrap - - decisions. See the documentation for more information. - layout_passes: {} -_help_markup: Options affecting comment reflow and formatting. -markup: - _help_bullet_char: - - What character to use for bulleted lists - bullet_char: "-" - _help_enum_char: - - What character to use as punctuation after numerals in an - - enumerated list - enum_char: . - _help_first_comment_is_literal: - - If comment markup is enabled, don't reflow the first comment - - block in each listfile. Use this to preserve formatting of - - your copyright/license statements. - first_comment_is_literal: false - _help_literal_comment_pattern: - - If comment markup is enabled, don't reflow any comment block - - which matches this (regex) pattern. Default is `None` - - (disabled). - literal_comment_pattern: null - _help_fence_pattern: - - Regular expression to match preformat fences in comments - - default= ``r'^\s*([`~]{3}[`~]*)(.*)$'`` - fence_pattern: ^\s*([`~]{3}[`~]*)(.*)$ - _help_ruler_pattern: - - Regular expression to match rulers in comments default= - - '``r''^\s*[^\w\s]{3}.*[^\w\s]{3}$''``' - ruler_pattern: ^\s*[^\w\s]{3}.*[^\w\s]{3}$ - _help_explicit_trailing_pattern: - - If a comment line matches starts with this pattern then it - - is explicitly a trailing comment for the preceding - - argument. Default is '#<' - explicit_trailing_pattern: "#<" - _help_hashruler_min_length: - - If a comment line starts with at least this many consecutive - - hash characters, then don't lstrip() them off. This allows - - for lazy hash rulers where the first hash char is not - - separated by space - hashruler_min_length: 10 - _help_canonicalize_hashrulers: - - If true, then insert a space between the first hash char and - - remaining hash chars in a hash ruler, and normalize its - - length to fill the column - canonicalize_hashrulers: true - _help_enable_markup: - - enable comment markup parsing and reflow - enable_markup: true -_help_lint: Options affecting the linter -lint: - _help_disabled_codes: - - a list of lint codes to disable - disabled_codes: [] - _help_function_pattern: - - regular expression pattern describing valid function names - function_pattern: "[0-9a-z_]+" - _help_macro_pattern: - - regular expression pattern describing valid macro names - macro_pattern: "[0-9A-Z_]+" - _help_global_var_pattern: - - regular expression pattern describing valid names for - - variables with global (cache) scope - global_var_pattern: "[A-Z][0-9A-Z_]+" - _help_internal_var_pattern: - - regular expression pattern describing valid names for - - variables with global scope (but internal semantic) - internal_var_pattern: _[A-Z][0-9A-Z_]+ - _help_local_var_pattern: - - regular expression pattern describing valid names for - - variables with local scope - local_var_pattern: "[a-z][a-z0-9_]+" - _help_private_var_pattern: - - regular expression pattern describing valid names for - - privatedirectory variables - private_var_pattern: _[0-9a-z_]+ - _help_public_var_pattern: - - regular expression pattern describing valid names for public - - directory variables - public_var_pattern: "[A-Z][0-9A-Z_]+" - _help_argument_var_pattern: - - regular expression pattern describing valid names for - - function/macro arguments and loop variables. - argument_var_pattern: "[a-z][a-z0-9_]+" - _help_keyword_pattern: - - regular expression pattern describing valid names for - - keywords used in functions or macros - keyword_pattern: "[A-Z][0-9A-Z_]+" - _help_max_conditionals_custom_parser: - - In the heuristic for C0201, how many conditionals to match - - within a loop in before considering the loop a parser. - max_conditionals_custom_parser: 2 - _help_min_statement_spacing: - - Require at least this many newlines between statements - min_statement_spacing: 1 - _help_max_statement_spacing: - - Require no more than this many newlines between statements - max_statement_spacing: 2 - max_returns: 6 - max_branches: 12 - max_arguments: 5 - max_localvars: 15 - max_statements: 50 -_help_encode: Options affecting file encoding -encode: - _help_emit_byteorder_mark: - - If true, emit the unicode byte-order mark (BOM) at the start - - of the file - emit_byteorder_mark: false - _help_input_encoding: - - Specify the encoding of the input file. Defaults to utf-8 - input_encoding: utf-8 - _help_output_encoding: - - Specify the encoding of the output file. Defaults to utf-8. - - Note that cmake only claims to support utf-8 so be careful - - when using anything else - output_encoding: utf-8 -_help_misc: Miscellaneous configurations options. -misc: - _help_per_command: - - A dictionary containing any per-command configuration - - overrides. Currently only `command_case` is supported. - per_command: {} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 249f48a38..67f938abc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -100,11 +100,10 @@ repos: args: [--style=file] types: [c++] - - repo: https://github.com/cheshirekow/cmake-format-precommit - rev: e2c2116d86a80e72e7146a06e68b7c228afc6319 # frozen: v0.6.13 + - repo: https://github.com/BlankSpruce/gersemi + rev: 0.26.0 hooks: - - id: cmake-format - additional_dependencies: [PyYAML] + - id: gersemi - repo: local hooks: diff --git a/CMakeLists.txt b/CMakeLists.txt index ceb42ea1f..d6f725353 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,11 @@ cmake_minimum_required(VERSION 3.20) -project(clio VERSION ${CLIO_VERSION} HOMEPAGE_URL "https://github.com/XRPLF/clio" - DESCRIPTION "An XRP Ledger API Server") +project( + clio + VERSION ${CLIO_VERSION} + HOMEPAGE_URL "https://github.com/XRPLF/clio" + DESCRIPTION "An XRP Ledger API Server" +) # =========================== Options ====================================== # option(verbose "Verbose build" FALSE) @@ -14,7 +18,11 @@ option(package "Create distribution packages" FALSE) option(lint "Run clang-tidy checks during compilation" FALSE) option(static "Statically linked Clio" FALSE) option(snapshot "Build snapshot tool" FALSE) -option(time_trace "Build using -ftime-trace to create compiler trace reports" FALSE) +option( + time_trace + "Build using -ftime-trace to create compiler trace reports" + FALSE +) # ========================================================================== # set(san "" CACHE STRING "Add sanitizer instrumentation") @@ -34,9 +42,9 @@ add_library(clio_options INTERFACE) target_compile_features(clio_options INTERFACE cxx_std_23) # Clio needs c++23 but deps can remain c++20 for now target_include_directories(clio_options INTERFACE ${CMAKE_SOURCE_DIR}/src) -if (verbose) +if(verbose) set(CMAKE_VERBOSE_MAKEFILE TRUE) -endif () +endif() # Clio tweaks and checks include(CheckCompiler) @@ -56,37 +64,43 @@ include(deps/spdlog) add_subdirectory(src) add_subdirectory(tests) -if (benchmark) +if(benchmark) add_subdirectory(benchmarks) -endif () +endif() # Enable selected sanitizer if enabled via `san` -if (san) +if(san) set(SUPPORTED_SANITIZERS "address" "thread" "memory" "undefined") - if (NOT san IN_LIST SUPPORTED_SANITIZERS) - message(FATAL_ERROR "Error: Unsupported sanitizer '${san}'. Supported values are: ${SUPPORTED_SANITIZERS}.") - endif () + if(NOT san IN_LIST SUPPORTED_SANITIZERS) + message( + FATAL_ERROR + "Error: Unsupported sanitizer '${san}'. Supported values are: ${SUPPORTED_SANITIZERS}." + ) + endif() # Sanitizers recommend minimum of -O1 for reasonable performance so we enable it for debug builds set(SAN_OPTIMIZATION_FLAG "") - if (CMAKE_BUILD_TYPE STREQUAL "Debug") + if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(SAN_OPTIMIZATION_FLAG -O1) - endif () - target_compile_options(clio_options INTERFACE ${SAN_OPTIMIZATION_FLAG} ${SAN_FLAG} -fno-omit-frame-pointer) + endif() + target_compile_options( + clio_options + INTERFACE ${SAN_OPTIMIZATION_FLAG} ${SAN_FLAG} -fno-omit-frame-pointer + ) target_link_libraries(clio_options INTERFACE ${SAN_FLAG} ${SAN_LIB}) -endif () +endif() # Generate `docs` target for doxygen documentation if enabled Note: use `make docs` to generate the documentation -if (docs) +if(docs) add_subdirectory(docs) -endif () +endif() include(install/install) -if (package) +if(package) include(ClioPackage) -endif () +endif() -if (snapshot) +if(snapshot) add_subdirectory(tools/snapshot) -endif () +endif() diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 8230be99a..4eee1b41c 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -1,18 +1,27 @@ add_executable(clio_benchmark) -target_sources(clio_benchmark - PRIVATE # Common - Main.cpp - Playground.cpp - # ExecutionContext - util/async/ExecutionContextBenchmarks.cpp - # Logger - util/log/LoggerBenchmark.cpp - # WorkQueue - rpc/WorkQueueBenchmarks.cpp) +target_sources( + clio_benchmark + PRIVATE + # Common + Main.cpp + Playground.cpp + # ExecutionContext + util/async/ExecutionContextBenchmarks.cpp + # Logger + util/log/LoggerBenchmark.cpp + # WorkQueue + rpc/WorkQueueBenchmarks.cpp +) include(deps/gbench) target_include_directories(clio_benchmark PRIVATE .) -target_link_libraries(clio_benchmark PRIVATE clio_rpc clio_util benchmark::benchmark_main spdlog::spdlog) -set_target_properties(clio_benchmark PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +target_link_libraries( + clio_benchmark + PRIVATE clio_rpc clio_util benchmark::benchmark_main spdlog::spdlog +) +set_target_properties( + clio_benchmark + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) diff --git a/cmake/Ccache.cmake b/cmake/Ccache.cmake index 2ff662b66..d111ff1e6 100644 --- a/cmake/Ccache.cmake +++ b/cmake/Ccache.cmake @@ -1,5 +1,5 @@ find_program(CCACHE_PATH "ccache") -if (CCACHE_PATH) +if(CCACHE_PATH) set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PATH}") message(STATUS "Using ccache: ${CCACHE_PATH}") -endif () +endif() diff --git a/cmake/CheckCompiler.cmake b/cmake/CheckCompiler.cmake index 98e23abcb..f0ce4e534 100644 --- a/cmake/CheckCompiler.cmake +++ b/cmake/CheckCompiler.cmake @@ -1,42 +1,48 @@ -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) message(FATAL_ERROR "Clang 16+ required for building clio") - endif () + endif() set(is_clang TRUE) -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15) message(FATAL_ERROR "AppleClang 15+ required for building clio") - endif () + endif() set(is_appleclang TRUE) -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12) message(FATAL_ERROR "GCC 12+ required for building clio") - endif () + endif() set(is_gcc TRUE) -else () - message(FATAL_ERROR "Supported compilers: AppleClang 15+, Clang 16+, GCC 12+") -endif () +else() + message( + FATAL_ERROR + "Supported compilers: AppleClang 15+, Clang 16+, GCC 12+" + ) +endif() -if (san) +if(san) string(TOLOWER ${san} san) set(SAN_FLAG "-fsanitize=${san}") set(SAN_LIB "") - if (is_gcc) - if (san STREQUAL "address") + if(is_gcc) + if(san STREQUAL "address") set(SAN_LIB "asan") - elseif (san STREQUAL "thread") + elseif(san STREQUAL "thread") set(SAN_LIB "tsan") - elseif (san STREQUAL "memory") + elseif(san STREQUAL "memory") set(SAN_LIB "msan") - elseif (san STREQUAL "undefined") + elseif(san STREQUAL "undefined") set(SAN_LIB "ubsan") - endif () - endif () + endif() + endif() set(_saved_CRL ${CMAKE_REQUIRED_LIBRARIES}) set(CMAKE_REQUIRED_LIBRARIES "${SAN_FLAG};${SAN_LIB}") check_cxx_compiler_flag(${SAN_FLAG} COMPILER_SUPPORTS_SAN) set(CMAKE_REQUIRED_LIBRARIES ${_saved_CRL}) - if (NOT COMPILER_SUPPORTS_SAN) - message(FATAL_ERROR "${san} sanitizer does not seem to be supported by your compiler") - endif () -endif () + if(NOT COMPILER_SUPPORTS_SAN) + message( + FATAL_ERROR + "${san} sanitizer does not seem to be supported by your compiler" + ) + endif() +endif() diff --git a/cmake/ClangTidy.cmake b/cmake/ClangTidy.cmake index 563f1c4d6..f0184e59d 100644 --- a/cmake/ClangTidy.cmake +++ b/cmake/ClangTidy.cmake @@ -1,30 +1,41 @@ -if (lint) - +if(lint) # Find clang-tidy binary - if (DEFINED ENV{CLIO_CLANG_TIDY_BIN}) + if(DEFINED ENV{CLIO_CLANG_TIDY_BIN}) set(_CLANG_TIDY_BIN $ENV{CLIO_CLANG_TIDY_BIN}) - if ((NOT EXISTS ${_CLANG_TIDY_BIN}) OR IS_DIRECTORY ${_CLANG_TIDY_BIN}) - message(FATAL_ERROR "$ENV{CLIO_CLANG_TIDY_BIN} no such file. Check CLIO_CLANG_TIDY_BIN env variable") - endif () + if((NOT EXISTS ${_CLANG_TIDY_BIN}) OR IS_DIRECTORY ${_CLANG_TIDY_BIN}) + message( + FATAL_ERROR + "$ENV{CLIO_CLANG_TIDY_BIN} no such file. Check CLIO_CLANG_TIDY_BIN env variable" + ) + endif() message(STATUS "Using clang-tidy from CLIO_CLANG_TIDY_BIN") - else () - find_program(_CLANG_TIDY_BIN NAMES "clang-tidy-20" "clang-tidy" REQUIRED) - endif () - - if (NOT _CLANG_TIDY_BIN) - message(FATAL_ERROR "clang-tidy binary not found. Please set the CLIO_CLANG_TIDY_BIN environment variable or install clang-tidy." + else() + find_program( + _CLANG_TIDY_BIN + NAMES "clang-tidy-20" "clang-tidy" + REQUIRED ) - endif () + endif() + + if(NOT _CLANG_TIDY_BIN) + message( + FATAL_ERROR + "clang-tidy binary not found. Please set the CLIO_CLANG_TIDY_BIN environment variable or install clang-tidy." + ) + endif() # Support for https://github.com/matus-chochlik/ctcache find_program(CLANG_TIDY_CACHE_PATH NAMES "clang-tidy-cache") - if (CLANG_TIDY_CACHE_PATH) - set(_CLANG_TIDY_CMD "${CLANG_TIDY_CACHE_PATH};${_CLANG_TIDY_BIN}" - CACHE STRING "A combined command to run clang-tidy with caching wrapper") - else () + if(CLANG_TIDY_CACHE_PATH) + set(_CLANG_TIDY_CMD + "${CLANG_TIDY_CACHE_PATH};${_CLANG_TIDY_BIN}" + CACHE STRING + "A combined command to run clang-tidy with caching wrapper" + ) + else() set(_CLANG_TIDY_CMD "${_CLANG_TIDY_BIN}") - endif () + endif() set(CMAKE_CXX_CLANG_TIDY "${_CLANG_TIDY_CMD};--quiet") message(STATUS "Using clang-tidy: ${CMAKE_CXX_CLANG_TIDY}") -endif () +endif() diff --git a/cmake/ClioVersion.cmake b/cmake/ClioVersion.cmake index 06206d41b..52959474b 100644 --- a/cmake/ClioVersion.cmake +++ b/cmake/ClioVersion.cmake @@ -1,41 +1,67 @@ find_package(Git REQUIRED) -if (DEFINED ENV{GITHUB_BRANCH_NAME}) +if(DEFINED ENV{GITHUB_BRANCH_NAME}) set(GIT_BUILD_BRANCH $ENV{GITHUB_BRANCH_NAME}) set(GIT_COMMIT_HASH $ENV{GITHUB_HEAD_SHA}) -else () +else() set(GIT_COMMAND branch --show-current) - execute_process(COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_BUILD_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY) + execute_process( + COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BUILD_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND_ERROR_IS_FATAL ANY + ) set(GIT_COMMAND rev-parse HEAD) - execute_process(COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY) -endif () + execute_process( + COMMAND ${GIT_EXECUTABLE} ${GIT_COMMAND} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND_ERROR_IS_FATAL ANY + ) +endif() -execute_process(COMMAND date +%Y%m%d%H%M%S WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE BUILD_DATE - OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY) +execute_process( + COMMAND date +%Y%m%d%H%M%S + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE BUILD_DATE + OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND_ERROR_IS_FATAL ANY +) message(STATUS "Git branch: ${GIT_BUILD_BRANCH}") message(STATUS "Git commit hash: ${GIT_COMMIT_HASH}") message(STATUS "Build date: ${BUILD_DATE}") -if (DEFINED ENV{FORCE_CLIO_VERSION} AND NOT "$ENV{FORCE_CLIO_VERSION}" STREQUAL "") - message(STATUS "Using explicitly provided '${FORCE_CLIO_VERSION}' as Clio version") +if( + DEFINED ENV{FORCE_CLIO_VERSION} + AND NOT "$ENV{FORCE_CLIO_VERSION}" STREQUAL "" +) + message( + STATUS + "Using explicitly provided '${FORCE_CLIO_VERSION}' as Clio version" + ) set(CLIO_VERSION "$ENV{FORCE_CLIO_VERSION}") set(DOC_CLIO_VERSION "$ENV{FORCE_CLIO_VERSION}") -else () - message(STATUS "Using 'YYYYMMDDHMS--' as Clio version") +else() + message( + STATUS + "Using 'YYYYMMDDHMS--' as Clio version" + ) string(SUBSTRING ${GIT_COMMIT_HASH} 0 7 GIT_COMMIT_HASH_SHORT) - set(CLIO_VERSION "${BUILD_DATE}-${GIT_BUILD_BRANCH}-${GIT_COMMIT_HASH_SHORT}") + set(CLIO_VERSION + "${BUILD_DATE}-${GIT_BUILD_BRANCH}-${GIT_COMMIT_HASH_SHORT}" + ) set(DOC_CLIO_VERSION "develop") -endif () +endif() -if (CMAKE_BUILD_TYPE MATCHES Debug) +if(CMAKE_BUILD_TYPE MATCHES Debug) set(CLIO_VERSION "${CLIO_VERSION}+DEBUG") -endif () +endif() message(STATUS "Build version: ${CLIO_VERSION}") diff --git a/cmake/CodeCoverage.cmake b/cmake/CodeCoverage.cmake index f8c56d6ad..fde43369f 100644 --- a/cmake/CodeCoverage.cmake +++ b/cmake/CodeCoverage.cmake @@ -106,71 +106,120 @@ option(CODE_COVERAGE_VERBOSE "Verbose information" FALSE) # Check prereqs find_program(GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test) -if (DEFINED CODE_COVERAGE_GCOV_TOOL) +if(DEFINED CODE_COVERAGE_GCOV_TOOL) set(GCOV_TOOL "${CODE_COVERAGE_GCOV_TOOL}") -elseif (DEFINED ENV{CODE_COVERAGE_GCOV_TOOL}) +elseif(DEFINED ENV{CODE_COVERAGE_GCOV_TOOL}) set(GCOV_TOOL "$ENV{CODE_COVERAGE_GCOV_TOOL}") -elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") - if (APPLE) - execute_process(COMMAND xcrun -f llvm-cov OUTPUT_VARIABLE LLVMCOV_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) - else () +elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") + if(APPLE) + execute_process( + COMMAND xcrun -f llvm-cov + OUTPUT_VARIABLE LLVMCOV_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + else() find_program(LLVMCOV_PATH llvm-cov) - endif () - if (LLVMCOV_PATH) + endif() + if(LLVMCOV_PATH) set(GCOV_TOOL "${LLVMCOV_PATH} gcov") - endif () -elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + endif() +elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") find_program(GCOV_PATH gcov) set(GCOV_TOOL "${GCOV_PATH}") -endif () +endif() # Check supported compiler (Clang, GNU and Flang) get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES) -foreach (LANG ${LANGUAGES}) - if ("${CMAKE_${LANG}_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") - if ("${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS 3) - message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") - endif () - elseif (NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES "GNU" AND NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES - "(LLVM)?[Ff]lang") +foreach(LANG ${LANGUAGES}) + if("${CMAKE_${LANG}_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") + if("${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS 3) + message( + FATAL_ERROR + "Clang version must be 3.0.0 or greater! Aborting..." + ) + endif() + elseif( + NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES "GNU" + AND NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES "(LLVM)?[Ff]lang" + ) message(FATAL_ERROR "Compiler is not GNU or Flang! Aborting...") - endif () -endforeach () + endif() +endforeach() set(COVERAGE_COMPILER_FLAGS "-g --coverage" CACHE INTERNAL "") -if (CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") +if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-fprofile-abs-path HAVE_cxx_fprofile_abs_path) - if (HAVE_cxx_fprofile_abs_path) - set(COVERAGE_CXX_COMPILER_FLAGS "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path") - endif () + if(HAVE_cxx_fprofile_abs_path) + set(COVERAGE_CXX_COMPILER_FLAGS + "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path" + ) + endif() include(CheckCCompilerFlag) check_c_compiler_flag(-fprofile-abs-path HAVE_c_fprofile_abs_path) - if (HAVE_c_fprofile_abs_path) - set(COVERAGE_C_COMPILER_FLAGS "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path") - endif () -endif () + if(HAVE_c_fprofile_abs_path) + set(COVERAGE_C_COMPILER_FLAGS + "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path" + ) + endif() +endif() -set(CMAKE_Fortran_FLAGS_COVERAGE ${COVERAGE_COMPILER_FLAGS} - CACHE STRING "Flags used by the Fortran compiler during coverage builds." FORCE) -set(CMAKE_CXX_FLAGS_COVERAGE ${COVERAGE_COMPILER_FLAGS} - CACHE STRING "Flags used by the C++ compiler during coverage builds." FORCE) -set(CMAKE_C_FLAGS_COVERAGE ${COVERAGE_COMPILER_FLAGS} - CACHE STRING "Flags used by the C compiler during coverage builds." FORCE) -set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "" CACHE STRING "Flags used for linking binaries during coverage builds." FORCE) -set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "" - CACHE STRING "Flags used by the shared libraries linker during coverage builds." FORCE) -mark_as_advanced(CMAKE_Fortran_FLAGS_COVERAGE CMAKE_CXX_FLAGS_COVERAGE CMAKE_C_FLAGS_COVERAGE - CMAKE_EXE_LINKER_FLAGS_COVERAGE CMAKE_SHARED_LINKER_FLAGS_COVERAGE) +set(CMAKE_Fortran_FLAGS_COVERAGE + ${COVERAGE_COMPILER_FLAGS} + CACHE STRING + "Flags used by the Fortran compiler during coverage builds." + FORCE +) +set(CMAKE_CXX_FLAGS_COVERAGE + ${COVERAGE_COMPILER_FLAGS} + CACHE STRING + "Flags used by the C++ compiler during coverage builds." + FORCE +) +set(CMAKE_C_FLAGS_COVERAGE + ${COVERAGE_COMPILER_FLAGS} + CACHE STRING + "Flags used by the C compiler during coverage builds." + FORCE +) +set(CMAKE_EXE_LINKER_FLAGS_COVERAGE + "" + CACHE STRING + "Flags used for linking binaries during coverage builds." + FORCE +) +set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE + "" + CACHE STRING + "Flags used by the shared libraries linker during coverage builds." + FORCE +) +mark_as_advanced( + CMAKE_Fortran_FLAGS_COVERAGE + CMAKE_CXX_FLAGS_COVERAGE + CMAKE_C_FLAGS_COVERAGE + CMAKE_EXE_LINKER_FLAGS_COVERAGE + CMAKE_SHARED_LINKER_FLAGS_COVERAGE +) -get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) -if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG)) - message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading") -endif () # NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG) +get_property( + GENERATOR_IS_MULTI_CONFIG + GLOBAL + PROPERTY GENERATOR_IS_MULTI_CONFIG +) +if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG)) + message( + WARNING + "Code coverage results with an optimised (non-Debug) build may be misleading" + ) +endif() # NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG) -if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") +if( + CMAKE_C_COMPILER_ID STREQUAL "GNU" + OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" +) link_libraries(gcov) -endif () +endif() # Defines a target for running and collection code coverage information Builds dependencies, runs the given executable # and outputs reports. NOTE! The executable should always have a ZERO as exit code otherwise the coverage generation @@ -184,107 +233,145 @@ endif () # defaults to xml) EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative # to BASE_DIRECTORY, # with CMake 3.4+) ) The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the GCVOR # command. -function (setup_target_for_coverage_gcovr) +function(setup_target_for_coverage_gcovr) set(options NONE) set(oneValueArgs BASE_DIRECTORY NAME FORMAT) set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) - cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + cmake_parse_arguments( + Coverage + "${options}" + "${oneValueArgs}" + "${multiValueArgs}" + ${ARGN} + ) - if (NOT GCOV_TOOL) + if(NOT GCOV_TOOL) message(FATAL_ERROR "Could not find gcov or llvm-cov tool! Aborting...") - endif () + endif() - if (NOT GCOVR_PATH) + if(NOT GCOVR_PATH) message(FATAL_ERROR "Could not find gcovr tool! Aborting...") - endif () + endif() # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR - if (DEFINED Coverage_BASE_DIRECTORY) + if(DEFINED Coverage_BASE_DIRECTORY) get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE) - else () + else() set(BASEDIR ${PROJECT_SOURCE_DIR}) - endif () + endif() - if (NOT DEFINED Coverage_FORMAT) + if(NOT DEFINED Coverage_FORMAT) set(Coverage_FORMAT xml) - endif () + endif() - if ("--output" IN_LIST GCOVR_ADDITIONAL_ARGS) - message(FATAL_ERROR "Unsupported --output option detected in GCOVR_ADDITIONAL_ARGS! Aborting...") - else () - if ((Coverage_FORMAT STREQUAL "html-details") OR (Coverage_FORMAT STREQUAL "html-nested")) - set(GCOVR_OUTPUT_FILE ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html) + if("--output" IN_LIST GCOVR_ADDITIONAL_ARGS) + message( + FATAL_ERROR + "Unsupported --output option detected in GCOVR_ADDITIONAL_ARGS! Aborting..." + ) + else() + if( + (Coverage_FORMAT STREQUAL "html-details") + OR (Coverage_FORMAT STREQUAL "html-nested") + ) + set(GCOVR_OUTPUT_FILE + ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html + ) set(GCOVR_CREATE_FOLDER ${PROJECT_BINARY_DIR}/${Coverage_NAME}) - elseif (Coverage_FORMAT STREQUAL "html-single") + elseif(Coverage_FORMAT STREQUAL "html-single") set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.html) - elseif ((Coverage_FORMAT STREQUAL "json-summary") OR (Coverage_FORMAT STREQUAL "json-details") - OR (Coverage_FORMAT STREQUAL "coveralls")) + elseif( + (Coverage_FORMAT STREQUAL "json-summary") + OR (Coverage_FORMAT STREQUAL "json-details") + OR (Coverage_FORMAT STREQUAL "coveralls") + ) set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.json) - elseif (Coverage_FORMAT STREQUAL "txt") + elseif(Coverage_FORMAT STREQUAL "txt") set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.txt) - elseif (Coverage_FORMAT STREQUAL "csv") + elseif(Coverage_FORMAT STREQUAL "csv") set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.csv) - else () + else() set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.xml) - endif () - endif () + endif() + endif() - if ((Coverage_FORMAT STREQUAL "cobertura") OR (Coverage_FORMAT STREQUAL "xml")) + if( + (Coverage_FORMAT STREQUAL "cobertura") + OR (Coverage_FORMAT STREQUAL "xml") + ) list(APPEND GCOVR_ADDITIONAL_ARGS --cobertura "${GCOVR_OUTPUT_FILE}") list(APPEND GCOVR_ADDITIONAL_ARGS --cobertura-pretty) set(Coverage_FORMAT cobertura) # overwrite xml - elseif (Coverage_FORMAT STREQUAL "sonarqube") + elseif(Coverage_FORMAT STREQUAL "sonarqube") list(APPEND GCOVR_ADDITIONAL_ARGS --sonarqube "${GCOVR_OUTPUT_FILE}") - elseif (Coverage_FORMAT STREQUAL "json-summary") + elseif(Coverage_FORMAT STREQUAL "json-summary") list(APPEND GCOVR_ADDITIONAL_ARGS --json-summary "${GCOVR_OUTPUT_FILE}") list(APPEND GCOVR_ADDITIONAL_ARGS --json-summary-pretty) - elseif (Coverage_FORMAT STREQUAL "json-details") + elseif(Coverage_FORMAT STREQUAL "json-details") list(APPEND GCOVR_ADDITIONAL_ARGS --json "${GCOVR_OUTPUT_FILE}") list(APPEND GCOVR_ADDITIONAL_ARGS --json-pretty) - elseif (Coverage_FORMAT STREQUAL "coveralls") + elseif(Coverage_FORMAT STREQUAL "coveralls") list(APPEND GCOVR_ADDITIONAL_ARGS --coveralls "${GCOVR_OUTPUT_FILE}") list(APPEND GCOVR_ADDITIONAL_ARGS --coveralls-pretty) - elseif (Coverage_FORMAT STREQUAL "csv") + elseif(Coverage_FORMAT STREQUAL "csv") list(APPEND GCOVR_ADDITIONAL_ARGS --csv "${GCOVR_OUTPUT_FILE}") - elseif (Coverage_FORMAT STREQUAL "txt") + elseif(Coverage_FORMAT STREQUAL "txt") list(APPEND GCOVR_ADDITIONAL_ARGS --txt "${GCOVR_OUTPUT_FILE}") - elseif (Coverage_FORMAT STREQUAL "html-single") + elseif(Coverage_FORMAT STREQUAL "html-single") list(APPEND GCOVR_ADDITIONAL_ARGS --html "${GCOVR_OUTPUT_FILE}") list(APPEND GCOVR_ADDITIONAL_ARGS --html-self-contained) - elseif (Coverage_FORMAT STREQUAL "html-nested") + elseif(Coverage_FORMAT STREQUAL "html-nested") list(APPEND GCOVR_ADDITIONAL_ARGS --html-nested "${GCOVR_OUTPUT_FILE}") - elseif (Coverage_FORMAT STREQUAL "html-details") + elseif(Coverage_FORMAT STREQUAL "html-details") list(APPEND GCOVR_ADDITIONAL_ARGS --html-details "${GCOVR_OUTPUT_FILE}") - else () - message(FATAL_ERROR "Unsupported output style ${Coverage_FORMAT}! Aborting...") - endif () + else() + message( + FATAL_ERROR + "Unsupported output style ${Coverage_FORMAT}! Aborting..." + ) + endif() # Collect excludes (CMake 3.4+: Also compute absolute paths) set(GCOVR_EXCLUDES "") - foreach (EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES}) - if (CMAKE_VERSION VERSION_GREATER 3.4) - get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR}) - endif () + foreach( + EXCLUDE + ${Coverage_EXCLUDE} + ${COVERAGE_EXCLUDES} + ${COVERAGE_GCOVR_EXCLUDES} + ) + if(CMAKE_VERSION VERSION_GREATER 3.4) + get_filename_component( + EXCLUDE + ${EXCLUDE} + ABSOLUTE + BASE_DIR ${BASEDIR} + ) + endif() list(APPEND GCOVR_EXCLUDES "${EXCLUDE}") - endforeach () + endforeach() list(REMOVE_DUPLICATES GCOVR_EXCLUDES) # Combine excludes to several -e arguments set(GCOVR_EXCLUDE_ARGS "") - foreach (EXCLUDE ${GCOVR_EXCLUDES}) + foreach(EXCLUDE ${GCOVR_EXCLUDES}) list(APPEND GCOVR_EXCLUDE_ARGS "-e") list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}") - endforeach () + endforeach() # Set up commands which will be run to generate coverage data Run tests set(GCOVR_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}) # Create folder - if (DEFINED GCOVR_CREATE_FOLDER) - set(GCOVR_FOLDER_CMD ${CMAKE_COMMAND} -E make_directory ${GCOVR_CREATE_FOLDER}) - else () + if(DEFINED GCOVR_CREATE_FOLDER) + set(GCOVR_FOLDER_CMD + ${CMAKE_COMMAND} + -E + make_directory + ${GCOVR_CREATE_FOLDER} + ) + else() set(GCOVR_FOLDER_CMD echo) # dummy - endif () + endif() # Running gcovr set(GCOVR_CMD @@ -296,53 +383,86 @@ function (setup_target_for_coverage_gcovr) ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS} ${GCOVR_EXCLUDE_ARGS} - --object-directory=${PROJECT_BINARY_DIR}) + --object-directory=${PROJECT_BINARY_DIR} + ) - if (CODE_COVERAGE_VERBOSE) + if(CODE_COVERAGE_VERBOSE) message(STATUS "Executed command report") message(STATUS "Command to run tests: ") - string(REPLACE ";" " " GCOVR_EXEC_TESTS_CMD_SPACED "${GCOVR_EXEC_TESTS_CMD}") + string( + REPLACE ";" + " " + GCOVR_EXEC_TESTS_CMD_SPACED + "${GCOVR_EXEC_TESTS_CMD}" + ) message(STATUS "${GCOVR_EXEC_TESTS_CMD_SPACED}") - if (NOT GCOVR_FOLDER_CMD STREQUAL "echo") + if(NOT GCOVR_FOLDER_CMD STREQUAL "echo") message(STATUS "Command to create a folder: ") - string(REPLACE ";" " " GCOVR_FOLDER_CMD_SPACED "${GCOVR_FOLDER_CMD}") + string( + REPLACE ";" + " " + GCOVR_FOLDER_CMD_SPACED + "${GCOVR_FOLDER_CMD}" + ) message(STATUS "${GCOVR_FOLDER_CMD_SPACED}") - endif () + endif() message(STATUS "Command to generate gcovr coverage data: ") string(REPLACE ";" " " GCOVR_CMD_SPACED "${GCOVR_CMD}") message(STATUS "${GCOVR_CMD_SPACED}") - endif () + endif() - add_custom_target(${Coverage_NAME} - COMMAND ${GCOVR_EXEC_TESTS_CMD} - COMMAND ${GCOVR_FOLDER_CMD} - COMMAND ${GCOVR_CMD} - BYPRODUCTS ${GCOVR_OUTPUT_FILE} - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} - DEPENDS ${Coverage_DEPENDENCIES} - VERBATIM # Protect arguments to commands - COMMENT "Running gcovr to produce code coverage report.") + add_custom_target( + ${Coverage_NAME} + COMMAND ${GCOVR_EXEC_TESTS_CMD} + COMMAND ${GCOVR_FOLDER_CMD} + COMMAND ${GCOVR_CMD} + BYPRODUCTS ${GCOVR_OUTPUT_FILE} + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS ${Coverage_DEPENDENCIES} + VERBATIM # Protect arguments to commands + COMMENT "Running gcovr to produce code coverage report." + ) # Show info where to find the report - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD COMMAND ; - COMMENT "Code coverage report saved in ${GCOVR_OUTPUT_FILE} formatted as ${Coverage_FORMAT}") -endfunction () # setup_target_for_coverage_gcovr + add_custom_command( + TARGET ${Coverage_NAME} + POST_BUILD + COMMAND ; + COMMENT + "Code coverage report saved in ${GCOVR_OUTPUT_FILE} formatted as ${Coverage_FORMAT}" + ) +endfunction() # setup_target_for_coverage_gcovr -function (append_coverage_compiler_flags) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) - message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}") -endfunction () # append_coverage_compiler_flags +function(append_coverage_compiler_flags) + set(CMAKE_C_FLAGS + "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" + PARENT_SCOPE + ) + set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" + PARENT_SCOPE + ) + set(CMAKE_Fortran_FLAGS + "${CMAKE_Fortran_FLAGS} ${COVERAGE_COMPILER_FLAGS}" + PARENT_SCOPE + ) + message( + STATUS + "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}" + ) +endfunction() # append_coverage_compiler_flags # Setup coverage for specific library -function (append_coverage_compiler_flags_to_target name mode) +function(append_coverage_compiler_flags_to_target name mode) separate_arguments(_flag_list NATIVE_COMMAND "${COVERAGE_COMPILER_FLAGS}") target_compile_options(${name} ${mode} ${_flag_list}) - if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") + if( + CMAKE_C_COMPILER_ID STREQUAL "GNU" + OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" + ) target_link_libraries(${name} ${mode} gcov) - endif () -endfunction () + endif() +endfunction() diff --git a/cmake/Docs.cmake b/cmake/Docs.cmake index 13b61c797..a78cb8c32 100644 --- a/cmake/Docs.cmake +++ b/cmake/Docs.cmake @@ -11,8 +11,10 @@ set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile) set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT}) -add_custom_target(docs - COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Generating API documentation with Doxygen" - VERBATIM) +add_custom_target( + docs + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating API documentation with Doxygen" + VERBATIM +) diff --git a/cmake/Linker.cmake b/cmake/Linker.cmake index 7a2299d2b..19e1adc0d 100644 --- a/cmake/Linker.cmake +++ b/cmake/Linker.cmake @@ -1,11 +1,11 @@ -if (DEFINED CMAKE_LINKER_TYPE) +if(DEFINED CMAKE_LINKER_TYPE) message(STATUS "Custom linker is already set: ${CMAKE_LINKER_TYPE}") return() -endif () +endif() find_program(MOLD_PATH mold) -if (MOLD_PATH AND CMAKE_SYSTEM_NAME STREQUAL "Linux") +if(MOLD_PATH AND CMAKE_SYSTEM_NAME STREQUAL "Linux") message(STATUS "Using Mold linker: ${MOLD_PATH}") set(CMAKE_LINKER_TYPE MOLD) -endif () +endif() diff --git a/cmake/Settings.cmake b/cmake/Settings.cmake index b1d4e983c..b31db9c21 100644 --- a/cmake/Settings.cmake +++ b/cmake/Settings.cmake @@ -30,53 +30,56 @@ set(COMPILER_FLAGS # TODO: re-enable when we change CI #884 if (is_gcc AND NOT lint) list(APPEND COMPILER_FLAGS -Wduplicated-branches # -Wduplicated-cond -Wlogical-op -Wuseless-cast ) endif () -if (is_clang) - list(APPEND COMPILER_FLAGS -Wshadow # gcc is to aggressive with shadowing - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78147 - ) -endif () +if(is_clang) + # gcc is too aggressive with shadowing + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78147 + list(APPEND COMPILER_FLAGS -Wshadow) +endif() -if (is_appleclang) +if(is_appleclang) list(APPEND COMPILER_FLAGS -Wreorder-init-list) -endif () +endif() -if (san) +if(san) # When building with sanitizers some compilers will actually produce extra warnings/errors. We don't want this yet, # at least not until we have fixed all runtime issues reported by the sanitizers. Once that is done we can start # removing some of these and trying to fix it in our codebase. We can never remove all of below because most of them # are reported from deep inside libraries like boost or libxrpl. # # TODO: Address in https://github.com/XRPLF/clio/issues/1885 - list(APPEND - COMPILER_FLAGS - -Wno-error=tsan # Disables treating TSAN warnings as errors - -Wno-tsan # Disables TSAN warnings (thread-safety analysis) - -Wno-uninitialized # Disables warnings about uninitialized variables (AddressSanitizer, - # UndefinedBehaviorSanitizer, etc.) - -Wno-stringop-overflow # Disables warnings about potential string operation overflows (AddressSanitizer) - -Wno-unsafe-buffer-usage # Disables warnings about unsafe memory operations (AddressSanitizer) - -Wno-frame-larger-than # Disables warnings about stack frame size being too large (AddressSanitizer) - -Wno-unused-function # Disables warnings about unused functions (LeakSanitizer, memory-related issues) - -Wno-unused-but-set-variable # Disables warnings about unused variables (MemorySanitizer) - -Wno-thread-safety-analysis # Disables warnings related to thread safety usage (ThreadSanitizer) - -Wno-thread-safety # Disables warnings related to thread safety usage (ThreadSanitizer) - -Wno-sign-compare # Disables warnings about signed/unsigned comparison (UndefinedBehaviorSanitizer) - -Wno-nonnull # Disables warnings related to null pointer dereferencing (UndefinedBehaviorSanitizer) - -Wno-address # Disables warnings about address-related issues (UndefinedBehaviorSanitizer) - -Wno-array-bounds # Disables array bounds checks (UndefinedBehaviorSanitizer) + list( + APPEND COMPILER_FLAGS + -Wno-error=tsan # Disables treating TSAN warnings as errors + -Wno-tsan # Disables TSAN warnings (thread-safety analysis) + -Wno-uninitialized # Disables warnings about uninitialized variables (AddressSanitizer, + # UndefinedBehaviorSanitizer, etc.) + -Wno-stringop-overflow # Disables warnings about potential string operation overflows (AddressSanitizer) + -Wno-unsafe-buffer-usage # Disables warnings about unsafe memory operations (AddressSanitizer) + -Wno-frame-larger-than # Disables warnings about stack frame size being too large (AddressSanitizer) + -Wno-unused-function # Disables warnings about unused functions (LeakSanitizer, memory-related issues) + -Wno-unused-but-set-variable # Disables warnings about unused variables (MemorySanitizer) + -Wno-thread-safety-analysis # Disables warnings related to thread safety usage (ThreadSanitizer) + -Wno-thread-safety # Disables warnings related to thread safety usage (ThreadSanitizer) + -Wno-sign-compare # Disables warnings about signed/unsigned comparison (UndefinedBehaviorSanitizer) + -Wno-nonnull # Disables warnings related to null pointer dereferencing (UndefinedBehaviorSanitizer) + -Wno-address # Disables warnings about address-related issues (UndefinedBehaviorSanitizer) + -Wno-array-bounds # Disables array bounds checks (UndefinedBehaviorSanitizer) ) -endif () +endif() # See https://github.com/cpp-best-practices/cppbestpractices/blob/master/02-Use_the_Tools_Available.md#gcc--clang for # the flags description -if (time_trace) - if (is_clang OR is_appleclang) +if(time_trace) + if(is_clang OR is_appleclang) list(APPEND COMPILER_FLAGS -ftime-trace) - else () - message(FATAL_ERROR "Clang or AppleClang is required to use `-ftime-trace`") - endif () -endif () + else() + message( + FATAL_ERROR + "Clang or AppleClang is required to use `-ftime-trace`" + ) + endif() +endif() target_compile_options(clio_options INTERFACE ${COMPILER_FLAGS}) diff --git a/cmake/SourceLocation.cmake b/cmake/SourceLocation.cmake index 9d37f10e1..cb7061789 100644 --- a/cmake/SourceLocation.cmake +++ b/cmake/SourceLocation.cmake @@ -1,11 +1,17 @@ include(CheckIncludeFileCXX) check_include_file_cxx("source_location" SOURCE_LOCATION_AVAILABLE) -if (SOURCE_LOCATION_AVAILABLE) +if(SOURCE_LOCATION_AVAILABLE) target_compile_definitions(clio_options INTERFACE "HAS_SOURCE_LOCATION") -endif () +endif() -check_include_file_cxx("experimental/source_location" EXPERIMENTAL_SOURCE_LOCATION_AVAILABLE) -if (EXPERIMENTAL_SOURCE_LOCATION_AVAILABLE) - target_compile_definitions(clio_options INTERFACE "HAS_EXPERIMENTAL_SOURCE_LOCATION") -endif () +check_include_file_cxx( + "experimental/source_location" + EXPERIMENTAL_SOURCE_LOCATION_AVAILABLE +) +if(EXPERIMENTAL_SOURCE_LOCATION_AVAILABLE) + target_compile_definitions( + clio_options + INTERFACE "HAS_EXPERIMENTAL_SOURCE_LOCATION" + ) +endif() diff --git a/cmake/deps/Boost.cmake b/cmake/deps/Boost.cmake index ce282580d..f4dd99e68 100644 --- a/cmake/deps/Boost.cmake +++ b/cmake/deps/Boost.cmake @@ -1,4 +1,10 @@ set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_RUNTIME ON) -find_package(Boost 1.82 REQUIRED CONFIG COMPONENTS program_options coroutine system log log_setup) +find_package( + Boost + 1.82 + REQUIRED + CONFIG + COMPONENTS program_options coroutine system log log_setup +) diff --git a/cmake/deps/OpenSSL.cmake b/cmake/deps/OpenSSL.cmake index 2b735f20b..c1831611f 100644 --- a/cmake/deps/OpenSSL.cmake +++ b/cmake/deps/OpenSSL.cmake @@ -1,3 +1,6 @@ find_package(OpenSSL 1.1.1 REQUIRED CONFIG) -set_target_properties(OpenSSL::SSL PROPERTIES INTERFACE_COMPILE_DEFINITIONS OPENSSL_NO_SSL2) +set_target_properties( + OpenSSL::SSL + PROPERTIES INTERFACE_COMPILE_DEFINITIONS OPENSSL_NO_SSL2 +) diff --git a/cmake/deps/libbacktrace.cmake b/cmake/deps/libbacktrace.cmake index ebd5904dc..3015d5781 100644 --- a/cmake/deps/libbacktrace.cmake +++ b/cmake/deps/libbacktrace.cmake @@ -1,11 +1,14 @@ -if ("${san}" STREQUAL "") +if("${san}" STREQUAL "") target_compile_definitions(clio_options INTERFACE BOOST_STACKTRACE_LINK) - target_compile_definitions(clio_options INTERFACE BOOST_STACKTRACE_USE_BACKTRACE) + target_compile_definitions( + clio_options + INTERFACE BOOST_STACKTRACE_USE_BACKTRACE + ) find_package(libbacktrace REQUIRED CONFIG) -else () +else() # Some sanitizers (TSAN and ASAN for sure) can't be used with libbacktrace because they have their own backtracing # capabilities and there are conflicts. In any case, this makes sure Clio code knows that backtrace is not # available. See relevant conan profiles for sanitizers where we disable stacktrace in Boost explicitly. target_compile_definitions(clio_options INTERFACE CLIO_WITHOUT_STACKTRACE) message(STATUS "Sanitizer enabled, disabling stacktrace") -endif () +endif() diff --git a/cmake/deps/spdlog.cmake b/cmake/deps/spdlog.cmake index c17b65d79..ce13c5327 100644 --- a/cmake/deps/spdlog.cmake +++ b/cmake/deps/spdlog.cmake @@ -1,5 +1,5 @@ find_package(spdlog REQUIRED) -if (NOT TARGET spdlog::spdlog) +if(NOT TARGET spdlog::spdlog) message(FATAL_ERROR "spdlog::spdlog target not found") -endif () +endif() diff --git a/cmake/install/install.cmake b/cmake/install/install.cmake index 848197969..bf223d12d 100644 --- a/cmake/install/install.cmake +++ b/cmake/install/install.cmake @@ -1,5 +1,10 @@ set(CLIO_INSTALL_DIR "/opt/clio") -set(CMAKE_INSTALL_PREFIX "${CLIO_INSTALL_DIR}" CACHE PATH "Install prefix" FORCE) +set(CMAKE_INSTALL_PREFIX + "${CLIO_INSTALL_DIR}" + CACHE PATH + "Install prefix" + FORCE +) set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") @@ -10,7 +15,17 @@ install(TARGETS clio_server DESTINATION "${CMAKE_INSTALL_BINDIR}") file(READ docs/examples/config/example-config.json config) string(REGEX REPLACE "./clio_log" "/var/log/clio/" config "${config}") file(WRITE ${CMAKE_BINARY_DIR}/install-config.json "${config}") -install(FILES ${CMAKE_BINARY_DIR}/install-config.json DESTINATION etc RENAME config.json) +install( + FILES ${CMAKE_BINARY_DIR}/install-config.json + DESTINATION etc + RENAME config.json +) -configure_file("${CMAKE_SOURCE_DIR}/cmake/install/clio.service.in" "${CMAKE_BINARY_DIR}/clio.service") -install(FILES "${CMAKE_BINARY_DIR}/clio.service" DESTINATION /lib/systemd/system) +configure_file( + "${CMAKE_SOURCE_DIR}/cmake/install/clio.service.in" + "${CMAKE_BINARY_DIR}/clio.service" +) +install( + FILES "${CMAKE_BINARY_DIR}/clio.service" + DESTINATION /lib/systemd/system +) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index bbe466b51..a975d5ed8 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -1,12 +1,11 @@ add_library(clio_app) -target_sources(clio_app PRIVATE CliArgs.cpp ClioApplication.cpp Stopper.cpp WebHandlers.cpp) +target_sources( + clio_app + PRIVATE CliArgs.cpp ClioApplication.cpp Stopper.cpp WebHandlers.cpp +) target_link_libraries( clio_app - PUBLIC clio_cluster - clio_etl - clio_feed - clio_migration - clio_rpc - clio_web - PRIVATE Boost::program_options) + PUBLIC clio_cluster clio_etl clio_feed clio_migration clio_rpc clio_web + PRIVATE Boost::program_options +) diff --git a/src/cluster/CMakeLists.txt b/src/cluster/CMakeLists.txt index 467f421fc..e7fa1ab38 100644 --- a/src/cluster/CMakeLists.txt +++ b/src/cluster/CMakeLists.txt @@ -1,6 +1,13 @@ add_library(clio_cluster) -target_sources(clio_cluster PRIVATE Backend.cpp ClioNode.cpp ClusterCommunicationService.cpp Metrics.cpp - WriterDecider.cpp) +target_sources( + clio_cluster + PRIVATE + Backend.cpp + ClioNode.cpp + ClusterCommunicationService.cpp + Metrics.cpp + WriterDecider.cpp +) target_link_libraries(clio_cluster PRIVATE clio_util clio_data) diff --git a/src/data/CMakeLists.txt b/src/data/CMakeLists.txt index d7d1b2d92..ef861f821 100644 --- a/src/data/CMakeLists.txt +++ b/src/data/CMakeLists.txt @@ -1,21 +1,27 @@ add_library(clio_data) -target_sources(clio_data - PRIVATE AmendmentCenter.cpp - BackendCounters.cpp - BackendInterface.cpp - LedgerCache.cpp - LedgerCacheSaver.cpp - LedgerHeaderCache.cpp - cassandra/impl/Future.cpp - cassandra/impl/Cluster.cpp - cassandra/impl/Batch.cpp - cassandra/impl/Result.cpp - cassandra/impl/Tuple.cpp - cassandra/impl/SslContext.cpp - cassandra/Handle.cpp - cassandra/SettingsProvider.cpp - impl/InputFile.cpp - impl/LedgerCacheFile.cpp - impl/OutputFile.cpp) +target_sources( + clio_data + PRIVATE + AmendmentCenter.cpp + BackendCounters.cpp + BackendInterface.cpp + LedgerCache.cpp + LedgerCacheSaver.cpp + LedgerHeaderCache.cpp + cassandra/impl/Future.cpp + cassandra/impl/Cluster.cpp + cassandra/impl/Batch.cpp + cassandra/impl/Result.cpp + cassandra/impl/Tuple.cpp + cassandra/impl/SslContext.cpp + cassandra/Handle.cpp + cassandra/SettingsProvider.cpp + impl/InputFile.cpp + impl/LedgerCacheFile.cpp + impl/OutputFile.cpp +) -target_link_libraries(clio_data PUBLIC cassandra-cpp-driver::cassandra-cpp-driver clio_util) +target_link_libraries( + clio_data + PUBLIC cassandra-cpp-driver::cassandra-cpp-driver clio_util +) diff --git a/src/etl/CMakeLists.txt b/src/etl/CMakeLists.txt index b9ec0a566..2b0ce2e0d 100644 --- a/src/etl/CMakeLists.txt +++ b/src/etl/CMakeLists.txt @@ -1,29 +1,32 @@ add_library(clio_etl) -target_sources(clio_etl - PRIVATE CacheLoaderSettings.cpp - ETLHelpers.cpp - ETLService.cpp - ETLState.cpp - LoadBalancer.cpp - MPTHelpers.cpp - NetworkValidatedLedgers.cpp - NFTHelpers.cpp - Source.cpp - WriterState.cpp - impl/AmendmentBlockHandler.cpp - impl/AsyncGrpcCall.cpp - impl/Extraction.cpp - impl/ForwardingSource.cpp - impl/GrpcSource.cpp - impl/Loading.cpp - impl/Monitor.cpp - impl/SubscriptionSource.cpp - impl/TaskManager.cpp - impl/ext/Cache.cpp - impl/ext/Core.cpp - impl/ext/MPT.cpp - impl/ext/NFT.cpp - impl/ext/Successor.cpp) +target_sources( + clio_etl + PRIVATE + CacheLoaderSettings.cpp + ETLHelpers.cpp + ETLService.cpp + ETLState.cpp + LoadBalancer.cpp + MPTHelpers.cpp + NetworkValidatedLedgers.cpp + NFTHelpers.cpp + Source.cpp + WriterState.cpp + impl/AmendmentBlockHandler.cpp + impl/AsyncGrpcCall.cpp + impl/Extraction.cpp + impl/ForwardingSource.cpp + impl/GrpcSource.cpp + impl/Loading.cpp + impl/Monitor.cpp + impl/SubscriptionSource.cpp + impl/TaskManager.cpp + impl/ext/Cache.cpp + impl/ext/Core.cpp + impl/ext/MPT.cpp + impl/ext/NFT.cpp + impl/ext/Successor.cpp +) target_link_libraries(clio_etl PUBLIC clio_data) diff --git a/src/feed/CMakeLists.txt b/src/feed/CMakeLists.txt index 481e74bd3..e136caca8 100644 --- a/src/feed/CMakeLists.txt +++ b/src/feed/CMakeLists.txt @@ -1,5 +1,12 @@ add_library(clio_feed) -target_sources(clio_feed PRIVATE SubscriptionManager.cpp impl/TransactionFeed.cpp impl/LedgerFeed.cpp - impl/ProposedTransactionFeed.cpp impl/SingleFeedBase.cpp) +target_sources( + clio_feed + PRIVATE + SubscriptionManager.cpp + impl/TransactionFeed.cpp + impl/LedgerFeed.cpp + impl/ProposedTransactionFeed.cpp + impl/SingleFeedBase.cpp +) target_link_libraries(clio_feed PRIVATE clio_util) diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index 8cb07ebbd..6ef5b0bc0 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -3,15 +3,21 @@ add_executable(clio_server) target_sources(clio_server PRIVATE Main.cpp) target_link_libraries(clio_server PRIVATE clio_app) -if (static) - if (san) +if(static) + if(san) message(FATAL_ERROR "Static linkage not allowed when using sanitizers") - elseif (is_appleclang) + elseif(is_appleclang) message(FATAL_ERROR "Static linkage not supported on AppleClang") - else () - target_link_options(# Note: -static-libstdc++ can statically link both libstdc++ and libc++ - clio_server PRIVATE -static-libstdc++ -static-libgcc) - endif () -endif () + else() + target_link_options( + # Note: -static-libstdc++ can statically link both libstdc++ and libc++ + clio_server + PRIVATE -static-libstdc++ -static-libgcc + ) + endif() +endif() -set_target_properties(clio_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +set_target_properties( + clio_server + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) diff --git a/src/migration/CMakeLists.txt b/src/migration/CMakeLists.txt index 5c629dd32..b62a09563 100644 --- a/src/migration/CMakeLists.txt +++ b/src/migration/CMakeLists.txt @@ -1,6 +1,13 @@ add_library(clio_migration) -target_sources(clio_migration PRIVATE MigrationApplication.cpp impl/MigrationManagerFactory.cpp MigratorStatus.cpp - cassandra/impl/ObjectsAdapter.cpp cassandra/impl/TransactionsAdapter.cpp) +target_sources( + clio_migration + PRIVATE + MigrationApplication.cpp + impl/MigrationManagerFactory.cpp + MigratorStatus.cpp + cassandra/impl/ObjectsAdapter.cpp + cassandra/impl/TransactionsAdapter.cpp +) target_link_libraries(clio_migration PRIVATE clio_util clio_data) diff --git a/src/rpc/CMakeLists.txt b/src/rpc/CMakeLists.txt index e313653d9..a23ed71af 100644 --- a/src/rpc/CMakeLists.txt +++ b/src/rpc/CMakeLists.txt @@ -6,53 +6,56 @@ target_link_libraries(clio_rpc_center PUBLIC clio_options) add_library(clio_rpc) -target_sources(clio_rpc - PRIVATE Errors.cpp - Factories.cpp - AMMHelpers.cpp - RPCHelpers.cpp - CredentialHelpers.cpp - Counters.cpp - WorkQueue.cpp - common/Specs.cpp - common/Validators.cpp - common/MetaProcessors.cpp - common/impl/APIVersionParser.cpp - common/impl/HandlerProvider.cpp - handlers/AccountChannels.cpp - handlers/AccountCurrencies.cpp - handlers/AccountInfo.cpp - handlers/AccountLines.cpp - handlers/AccountMPTokenIssuances.cpp - handlers/AccountMPTokens.cpp - handlers/AccountNFTs.cpp - handlers/AccountObjects.cpp - handlers/AccountOffers.cpp - handlers/AccountTx.cpp - handlers/AMMInfo.cpp - handlers/BookChanges.cpp - handlers/BookOffers.cpp - handlers/DepositAuthorized.cpp - handlers/Feature.cpp - handlers/GatewayBalances.cpp - handlers/GetAggregatePrice.cpp - handlers/Ledger.cpp - handlers/LedgerData.cpp - handlers/LedgerEntry.cpp - handlers/LedgerIndex.cpp - handlers/LedgerRange.cpp - handlers/MPTHolders.cpp - handlers/NFTsByIssuer.cpp - handlers/NFTBuyOffers.cpp - handlers/NFTHistory.cpp - handlers/NFTInfo.cpp - handlers/NFTOffersCommon.cpp - handlers/NFTSellOffers.cpp - handlers/NoRippleCheck.cpp - handlers/Random.cpp - handlers/Subscribe.cpp - handlers/TransactionEntry.cpp - handlers/Unsubscribe.cpp - handlers/VaultInfo.cpp) +target_sources( + clio_rpc + PRIVATE + Errors.cpp + Factories.cpp + AMMHelpers.cpp + RPCHelpers.cpp + CredentialHelpers.cpp + Counters.cpp + WorkQueue.cpp + common/Specs.cpp + common/Validators.cpp + common/MetaProcessors.cpp + common/impl/APIVersionParser.cpp + common/impl/HandlerProvider.cpp + handlers/AccountChannels.cpp + handlers/AccountCurrencies.cpp + handlers/AccountInfo.cpp + handlers/AccountLines.cpp + handlers/AccountMPTokenIssuances.cpp + handlers/AccountMPTokens.cpp + handlers/AccountNFTs.cpp + handlers/AccountObjects.cpp + handlers/AccountOffers.cpp + handlers/AccountTx.cpp + handlers/AMMInfo.cpp + handlers/BookChanges.cpp + handlers/BookOffers.cpp + handlers/DepositAuthorized.cpp + handlers/Feature.cpp + handlers/GatewayBalances.cpp + handlers/GetAggregatePrice.cpp + handlers/Ledger.cpp + handlers/LedgerData.cpp + handlers/LedgerEntry.cpp + handlers/LedgerIndex.cpp + handlers/LedgerRange.cpp + handlers/MPTHolders.cpp + handlers/NFTsByIssuer.cpp + handlers/NFTBuyOffers.cpp + handlers/NFTHistory.cpp + handlers/NFTInfo.cpp + handlers/NFTOffersCommon.cpp + handlers/NFTSellOffers.cpp + handlers/NoRippleCheck.cpp + handlers/Random.cpp + handlers/Subscribe.cpp + handlers/TransactionEntry.cpp + handlers/Unsubscribe.cpp + handlers/VaultInfo.cpp +) target_link_libraries(clio_rpc PRIVATE clio_util) diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index d43ec456f..ee7031565 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -2,64 +2,69 @@ add_subdirectory(build) add_library(clio_util) -target_sources(clio_util - PRIVATE Assert.cpp - Coroutine.cpp - CoroutineGroup.cpp - log/Logger.cpp - log/PrettyPath.cpp - prometheus/Http.cpp - prometheus/Label.cpp - prometheus/MetricBase.cpp - prometheus/MetricBuilder.cpp - prometheus/MetricsFamily.cpp - prometheus/OStream.cpp - prometheus/Prometheus.cpp - Random.cpp - Retry.cpp - Repeat.cpp - requests/RequestBuilder.cpp - requests/Types.cpp - requests/WsConnection.cpp - requests/impl/SslContext.cpp - ResponseExpirationCache.cpp - Shasum.cpp - SignalsHandler.cpp - StopHelper.cpp - StringHash.cpp - Taggable.cpp - TerminationHandler.cpp - TimeUtils.cpp - TxUtils.cpp - LedgerUtils.cpp - config/Array.cpp - config/ArrayView.cpp - config/ConfigConstraints.cpp - config/ConfigDefinition.cpp - config/ConfigFileJson.cpp - config/ObjectView.cpp - config/Types.cpp - config/ValueView.cpp) +target_sources( + clio_util + PRIVATE + Assert.cpp + Coroutine.cpp + CoroutineGroup.cpp + log/Logger.cpp + log/PrettyPath.cpp + prometheus/Http.cpp + prometheus/Label.cpp + prometheus/MetricBase.cpp + prometheus/MetricBuilder.cpp + prometheus/MetricsFamily.cpp + prometheus/OStream.cpp + prometheus/Prometheus.cpp + Random.cpp + Retry.cpp + Repeat.cpp + requests/RequestBuilder.cpp + requests/Types.cpp + requests/WsConnection.cpp + requests/impl/SslContext.cpp + ResponseExpirationCache.cpp + Shasum.cpp + SignalsHandler.cpp + StopHelper.cpp + StringHash.cpp + Taggable.cpp + TerminationHandler.cpp + TimeUtils.cpp + TxUtils.cpp + LedgerUtils.cpp + config/Array.cpp + config/ArrayView.cpp + config/ConfigConstraints.cpp + config/ConfigDefinition.cpp + config/ConfigFileJson.cpp + config/ObjectView.cpp + config/Types.cpp + config/ValueView.cpp +) # This must be above the target_link_libraries call otherwise backtrace doesn't work -if ("${san}" STREQUAL "") +if("${san}" STREQUAL "") target_link_libraries(clio_util PUBLIC Boost::stacktrace_backtrace) -endif () +endif() target_link_libraries( clio_util - PUBLIC Boost::headers - Boost::iostreams - Boost::coroutine - Boost::context - fmt::fmt - openssl::openssl - xrpl::libxrpl - Threads::Threads - clio_options - clio_rpc_center - clio_build_version - PRIVATE spdlog::spdlog) + PUBLIC + Boost::headers + Boost::iostreams + Boost::coroutine + Boost::context + fmt::fmt + openssl::openssl + xrpl::libxrpl + Threads::Threads + clio_options + clio_rpc_center + clio_build_version + PRIVATE spdlog::spdlog +) # FIXME: needed on gcc-12, clang-16 and AppleClang for now (known boost 1.82 issue for some compilers) # diff --git a/src/util/build/CMakeLists.txt b/src/util/build/CMakeLists.txt index 1049a3470..f8475d467 100644 --- a/src/util/build/CMakeLists.txt +++ b/src/util/build/CMakeLists.txt @@ -4,5 +4,10 @@ add_library(clio_build_version) target_sources(clio_build_version PRIVATE Build.cpp) target_link_libraries(clio_build_version PUBLIC clio_options) target_compile_definitions( - clio_build_version PRIVATE CLIO_VERSION="${CLIO_VERSION}" GIT_COMMIT_HASH="${GIT_COMMIT_HASH}" - GIT_BUILD_BRANCH="${GIT_BUILD_BRANCH}" BUILD_DATE="${BUILD_DATE}") + clio_build_version + PRIVATE + CLIO_VERSION="${CLIO_VERSION}" + GIT_COMMIT_HASH="${GIT_COMMIT_HASH}" + GIT_BUILD_BRANCH="${GIT_BUILD_BRANCH}" + BUILD_DATE="${BUILD_DATE}" +) diff --git a/src/web/CMakeLists.txt b/src/web/CMakeLists.txt index e8396a623..facc5e258 100644 --- a/src/web/CMakeLists.txt +++ b/src/web/CMakeLists.txt @@ -1,21 +1,24 @@ add_library(clio_web) -target_sources(clio_web - PRIVATE AdminVerificationStrategy.cpp - dosguard/DOSGuard.cpp - dosguard/IntervalSweepHandler.cpp - dosguard/Weights.cpp - dosguard/WhitelistHandler.cpp - ng/Connection.cpp - ng/impl/ErrorHandling.cpp - ng/impl/ConnectionHandler.cpp - ng/impl/ServerSslContext.cpp - ng/Request.cpp - ng/Response.cpp - ng/Server.cpp - ng/SubscriptionContext.cpp - ProxyIpResolver.cpp - Resolver.cpp - SubscriptionContext.cpp) +target_sources( + clio_web + PRIVATE + AdminVerificationStrategy.cpp + dosguard/DOSGuard.cpp + dosguard/IntervalSweepHandler.cpp + dosguard/Weights.cpp + dosguard/WhitelistHandler.cpp + ng/Connection.cpp + ng/impl/ErrorHandling.cpp + ng/impl/ConnectionHandler.cpp + ng/impl/ServerSslContext.cpp + ng/Request.cpp + ng/Response.cpp + ng/Server.cpp + ng/SubscriptionContext.cpp + ProxyIpResolver.cpp + Resolver.cpp + SubscriptionContext.cpp +) target_link_libraries(clio_web PUBLIC clio_util) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dabf0a905..e40ef225f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,20 +1,20 @@ # Set coverage build options -if (coverage) - if (NOT tests) +if(coverage) + if(NOT tests) message(FATAL_ERROR "Coverage requires tests to be enabled") - endif () + endif() include(CodeCoverage) append_coverage_compiler_flags_to_target(clio_options INTERFACE) -endif () +endif() -if (tests OR integration_tests) +if(tests OR integration_tests) add_subdirectory(common) -endif () +endif() -if (tests) +if(tests) add_subdirectory(unit) -endif () +endif() -if (integration_tests) +if(integration_tests) add_subdirectory(integration) -endif () +endif() diff --git a/tests/common/CMakeLists.txt b/tests/common/CMakeLists.txt index c2a1c79eb..bd5f7c52b 100644 --- a/tests/common/CMakeLists.txt +++ b/tests/common/CMakeLists.txt @@ -1,19 +1,26 @@ add_library(clio_testing_common) -target_sources(clio_testing_common - PRIVATE util/AssignRandomPort.cpp - util/BinaryTestObject.cpp - util/CallWithTimeout.cpp - util/LoggerFixtures.cpp - util/MockAssert.cpp - util/StringUtils.cpp - util/TestHttpClient.cpp - util/TestHttpServer.cpp - util/TestObject.cpp - util/TestWebSocketClient.cpp - util/TestWsServer.cpp) +target_sources( + clio_testing_common + PRIVATE + util/AssignRandomPort.cpp + util/BinaryTestObject.cpp + util/CallWithTimeout.cpp + util/LoggerFixtures.cpp + util/MockAssert.cpp + util/StringUtils.cpp + util/TestHttpClient.cpp + util/TestHttpServer.cpp + util/TestObject.cpp + util/TestWebSocketClient.cpp + util/TestWsServer.cpp +) include(deps/gtest) target_include_directories(clio_testing_common PUBLIC .) -target_link_libraries(clio_testing_common PUBLIC clio_app gtest::gtest PRIVATE spdlog::spdlog) +target_link_libraries( + clio_testing_common + PUBLIC clio_app gtest::gtest + PRIVATE spdlog::spdlog +) diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 817232a52..b9312eed1 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -1,20 +1,30 @@ add_executable(clio_integration_tests) -target_sources(clio_integration_tests - PRIVATE data/BackendFactoryTests.cpp - data/cassandra/BackendTests.cpp - data/cassandra/BaseTests.cpp - migration/cassandra/DBRawData.cpp - migration/cassandra/CassandraMigrationManagerTests.cpp - migration/cassandra/ExampleTransactionsMigrator.cpp - migration/cassandra/ExampleObjectsMigrator.cpp - migration/cassandra/ExampleLedgerMigrator.cpp - migration/cassandra/ExampleDropTableMigrator.cpp - util/CassandraDBHelper.cpp - # Test runner - TestGlobals.cpp - Main.cpp) +target_sources( + clio_integration_tests + PRIVATE + data/BackendFactoryTests.cpp + data/cassandra/BackendTests.cpp + data/cassandra/BaseTests.cpp + migration/cassandra/DBRawData.cpp + migration/cassandra/CassandraMigrationManagerTests.cpp + migration/cassandra/ExampleTransactionsMigrator.cpp + migration/cassandra/ExampleObjectsMigrator.cpp + migration/cassandra/ExampleLedgerMigrator.cpp + migration/cassandra/ExampleDropTableMigrator.cpp + util/CassandraDBHelper.cpp + # Test runner + TestGlobals.cpp + Main.cpp +) target_include_directories(clio_integration_tests PRIVATE .) -target_link_libraries(clio_integration_tests PUBLIC clio_testing_common PRIVATE Boost::program_options) -set_target_properties(clio_integration_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +target_link_libraries( + clio_integration_tests + PUBLIC clio_testing_common + PRIVATE Boost::program_options +) +set_target_properties( + clio_integration_tests + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 693e10c66..d1fa709d6 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -1,245 +1,255 @@ add_executable(clio_tests) -target_sources(clio_tests - PRIVATE # Common - app/CliArgsTests.cpp - app/StopperTests.cpp - app/VerifyConfigTests.cpp - app/WebHandlersTests.cpp - data/AmendmentCenterTests.cpp - data/BackendCountersTests.cpp - data/BackendInterfaceTests.cpp - data/LedgerCacheTests.cpp - data/LedgerCacheSaverTests.cpp - data/cassandra/AsyncExecutorTests.cpp - data/cassandra/ExecutionStrategyTests.cpp - data/cassandra/LedgerHeaderCacheTests.cpp - data/cassandra/RetryPolicyTests.cpp - data/cassandra/SettingsProviderTests.cpp - data/impl/InputFileTests.cpp - data/impl/LedgerCacheFileTests.cpp - data/impl/OutputFileTests.cpp - # Cluster - cluster/BackendTests.cpp - cluster/ClioNodeTests.cpp - cluster/ClusterCommunicationServiceTests.cpp - cluster/MetricsTests.cpp - cluster/RepeatedTaskTests.cpp - cluster/WriterDeciderTests.cpp - # ETL - etl/AmendmentBlockHandlerTests.cpp - etl/CacheLoaderSettingsTests.cpp - etl/CacheLoaderTests.cpp - etl/CursorFromAccountProviderTests.cpp - etl/CursorFromDiffProviderTests.cpp - etl/CursorFromFixDiffNumProviderTests.cpp - etl/CorruptionDetectorTests.cpp - etl/ETLStateTests.cpp - etl/ETLServiceTests.cpp - etl/ExtractionTests.cpp - etl/ForwardingSourceTests.cpp - etl/GrpcSourceTests.cpp - etl/LedgerPublisherTests.cpp - etl/LoadBalancerTests.cpp - etl/LoadingTests.cpp - etl/MonitorTests.cpp - etl/NetworkValidatedLedgersTests.cpp - etl/NFTHelpersTests.cpp - etl/RegistryTests.cpp - etl/SchedulingTests.cpp - etl/SourceImplTests.cpp - etl/SubscriptionSourceTests.cpp - etl/SystemStateTests.cpp - etl/TaskManagerTests.cpp - etl/WriterStateTests.cpp - etl/ext/CoreTests.cpp - etl/ext/CacheTests.cpp - etl/ext/MPTTests.cpp - etl/ext/NFTTests.cpp - etl/ext/SuccessorTests.cpp - # Feed - feed/BookChangesFeedTests.cpp - feed/ForwardFeedTests.cpp - feed/LedgerFeedTests.cpp - feed/ProposedTransactionFeedTests.cpp - feed/SingleFeedBaseTests.cpp - feed/SubscriptionManagerTests.cpp - feed/TrackableSignalTests.cpp - feed/TransactionFeedTests.cpp - # Logging - util/log/LogServiceInitTests.cpp - util/log/LoggerTests.cpp - util/log/PrettyPathTests.cpp - # Other - JsonUtilTests.cpp - Main.cpp - Playground.cpp - ProfilerTests.cpp - # Migration - migration/cassandra/FullTableScannerTests.cpp - migration/cassandra/SpecTests.cpp - migration/MigratorRegisterTests.cpp - migration/MigratorStatusTests.cpp - migration/MigrationInspectorFactoryTests.cpp - migration/MigrationInspectorBaseTests.cpp - migration/MigrationManagerBaseTests.cpp - migration/MigrationManagerFactoryTests.cpp - migration/SpecTests.cpp - # RPC - rpc/APIVersionTests.cpp - rpc/BaseTests.cpp - rpc/CountersTests.cpp - rpc/ErrorTests.cpp - rpc/ForwardingProxyTests.cpp - rpc/common/CheckersTests.cpp - rpc/common/SpecsTests.cpp - rpc/common/TypesTests.cpp - rpc/common/impl/HandlerProviderTests.cpp - rpc/handlers/AccountChannelsTests.cpp - rpc/handlers/AccountCurrenciesTests.cpp - rpc/handlers/AccountInfoTests.cpp - rpc/handlers/AccountLinesTests.cpp - rpc/handlers/AccountMPTokenIssuancesTests.cpp - rpc/handlers/AccountMPTokensTests.cpp - rpc/handlers/AccountNFTsTests.cpp - rpc/handlers/AccountObjectsTests.cpp - rpc/handlers/AccountOffersTests.cpp - rpc/handlers/AccountTxTests.cpp - rpc/handlers/AMMInfoTests.cpp - rpc/handlers/AllHandlerTests.cpp - rpc/handlers/BookChangesTests.cpp - rpc/handlers/BookOffersTests.cpp - rpc/handlers/CredentialHelpersTests.cpp - rpc/handlers/DefaultProcessorTests.cpp - rpc/handlers/DepositAuthorizedTests.cpp - rpc/handlers/FeatureTests.cpp - rpc/handlers/GatewayBalancesTests.cpp - rpc/handlers/GetAggregatePriceTests.cpp - rpc/handlers/LedgerDataTests.cpp - rpc/handlers/LedgerEntryTests.cpp - rpc/handlers/LedgerIndexTests.cpp - rpc/handlers/LedgerRangeTests.cpp - rpc/handlers/LedgerTests.cpp - rpc/handlers/MPTHoldersTests.cpp - rpc/handlers/NFTBuyOffersTests.cpp - rpc/handlers/NFTHistoryTests.cpp - rpc/handlers/NFTInfoTests.cpp - rpc/handlers/NFTsByIssuerTest.cpp - rpc/handlers/NFTSellOffersTests.cpp - rpc/handlers/NoRippleCheckTests.cpp - rpc/handlers/PingTests.cpp - rpc/handlers/RandomTests.cpp - rpc/handlers/ServerInfoTests.cpp - rpc/handlers/SubscribeTests.cpp - rpc/handlers/TestHandlerTests.cpp - rpc/handlers/TransactionEntryTests.cpp - rpc/handlers/TxTests.cpp - rpc/handlers/UnsubscribeTests.cpp - rpc/handlers/VersionHandlerTests.cpp - rpc/handlers/VaultInfoTests.cpp - rpc/JsonBoolTests.cpp - rpc/RPCEngineTests.cpp - rpc/RPCHelpersTests.cpp - rpc/WorkQueueTests.cpp - test_data/SslCert.cpp - # Async framework - util/async/AnyExecutionContextTests.cpp - util/async/AnyOperationTests.cpp - util/async/AnyStopTokenTests.cpp - util/async/AnyStrandTests.cpp - util/async/AsyncExecutionContextTests.cpp - util/BatchingTests.cpp - util/BlockingCacheTests.cpp - util/ConceptsTests.cpp - util/CoroutineGroupTests.cpp - util/LedgerUtilsTests.cpp - util/StringHashTests.cpp - # Prometheus support - util/prometheus/BoolTests.cpp - util/prometheus/CounterTests.cpp - util/prometheus/GaugeTests.cpp - util/prometheus/HistogramTests.cpp - util/prometheus/HttpTests.cpp - util/prometheus/LabelTests.cpp - util/prometheus/MetricBuilderTests.cpp - util/prometheus/MetricsFamilyTests.cpp - util/prometheus/OStreamTests.cpp - # Requests framework - util/requests/RequestBuilderTests.cpp - util/requests/SslContextTests.cpp - util/requests/WsConnectionTests.cpp - # Common utils - util/AccountUtilsTests.cpp - util/AssertTests.cpp - util/BytesConverterTests.cpp - util/ChannelTests.cpp - util/CoroutineTest.cpp - util/MoveTrackerTests.cpp - util/ObservableValueTest.cpp - util/ObservableValueAtomicTest.cpp - util/RandomTests.cpp - util/RepeatTests.cpp - util/ResponseExpirationCacheTests.cpp - util/RetryTests.cpp - util/ScopeGuardTests.cpp - util/SignalsHandlerTests.cpp - util/ShasumTests.cpp - util/SpawnTests.cpp - util/StopHelperTests.cpp - util/TimeUtilsTests.cpp - util/TxUtilTests.cpp - util/WithTimeout.cpp - # Webserver - web/AdminVerificationTests.cpp - web/dosguard/DOSGuardTests.cpp - web/dosguard/IntervalSweepHandlerTests.cpp - web/dosguard/WeightsTests.cpp - web/dosguard/WhitelistHandlerTests.cpp - web/impl/ErrorHandlingTests.cpp - web/ng/ResponseTests.cpp - web/ng/RequestTests.cpp - web/ng/RPCServerHandlerTests.cpp - web/ng/ServerTests.cpp - web/ng/SubscriptionContextTests.cpp - web/ng/impl/ConnectionHandlerTests.cpp - web/ng/impl/ErrorHandlingTests.cpp - web/ng/impl/HttpConnectionTests.cpp - web/ng/impl/ServerSslContextTests.cpp - web/ng/impl/WsConnectionTests.cpp - web/ProxyIpResolverTests.cpp - web/RPCServerHandlerTests.cpp - web/ServerTests.cpp - web/SubscriptionContextTests.cpp - # Config - util/config/ArrayTests.cpp - util/config/ArrayViewTests.cpp - util/config/ClioConfigDefinitionTests.cpp - util/config/ConfigValueTests.cpp - util/config/ObjectViewTests.cpp - util/config/ConfigFileJsonTests.cpp - util/config/ValueViewTests.cpp) +target_sources( + clio_tests + PRIVATE + # Common + app/CliArgsTests.cpp + app/StopperTests.cpp + app/VerifyConfigTests.cpp + app/WebHandlersTests.cpp + data/AmendmentCenterTests.cpp + data/BackendCountersTests.cpp + data/BackendInterfaceTests.cpp + data/LedgerCacheTests.cpp + data/LedgerCacheSaverTests.cpp + data/cassandra/AsyncExecutorTests.cpp + data/cassandra/ExecutionStrategyTests.cpp + data/cassandra/LedgerHeaderCacheTests.cpp + data/cassandra/RetryPolicyTests.cpp + data/cassandra/SettingsProviderTests.cpp + data/impl/InputFileTests.cpp + data/impl/LedgerCacheFileTests.cpp + data/impl/OutputFileTests.cpp + # Cluster + cluster/BackendTests.cpp + cluster/ClioNodeTests.cpp + cluster/ClusterCommunicationServiceTests.cpp + cluster/MetricsTests.cpp + cluster/RepeatedTaskTests.cpp + cluster/WriterDeciderTests.cpp + # ETL + etl/AmendmentBlockHandlerTests.cpp + etl/CacheLoaderSettingsTests.cpp + etl/CacheLoaderTests.cpp + etl/CursorFromAccountProviderTests.cpp + etl/CursorFromDiffProviderTests.cpp + etl/CursorFromFixDiffNumProviderTests.cpp + etl/CorruptionDetectorTests.cpp + etl/ETLStateTests.cpp + etl/ETLServiceTests.cpp + etl/ExtractionTests.cpp + etl/ForwardingSourceTests.cpp + etl/GrpcSourceTests.cpp + etl/LedgerPublisherTests.cpp + etl/LoadBalancerTests.cpp + etl/LoadingTests.cpp + etl/MonitorTests.cpp + etl/NetworkValidatedLedgersTests.cpp + etl/NFTHelpersTests.cpp + etl/RegistryTests.cpp + etl/SchedulingTests.cpp + etl/SourceImplTests.cpp + etl/SubscriptionSourceTests.cpp + etl/SystemStateTests.cpp + etl/TaskManagerTests.cpp + etl/WriterStateTests.cpp + etl/ext/CoreTests.cpp + etl/ext/CacheTests.cpp + etl/ext/MPTTests.cpp + etl/ext/NFTTests.cpp + etl/ext/SuccessorTests.cpp + # Feed + feed/BookChangesFeedTests.cpp + feed/ForwardFeedTests.cpp + feed/LedgerFeedTests.cpp + feed/ProposedTransactionFeedTests.cpp + feed/SingleFeedBaseTests.cpp + feed/SubscriptionManagerTests.cpp + feed/TrackableSignalTests.cpp + feed/TransactionFeedTests.cpp + # Logging + util/log/LogServiceInitTests.cpp + util/log/LoggerTests.cpp + util/log/PrettyPathTests.cpp + # Other + JsonUtilTests.cpp + Main.cpp + Playground.cpp + ProfilerTests.cpp + # Migration + migration/cassandra/FullTableScannerTests.cpp + migration/cassandra/SpecTests.cpp + migration/MigratorRegisterTests.cpp + migration/MigratorStatusTests.cpp + migration/MigrationInspectorFactoryTests.cpp + migration/MigrationInspectorBaseTests.cpp + migration/MigrationManagerBaseTests.cpp + migration/MigrationManagerFactoryTests.cpp + migration/SpecTests.cpp + # RPC + rpc/APIVersionTests.cpp + rpc/BaseTests.cpp + rpc/CountersTests.cpp + rpc/ErrorTests.cpp + rpc/ForwardingProxyTests.cpp + rpc/common/CheckersTests.cpp + rpc/common/SpecsTests.cpp + rpc/common/TypesTests.cpp + rpc/common/impl/HandlerProviderTests.cpp + rpc/handlers/AccountChannelsTests.cpp + rpc/handlers/AccountCurrenciesTests.cpp + rpc/handlers/AccountInfoTests.cpp + rpc/handlers/AccountLinesTests.cpp + rpc/handlers/AccountMPTokenIssuancesTests.cpp + rpc/handlers/AccountMPTokensTests.cpp + rpc/handlers/AccountNFTsTests.cpp + rpc/handlers/AccountObjectsTests.cpp + rpc/handlers/AccountOffersTests.cpp + rpc/handlers/AccountTxTests.cpp + rpc/handlers/AMMInfoTests.cpp + rpc/handlers/AllHandlerTests.cpp + rpc/handlers/BookChangesTests.cpp + rpc/handlers/BookOffersTests.cpp + rpc/handlers/CredentialHelpersTests.cpp + rpc/handlers/DefaultProcessorTests.cpp + rpc/handlers/DepositAuthorizedTests.cpp + rpc/handlers/FeatureTests.cpp + rpc/handlers/GatewayBalancesTests.cpp + rpc/handlers/GetAggregatePriceTests.cpp + rpc/handlers/LedgerDataTests.cpp + rpc/handlers/LedgerEntryTests.cpp + rpc/handlers/LedgerIndexTests.cpp + rpc/handlers/LedgerRangeTests.cpp + rpc/handlers/LedgerTests.cpp + rpc/handlers/MPTHoldersTests.cpp + rpc/handlers/NFTBuyOffersTests.cpp + rpc/handlers/NFTHistoryTests.cpp + rpc/handlers/NFTInfoTests.cpp + rpc/handlers/NFTsByIssuerTest.cpp + rpc/handlers/NFTSellOffersTests.cpp + rpc/handlers/NoRippleCheckTests.cpp + rpc/handlers/PingTests.cpp + rpc/handlers/RandomTests.cpp + rpc/handlers/ServerInfoTests.cpp + rpc/handlers/SubscribeTests.cpp + rpc/handlers/TestHandlerTests.cpp + rpc/handlers/TransactionEntryTests.cpp + rpc/handlers/TxTests.cpp + rpc/handlers/UnsubscribeTests.cpp + rpc/handlers/VersionHandlerTests.cpp + rpc/handlers/VaultInfoTests.cpp + rpc/JsonBoolTests.cpp + rpc/RPCEngineTests.cpp + rpc/RPCHelpersTests.cpp + rpc/WorkQueueTests.cpp + test_data/SslCert.cpp + # Async framework + util/async/AnyExecutionContextTests.cpp + util/async/AnyOperationTests.cpp + util/async/AnyStopTokenTests.cpp + util/async/AnyStrandTests.cpp + util/async/AsyncExecutionContextTests.cpp + util/BatchingTests.cpp + util/BlockingCacheTests.cpp + util/ConceptsTests.cpp + util/CoroutineGroupTests.cpp + util/LedgerUtilsTests.cpp + util/StringHashTests.cpp + # Prometheus support + util/prometheus/BoolTests.cpp + util/prometheus/CounterTests.cpp + util/prometheus/GaugeTests.cpp + util/prometheus/HistogramTests.cpp + util/prometheus/HttpTests.cpp + util/prometheus/LabelTests.cpp + util/prometheus/MetricBuilderTests.cpp + util/prometheus/MetricsFamilyTests.cpp + util/prometheus/OStreamTests.cpp + # Requests framework + util/requests/RequestBuilderTests.cpp + util/requests/SslContextTests.cpp + util/requests/WsConnectionTests.cpp + # Common utils + util/AccountUtilsTests.cpp + util/AssertTests.cpp + util/BytesConverterTests.cpp + util/ChannelTests.cpp + util/CoroutineTest.cpp + util/MoveTrackerTests.cpp + util/ObservableValueTest.cpp + util/ObservableValueAtomicTest.cpp + util/RandomTests.cpp + util/RepeatTests.cpp + util/ResponseExpirationCacheTests.cpp + util/RetryTests.cpp + util/ScopeGuardTests.cpp + util/SignalsHandlerTests.cpp + util/ShasumTests.cpp + util/SpawnTests.cpp + util/StopHelperTests.cpp + util/TimeUtilsTests.cpp + util/TxUtilTests.cpp + util/WithTimeout.cpp + # Webserver + web/AdminVerificationTests.cpp + web/dosguard/DOSGuardTests.cpp + web/dosguard/IntervalSweepHandlerTests.cpp + web/dosguard/WeightsTests.cpp + web/dosguard/WhitelistHandlerTests.cpp + web/impl/ErrorHandlingTests.cpp + web/ng/ResponseTests.cpp + web/ng/RequestTests.cpp + web/ng/RPCServerHandlerTests.cpp + web/ng/ServerTests.cpp + web/ng/SubscriptionContextTests.cpp + web/ng/impl/ConnectionHandlerTests.cpp + web/ng/impl/ErrorHandlingTests.cpp + web/ng/impl/HttpConnectionTests.cpp + web/ng/impl/ServerSslContextTests.cpp + web/ng/impl/WsConnectionTests.cpp + web/ProxyIpResolverTests.cpp + web/RPCServerHandlerTests.cpp + web/ServerTests.cpp + web/SubscriptionContextTests.cpp + # Config + util/config/ArrayTests.cpp + util/config/ArrayViewTests.cpp + util/config/ClioConfigDefinitionTests.cpp + util/config/ConfigValueTests.cpp + util/config/ObjectViewTests.cpp + util/config/ConfigFileJsonTests.cpp + util/config/ValueViewTests.cpp +) # See https://github.com/google/googletest/issues/3475 gtest_discover_tests(clio_tests DISCOVERY_TIMEOUT 90) target_include_directories(clio_tests PRIVATE .) -target_link_libraries(clio_tests PUBLIC clio_testing_common PRIVATE spdlog::spdlog) -set_target_properties(clio_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +target_link_libraries( + clio_tests + PUBLIC clio_testing_common + PRIVATE spdlog::spdlog +) +set_target_properties( + clio_tests + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) # Generate `coverage_report` target if coverage is enabled -if (coverage) - if (DEFINED CODE_COVERAGE_REPORT_FORMAT) +if(coverage) + if(DEFINED CODE_COVERAGE_REPORT_FORMAT) set(CODE_COVERAGE_FORMAT ${CODE_COVERAGE_REPORT_FORMAT}) - else () + else() set(CODE_COVERAGE_FORMAT html-details) - endif () + endif() - if (DEFINED CODE_COVERAGE_TESTS_ARGS) + if(DEFINED CODE_COVERAGE_TESTS_ARGS) set(TESTS_ADDITIONAL_ARGS ${CODE_COVERAGE_TESTS_ARGS}) separate_arguments(TESTS_ADDITIONAL_ARGS) - else () + else() set(TESTS_ADDITIONAL_ARGS "") - endif () + endif() set(GCOVR_ADDITIONAL_ARGS --exclude-throw-branches -s) @@ -259,5 +269,6 @@ if (coverage) "src/data/CassandraBackend.hpp" "src/data/BackendFactory.*" DEPENDENCIES - clio_tests) -endif () + clio_tests + ) +endif() diff --git a/tools/snapshot/CMakeLists.txt b/tools/snapshot/CMakeLists.txt index 1d3eeeaf3..26ba797ea 100644 --- a/tools/snapshot/CMakeLists.txt +++ b/tools/snapshot/CMakeLists.txt @@ -13,9 +13,14 @@ set(PROTO_FILES ${PROTO_SOURCE_DIR}/get_ledger.proto ${PROTO_SOURCE_DIR}/get_ledger_entry.proto ${PROTO_SOURCE_DIR}/get_ledger_data.proto - ${PROTO_SOURCE_DIR}/get_ledger_diff.proto) + ${PROTO_SOURCE_DIR}/get_ledger_diff.proto +) -execute_process(COMMAND go env GOPATH OUTPUT_VARIABLE GOPATH_VALUE OUTPUT_STRIP_TRAILING_WHITESPACE) +execute_process( + COMMAND go env GOPATH + OUTPUT_VARIABLE GOPATH_VALUE + OUTPUT_STRIP_TRAILING_WHITESPACE +) # Target Go package path set(GO_IMPORT_PATH "org/xrpl/rpc/v1") @@ -25,36 +30,51 @@ set(GO_OPTS "") set(GRPC_OPTS "") # Loop through each proto file -foreach (proto ${PROTO_FILES}) +foreach(proto ${PROTO_FILES}) get_filename_component(proto_filename ${proto} NAME) # Build the --go_opt and --go-grpc_opt mappings - set(GO_OPTS ${GO_OPTS} --go_opt=M${GO_IMPORT_PATH}/${proto_filename}=${GO_IMPORT_PATH}) - set(GRPC_OPTS ${GRPC_OPTS} --go-grpc_opt=M${GO_IMPORT_PATH}/${proto_filename}=${GO_IMPORT_PATH}) -endforeach () + set(GO_OPTS + ${GO_OPTS} + --go_opt=M${GO_IMPORT_PATH}/${proto_filename}=${GO_IMPORT_PATH} + ) + set(GRPC_OPTS + ${GRPC_OPTS} + --go-grpc_opt=M${GO_IMPORT_PATH}/${proto_filename}=${GO_IMPORT_PATH} + ) +endforeach() -foreach (proto ${PROTO_FILES}) +foreach(proto ${PROTO_FILES}) get_filename_component(proto_name ${proto} NAME_WE) add_custom_command( OUTPUT ${GO_SOURCE_DIR}/${GO_IMPORT_PATH}/${proto_name}.pb.go - COMMAND protoc ${GO_OPTS} ${GRPC_OPTS} --go-grpc_out=${GO_SOURCE_DIR} -I${PROTO_INC_DIR} ${proto} - --plugin=${GOPATH_VALUE}/bin/protoc-gen-go --plugin=${GOPATH_VALUE}/bin/protoc-gen-go-grpc - --go_out=${GO_SOURCE_DIR}/ + COMMAND + protoc ${GO_OPTS} ${GRPC_OPTS} --go-grpc_out=${GO_SOURCE_DIR} + -I${PROTO_INC_DIR} ${proto} + --plugin=${GOPATH_VALUE}/bin/protoc-gen-go + --plugin=${GOPATH_VALUE}/bin/protoc-gen-go-grpc + --go_out=${GO_SOURCE_DIR}/ DEPENDS ${proto} COMMENT "Generating Go code for ${proto}" - VERBATIM) + VERBATIM + ) - list(APPEND GENERATED_GO_FILES ${GO_SOURCE_DIR}/${GO_IMPORT_PATH}/${proto_name}.pb.go) -endforeach () + list( + APPEND GENERATED_GO_FILES + ${GO_SOURCE_DIR}/${GO_IMPORT_PATH}/${proto_name}.pb.go + ) +endforeach() add_custom_target(build_clio_snapshot ALL DEPENDS run_go_tests ${GO_OUTPUT}) -add_custom_target(run_go_tests - COMMAND go test ./... - WORKING_DIRECTORY ${GO_SOURCE_DIR} - DEPENDS ${GENERATED_GO_FILES} - COMMENT "Running clio_snapshot unittests" - VERBATIM) +add_custom_target( + run_go_tests + COMMAND go test ./... + WORKING_DIRECTORY ${GO_SOURCE_DIR} + DEPENDS ${GENERATED_GO_FILES} + COMMENT "Running clio_snapshot unittests" + VERBATIM +) add_custom_command( OUTPUT ${GO_OUTPUT} @@ -62,4 +82,5 @@ add_custom_command( WORKING_DIRECTORY ${GO_SOURCE_DIR} DEPENDS ${GO_SOURCES} COMMENT "Building clio_snapshot" - VERBATIM) + VERBATIM +)