From af0ec7defdac8dde0c32fec58e79f70c6a7fcf77 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Thu, 5 Mar 2026 19:18:31 +0000 Subject: [PATCH] chore: Apply gersemi changes (#6486) --- CMakeLists.txt | 97 ++++--- cmake/CMakeFuncs.cmake | 37 +-- cmake/Ccache.cmake | 52 ++-- cmake/CodeCoverage.cmake | 415 ++++++++++++++++++---------- cmake/CompilationEnv.cmake | 30 +- cmake/GitInfo.cmake | 19 +- cmake/XrplAddTest.cmake | 12 +- cmake/XrplCompiler.cmake | 283 ++++++++++--------- cmake/XrplConfig.cmake | 70 ++--- cmake/XrplCore.cmake | 183 ++++++++---- cmake/XrplCov.cmake | 37 +-- cmake/XrplDocs.cmake | 77 +++--- cmake/XrplInstall.cmake | 114 +++++--- cmake/XrplInterface.cmake | 108 ++++---- cmake/XrplSanitizers.cmake | 132 +++++---- cmake/XrplSanity.cmake | 55 ++-- cmake/XrplSettings.cmake | 140 ++++++---- cmake/XrplValidatorKeys.cmake | 28 +- cmake/XrplVersion.cmake | 14 +- cmake/add_module.cmake | 22 +- cmake/create_symbolic_link.cmake | 26 +- cmake/deps/Boost.cmake | 79 +++--- cmake/isolate_headers.cmake | 4 +- cmake/target_link_modules.cmake | 13 +- cmake/target_protobuf_sources.cmake | 35 ++- src/tests/libxrpl/CMakeLists.txt | 9 +- 26 files changed, 1264 insertions(+), 827 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0d8519327..7ca0798ae4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,16 @@ cmake_minimum_required(VERSION 3.16) -if (POLICY CMP0074) +if(POLICY CMP0074) cmake_policy(SET CMP0074 NEW) -endif () -if (POLICY CMP0077) +endif() +if(POLICY CMP0077) cmake_policy(SET CMP0077 NEW) -endif () +endif() # Fix "unrecognized escape" issues when passing CMAKE_MODULE_PATH on Windows. -if (DEFINED CMAKE_MODULE_PATH) +if(DEFINED CMAKE_MODULE_PATH) file(TO_CMAKE_PATH "${CMAKE_MODULE_PATH}" CMAKE_MODULE_PATH) -endif () +endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") project(xrpl) @@ -21,57 +21,64 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) include(CompilationEnv) -if (is_gcc) +if(is_gcc) # GCC-specific fixes add_compile_options(-Wno-unknown-pragmas -Wno-subobject-linkage) # -Wno-subobject-linkage can be removed when we upgrade GCC version to at least 13.3 -elseif (is_clang) +elseif(is_clang) # Clang-specific fixes add_compile_options(-Wno-unknown-warning-option) # Ignore unknown warning options -elseif (is_msvc) +elseif(is_msvc) # MSVC-specific fixes add_compile_options(/wd4068) # Ignore unknown pragmas -endif () +endif() # Enable ccache to speed up builds. include(Ccache) -if (thread_safety_analysis) - add_compile_options(-Wthread-safety -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS - -DXRPL_ENABLE_THREAD_SAFETY_ANNOTATIONS) +if(thread_safety_analysis) + add_compile_options( + -Wthread-safety + -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS + -DXRPL_ENABLE_THREAD_SAFETY_ANNOTATIONS + ) add_compile_options("-stdlib=libc++") add_link_options("-stdlib=libc++") -endif () +endif() include(CheckCXXCompilerFlag) include(FetchContent) include(ExternalProject) include(CMakeFuncs) # must come *after* ExternalProject b/c it overrides one function in EP -if (target) - message(FATAL_ERROR "The target option has been removed - use native cmake options to control build" +if(target) + message( + FATAL_ERROR + "The target option has been removed - use native cmake options to control build" ) -endif () +endif() include(XrplSanity) include(XrplVersion) include(XrplSettings) # this check has to remain in the top-level cmake because of the early return statement -if (packages_only) - if (NOT TARGET rpm) - message(FATAL_ERROR "packages_only requested, but targets were not created - is docker installed?" +if(packages_only) + if(NOT TARGET rpm) + message( + FATAL_ERROR + "packages_only requested, but targets were not created - is docker installed?" ) - endif () + endif() return() -endif () +endif() include(XrplCompiler) include(XrplSanitizers) include(XrplInterface) option(only_docs "Include only the docs target?" FALSE) include(XrplDocs) -if (only_docs) +if(only_docs) return() -endif () +endif() include(deps/Boost) @@ -90,42 +97,46 @@ find_package(xxHash REQUIRED) target_link_libraries( xrpl_libs - INTERFACE ed25519::ed25519 - lz4::lz4 - OpenSSL::Crypto - OpenSSL::SSL - secp256k1::secp256k1 - soci::soci - SQLite::SQLite3) + INTERFACE + ed25519::ed25519 + lz4::lz4 + OpenSSL::Crypto + OpenSSL::SSL + secp256k1::secp256k1 + soci::soci + SQLite::SQLite3 +) option(rocksdb "Enable RocksDB" ON) -if (rocksdb) +if(rocksdb) find_package(RocksDB REQUIRED) - set_target_properties(RocksDB::rocksdb PROPERTIES INTERFACE_COMPILE_DEFINITIONS - XRPL_ROCKSDB_AVAILABLE=1) + set_target_properties( + RocksDB::rocksdb + PROPERTIES INTERFACE_COMPILE_DEFINITIONS XRPL_ROCKSDB_AVAILABLE=1 + ) target_link_libraries(xrpl_libs INTERFACE RocksDB::rocksdb) -endif () +endif() # Work around changes to Conan recipe for now. -if (TARGET nudb::core) +if(TARGET nudb::core) set(nudb nudb::core) -elseif (TARGET NuDB::nudb) +elseif(TARGET NuDB::nudb) set(nudb NuDB::nudb) -else () +else() message(FATAL_ERROR "unknown nudb target") -endif () +endif() target_link_libraries(xrpl_libs INTERFACE ${nudb}) -if (coverage) +if(coverage) include(XrplCov) -endif () +endif() set(PROJECT_EXPORT_SET XrplExports) include(XrplCore) include(XrplInstall) include(XrplValidatorKeys) -if (tests) +if(tests) include(CTest) add_subdirectory(src/tests/libxrpl) -endif () +endif() diff --git a/cmake/CMakeFuncs.cmake b/cmake/CMakeFuncs.cmake index ec2d9db330..391ed3364c 100644 --- a/cmake/CMakeFuncs.cmake +++ b/cmake/CMakeFuncs.cmake @@ -1,29 +1,32 @@ -macro (exclude_from_default target_) +macro(exclude_from_default target_) set_target_properties(${target_} PROPERTIES EXCLUDE_FROM_ALL ON) set_target_properties(${target_} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON) -endmacro () +endmacro() -macro (exclude_if_included target_) +macro(exclude_if_included target_) get_directory_property(has_parent PARENT_DIRECTORY) - if (has_parent) + if(has_parent) exclude_from_default(${target_}) - endif () -endmacro () + endif() +endmacro() find_package(Git) -function (git_branch branch_val) - if (NOT GIT_FOUND) +function(git_branch branch_val) + if(NOT GIT_FOUND) return() - endif () + endif() set(_branch "") - execute_process(COMMAND ${GIT_EXECUTABLE} "rev-parse" "--abbrev-ref" "HEAD" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE _git_exit_code - OUTPUT_VARIABLE _temp_branch - OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) - if (_git_exit_code EQUAL 0) + execute_process( + COMMAND ${GIT_EXECUTABLE} "rev-parse" "--abbrev-ref" "HEAD" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE _git_exit_code + OUTPUT_VARIABLE _temp_branch + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + if(_git_exit_code EQUAL 0) set(_branch ${_temp_branch}) - endif () + endif() set(${branch_val} "${_branch}" PARENT_SCOPE) -endfunction () +endfunction() diff --git a/cmake/Ccache.cmake b/cmake/Ccache.cmake index e34627ad8a..f8972dbb30 100644 --- a/cmake/Ccache.cmake +++ b/cmake/Ccache.cmake @@ -1,50 +1,62 @@ find_program(CCACHE_PATH "ccache") -if (NOT CCACHE_PATH) +if(NOT CCACHE_PATH) return() -endif () +endif() # For Linux and macOS we can use the ccache binary directly. -if (NOT MSVC) +if(NOT MSVC) set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PATH}") set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PATH}") message(STATUS "Found ccache: ${CCACHE_PATH}") return() -endif () +endif() # For Windows more effort is required. The code below is a modified version of # https://github.com/ccache/ccache/wiki/MS-Visual-Studio#usage-with-cmake. -if ("${CCACHE_PATH}" MATCHES "chocolatey") +if("${CCACHE_PATH}" MATCHES "chocolatey") message(DEBUG "Ccache path: ${CCACHE_PATH}") # Chocolatey uses a shim executable that we cannot use directly, in which case we have to find the executable it # points to. If we cannot find the target executable then we cannot use ccache. find_program(BASH_PATH "bash") - if (NOT BASH_PATH) + if(NOT BASH_PATH) message(WARNING "Could not find bash.") return() - endif () + endif() - execute_process(COMMAND bash -c - "export LC_ALL='en_US.UTF-8'; ${CCACHE_PATH} --shimgen-noop | grep -oP 'path to executable: \\K.+' | head -c -1" - OUTPUT_VARIABLE CCACHE_PATH) + execute_process( + COMMAND + bash -c + "export LC_ALL='en_US.UTF-8'; ${CCACHE_PATH} --shimgen-noop | grep -oP 'path to executable: \\K.+' | head -c -1" + OUTPUT_VARIABLE CCACHE_PATH + ) - if (NOT CCACHE_PATH) + if(NOT CCACHE_PATH) message(WARNING "Could not find ccache target.") return() - endif () + endif() file(TO_CMAKE_PATH "${CCACHE_PATH}" CCACHE_PATH) -endif () +endif() message(STATUS "Found ccache: ${CCACHE_PATH}") # Tell cmake to use ccache for compiling with Visual Studio. file(COPY_FILE ${CCACHE_PATH} ${CMAKE_BINARY_DIR}/cl.exe ONLY_IF_DIFFERENT) -set(CMAKE_VS_GLOBALS "CLToolExe=cl.exe" "CLToolPath=${CMAKE_BINARY_DIR}" "TrackFileAccess=false" - "UseMultiToolTask=true") +set(CMAKE_VS_GLOBALS + "CLToolExe=cl.exe" + "CLToolPath=${CMAKE_BINARY_DIR}" + "TrackFileAccess=false" + "UseMultiToolTask=true" +) # By default Visual Studio generators will use /Zi to capture debug information, which is not compatible with ccache, so # tell it to use /Z7 instead. -if (MSVC) - foreach (var_ CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE) +if(MSVC) + foreach( + var_ + CMAKE_C_FLAGS_DEBUG + CMAKE_C_FLAGS_RELEASE + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_RELEASE + ) string(REPLACE "/Zi" "/Z7" ${var_} "${${var_}}") - endforeach () -endif () + endforeach() +endif() diff --git a/cmake/CodeCoverage.cmake b/cmake/CodeCoverage.cmake index 74796718c1..5681f76640 100644 --- a/cmake/CodeCoverage.cmake +++ b/cmake/CodeCoverage.cmake @@ -174,37 +174,45 @@ 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 "") @@ -213,7 +221,7 @@ set(COVERAGE_C_COMPILER_FLAGS "") set(COVERAGE_CXX_LINKER_FLAGS "") set(COVERAGE_C_LINKER_FLAGS "") -if (CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") +if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") include(CheckCXXCompilerFlag) include(CheckCCompilerFlag) include(CheckLinkerFlag) @@ -224,51 +232,77 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") set(COVERAGE_C_LINKER_FLAGS ${COVERAGE_COMPILER_FLAGS}) check_cxx_compiler_flag(-fprofile-abs-path HAVE_cxx_fprofile_abs_path) - if (HAVE_cxx_fprofile_abs_path) - set(COVERAGE_CXX_COMPILER_FLAGS "${COVERAGE_CXX_COMPILER_FLAGS} -fprofile-abs-path") - endif () + if(HAVE_cxx_fprofile_abs_path) + set(COVERAGE_CXX_COMPILER_FLAGS + "${COVERAGE_CXX_COMPILER_FLAGS} -fprofile-abs-path" + ) + endif() check_c_compiler_flag(-fprofile-abs-path HAVE_c_fprofile_abs_path) - if (HAVE_c_fprofile_abs_path) - set(COVERAGE_C_COMPILER_FLAGS "${COVERAGE_C_COMPILER_FLAGS} -fprofile-abs-path") - endif () + if(HAVE_c_fprofile_abs_path) + set(COVERAGE_C_COMPILER_FLAGS + "${COVERAGE_C_COMPILER_FLAGS} -fprofile-abs-path" + ) + endif() check_linker_flag(CXX -fprofile-abs-path HAVE_cxx_linker_fprofile_abs_path) - if (HAVE_cxx_linker_fprofile_abs_path) - set(COVERAGE_CXX_LINKER_FLAGS "${COVERAGE_CXX_LINKER_FLAGS} -fprofile-abs-path") - endif () + if(HAVE_cxx_linker_fprofile_abs_path) + set(COVERAGE_CXX_LINKER_FLAGS + "${COVERAGE_CXX_LINKER_FLAGS} -fprofile-abs-path" + ) + endif() check_linker_flag(C -fprofile-abs-path HAVE_c_linker_fprofile_abs_path) - if (HAVE_c_linker_fprofile_abs_path) - set(COVERAGE_C_LINKER_FLAGS "${COVERAGE_C_LINKER_FLAGS} -fprofile-abs-path") - endif () + if(HAVE_c_linker_fprofile_abs_path) + set(COVERAGE_C_LINKER_FLAGS + "${COVERAGE_C_LINKER_FLAGS} -fprofile-abs-path" + ) + endif() check_cxx_compiler_flag(-fprofile-update=atomic HAVE_cxx_fprofile_update) - if (HAVE_cxx_fprofile_update) - set(COVERAGE_CXX_COMPILER_FLAGS "${COVERAGE_CXX_COMPILER_FLAGS} -fprofile-update=atomic") - endif () + if(HAVE_cxx_fprofile_update) + set(COVERAGE_CXX_COMPILER_FLAGS + "${COVERAGE_CXX_COMPILER_FLAGS} -fprofile-update=atomic" + ) + endif() check_c_compiler_flag(-fprofile-update=atomic HAVE_c_fprofile_update) - if (HAVE_c_fprofile_update) - set(COVERAGE_C_COMPILER_FLAGS "${COVERAGE_C_COMPILER_FLAGS} -fprofile-update=atomic") - endif () + if(HAVE_c_fprofile_update) + set(COVERAGE_C_COMPILER_FLAGS + "${COVERAGE_C_COMPILER_FLAGS} -fprofile-update=atomic" + ) + endif() - check_linker_flag(CXX -fprofile-update=atomic HAVE_cxx_linker_fprofile_update) - if (HAVE_cxx_linker_fprofile_update) - set(COVERAGE_CXX_LINKER_FLAGS "${COVERAGE_CXX_LINKER_FLAGS} -fprofile-update=atomic") - endif () + check_linker_flag( + CXX + -fprofile-update=atomic + HAVE_cxx_linker_fprofile_update + ) + if(HAVE_cxx_linker_fprofile_update) + set(COVERAGE_CXX_LINKER_FLAGS + "${COVERAGE_CXX_LINKER_FLAGS} -fprofile-update=atomic" + ) + endif() check_linker_flag(C -fprofile-update=atomic HAVE_c_linker_fprofile_update) - if (HAVE_c_linker_fprofile_update) - set(COVERAGE_C_LINKER_FLAGS "${COVERAGE_C_LINKER_FLAGS} -fprofile-update=atomic") - endif () + if(HAVE_c_linker_fprofile_update) + set(COVERAGE_C_LINKER_FLAGS + "${COVERAGE_C_LINKER_FLAGS} -fprofile-update=atomic" + ) + endif() +endif() -endif () - -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) # Defines a target for running and collection code coverage information # Builds dependencies, runs the given executable and outputs reports. @@ -292,125 +326,167 @@ endif () # NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG) # ) # 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 (NOT DEFINED Coverage_EXECUTABLE AND DEFINED Coverage_EXECUTABLE_ARGS) - message(FATAL_ERROR "EXECUTABLE_ARGS must not be set if EXECUTABLE is not set") - endif () - - if ("--output" IN_LIST GCOVR_ADDITIONAL_ARGS) - message(FATAL_ERROR "Unsupported --output option detected in GCOVR_ADDITIONAL_ARGS! Aborting..." + if(NOT DEFINED Coverage_EXECUTABLE AND DEFINED Coverage_EXECUTABLE_ARGS) + message( + FATAL_ERROR + "EXECUTABLE_ARGS must not be set if EXECUTABLE is not set" ) - 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") - set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.html) - 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") - set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.txt) - elseif (Coverage_FORMAT STREQUAL "csv") - set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.csv) - elseif (Coverage_FORMAT STREQUAL "lcov") - set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.lcov) - else () - set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.xml) - endif () - endif () + endif() - if ((Coverage_FORMAT STREQUAL "cobertura") OR (Coverage_FORMAT STREQUAL "xml")) + 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") + set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.html) + 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") + set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.txt) + elseif(Coverage_FORMAT STREQUAL "csv") + set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.csv) + elseif(Coverage_FORMAT STREQUAL "lcov") + set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.lcov) + else() + set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.xml) + endif() + endif() + + 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 "jacoco") + elseif(Coverage_FORMAT STREQUAL "jacoco") list(APPEND GCOVR_ADDITIONAL_ARGS --jacoco "${GCOVR_OUTPUT_FILE}") list(APPEND GCOVR_ADDITIONAL_ARGS --jacoco-pretty) - elseif (Coverage_FORMAT STREQUAL "clover") + elseif(Coverage_FORMAT STREQUAL "clover") list(APPEND GCOVR_ADDITIONAL_ARGS --clover "${GCOVR_OUTPUT_FILE}") list(APPEND GCOVR_ADDITIONAL_ARGS --clover-pretty) - elseif (Coverage_FORMAT STREQUAL "lcov") + elseif(Coverage_FORMAT STREQUAL "lcov") list(APPEND GCOVR_ADDITIONAL_ARGS --lcov "${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 # If EXECUTABLE is not set, the user is expected to run the tests manually # before running the coverage target NAME - if (DEFINED Coverage_EXECUTABLE) - set(GCOVR_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}) - endif () + if(DEFINED Coverage_EXECUTABLE) + set(GCOVR_EXEC_TESTS_CMD + ${Coverage_EXECUTABLE} + ${Coverage_EXECUTABLE_ARGS} + ) + endif() # Create folder - if (DEFINED GCOVR_CREATE_FOLDER) - set(GCOVR_FOLDER_CMD ${CMAKE_COMMAND} -E make_directory ${GCOVR_CREATE_FOLDER}) - endif () + if(DEFINED GCOVR_CREATE_FOLDER) + set(GCOVR_FOLDER_CMD + ${CMAKE_COMMAND} + -E + make_directory + ${GCOVR_CREATE_FOLDER} + ) + endif() # Running gcovr set(GCOVR_CMD @@ -422,56 +498,95 @@ 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") - if (NOT "${GCOVR_EXEC_TESTS_CMD}" STREQUAL "") + if(NOT "${GCOVR_EXEC_TESTS_CMD}" STREQUAL "") 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}") - endif () + endif() - if (NOT "${GCOVR_FOLDER_CMD}" STREQUAL "") + if(NOT "${GCOVR_FOLDER_CMD}" STREQUAL "") 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 echo - COMMENT "Code coverage report saved in ${GCOVR_OUTPUT_FILE} formatted as ${Coverage_FORMAT}" + TARGET ${Coverage_NAME} + POST_BUILD + COMMAND echo + COMMENT + "Code coverage report saved in ${GCOVR_OUTPUT_FILE} formatted as ${Coverage_FORMAT}" ) -endfunction () # setup_target_for_coverage_gcovr +endfunction() # setup_target_for_coverage_gcovr -function (add_code_coverage_to_target name scope) - separate_arguments(COVERAGE_CXX_COMPILER_FLAGS NATIVE_COMMAND "${COVERAGE_CXX_COMPILER_FLAGS}") - separate_arguments(COVERAGE_C_COMPILER_FLAGS NATIVE_COMMAND "${COVERAGE_C_COMPILER_FLAGS}") - separate_arguments(COVERAGE_CXX_LINKER_FLAGS NATIVE_COMMAND "${COVERAGE_CXX_LINKER_FLAGS}") - separate_arguments(COVERAGE_C_LINKER_FLAGS NATIVE_COMMAND "${COVERAGE_C_LINKER_FLAGS}") +function(add_code_coverage_to_target name scope) + separate_arguments( + COVERAGE_CXX_COMPILER_FLAGS + NATIVE_COMMAND + "${COVERAGE_CXX_COMPILER_FLAGS}" + ) + separate_arguments( + COVERAGE_C_COMPILER_FLAGS + NATIVE_COMMAND + "${COVERAGE_C_COMPILER_FLAGS}" + ) + separate_arguments( + COVERAGE_CXX_LINKER_FLAGS + NATIVE_COMMAND + "${COVERAGE_CXX_LINKER_FLAGS}" + ) + separate_arguments( + COVERAGE_C_LINKER_FLAGS + NATIVE_COMMAND + "${COVERAGE_C_LINKER_FLAGS}" + ) # Add compiler options to the target target_compile_options( - ${name} ${scope} $<$:${COVERAGE_CXX_COMPILER_FLAGS}> - $<$:${COVERAGE_C_COMPILER_FLAGS}>) + ${name} + ${scope} + $<$:${COVERAGE_CXX_COMPILER_FLAGS}> + $<$:${COVERAGE_C_COMPILER_FLAGS}> + ) - target_link_libraries(${name} ${scope} $<$:${COVERAGE_CXX_LINKER_FLAGS}> - $<$:${COVERAGE_C_LINKER_FLAGS}>) -endfunction () # add_code_coverage_to_target + target_link_libraries( + ${name} + ${scope} + $<$:${COVERAGE_CXX_LINKER_FLAGS}> + $<$:${COVERAGE_C_LINKER_FLAGS}> + ) +endfunction() # add_code_coverage_to_target diff --git a/cmake/CompilationEnv.cmake b/cmake/CompilationEnv.cmake index 59b903c13a..0d44f90974 100644 --- a/cmake/CompilationEnv.cmake +++ b/cmake/CompilationEnv.cmake @@ -14,20 +14,20 @@ set(is_gcc FALSE) set(is_msvc FALSE) set(is_xcode FALSE) -if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") # Clang or AppleClang +if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") # Clang or AppleClang set(is_clang TRUE) -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(is_gcc TRUE) -elseif (MSVC) +elseif(MSVC) set(is_msvc TRUE) -else () +else() message(FATAL_ERROR "Unsupported C++ compiler: ${CMAKE_CXX_COMPILER_ID}") -endif () +endif() # Xcode generator detection -if (CMAKE_GENERATOR STREQUAL "Xcode") +if(CMAKE_GENERATOR STREQUAL "Xcode") set(is_xcode TRUE) -endif () +endif() # -------------------------------------------------------------------- # Operating system detection @@ -36,23 +36,23 @@ set(is_linux FALSE) set(is_windows FALSE) set(is_macos FALSE) -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(is_linux TRUE) -elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(is_windows TRUE) -elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(is_macos TRUE) -endif () +endif() # -------------------------------------------------------------------- # Architecture # -------------------------------------------------------------------- set(is_amd64 FALSE) set(is_arm64 FALSE) -if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") +if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") set(is_amd64 TRUE) -elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") set(is_arm64 TRUE) -else () +else() message(FATAL_ERROR "Unknown architecture: ${CMAKE_SYSTEM_PROCESSOR}") -endif () +endif() diff --git a/cmake/GitInfo.cmake b/cmake/GitInfo.cmake index 1281182977..788efe624a 100644 --- a/cmake/GitInfo.cmake +++ b/cmake/GitInfo.cmake @@ -4,18 +4,25 @@ set(GIT_BUILD_BRANCH "") set(GIT_COMMIT_HASH "") find_package(Git) -if (NOT Git_FOUND) +if(NOT Git_FOUND) message(WARNING "Git not found. Git branch and commit hash will be empty.") return() -endif () +endif() set(GIT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.git) -execute_process(COMMAND ${GIT_EXECUTABLE} --git-dir=${GIT_DIRECTORY} rev-parse --abbrev-ref HEAD - OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE GIT_BUILD_BRANCH) +execute_process( + COMMAND + ${GIT_EXECUTABLE} --git-dir=${GIT_DIRECTORY} rev-parse --abbrev-ref HEAD + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE GIT_BUILD_BRANCH +) -execute_process(COMMAND ${GIT_EXECUTABLE} --git-dir=${GIT_DIRECTORY} rev-parse HEAD - OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE GIT_COMMIT_HASH) +execute_process( + COMMAND ${GIT_EXECUTABLE} --git-dir=${GIT_DIRECTORY} rev-parse HEAD + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE GIT_COMMIT_HASH +) message(STATUS "Git branch: ${GIT_BUILD_BRANCH}") message(STATUS "Git commit hash: ${GIT_COMMIT_HASH}") diff --git a/cmake/XrplAddTest.cmake b/cmake/XrplAddTest.cmake index 35189e203f..0f8f9e2c01 100644 --- a/cmake/XrplAddTest.cmake +++ b/cmake/XrplAddTest.cmake @@ -1,13 +1,17 @@ include(isolate_headers) -function (xrpl_add_test name) +function(xrpl_add_test name) set(target ${PROJECT_NAME}.test.${name}) - file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp") + file( + GLOB_RECURSE sources + CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp" + ) add_executable(${target} ${ARGN} ${sources}) isolate_headers(${target} "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/tests/${name}" PRIVATE) add_test(NAME ${target} COMMAND ${target}) -endfunction () +endfunction() diff --git a/cmake/XrplCompiler.cmake b/cmake/XrplCompiler.cmake index 8093004b2e..0b77ff3525 100644 --- a/cmake/XrplCompiler.cmake +++ b/cmake/XrplCompiler.cmake @@ -14,33 +14,42 @@ include(XrplSanitizers) # add a single global dependency on this interface lib link_libraries(Xrpl::common) # Respect CMAKE_POSITION_INDEPENDENT_CODE setting (may be set by Conan toolchain) -if (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE) +if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -endif () -set_target_properties(common PROPERTIES INTERFACE_POSITION_INDEPENDENT_CODE - ${CMAKE_POSITION_INDEPENDENT_CODE}) +endif() +set_target_properties( + common + PROPERTIES + INTERFACE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE} +) set(CMAKE_CXX_EXTENSIONS OFF) target_compile_definitions( common - INTERFACE $<$:DEBUG - _DEBUG> - #[===[ + INTERFACE + $<$:DEBUG + _DEBUG> + #[===[ NOTE: CMAKE release builds already have NDEBUG defined, so no need to add it explicitly except for the special case of (profile ON) and (assert OFF). Presumably this is because we don't want profile builds asserting unless asserts were specifically requested. ]===] - $<$,$>>:NDEBUG> - # TODO: Remove once we have migrated functions from OpenSSL 1.x to 3.x. - OPENSSL_SUPPRESS_DEPRECATED) + $<$,$>>:NDEBUG> + # TODO: Remove once we have migrated functions from OpenSSL 1.x to 3.x. + OPENSSL_SUPPRESS_DEPRECATED +) -if (MSVC) +if(MSVC) # remove existing exception flag since we set it to -EHa string(REGEX REPLACE "[-/]EH[a-z]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - foreach (var_ CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE) - + foreach( + var_ + CMAKE_C_FLAGS_DEBUG + CMAKE_C_FLAGS_RELEASE + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_RELEASE + ) # also remove dynamic runtime string(REGEX REPLACE "[-/]MD[d]*" " " ${var_} "${${var_}}") @@ -48,120 +57,143 @@ if (MSVC) string(REPLACE "/ZI" "/Zi" ${var_} "${${var_}}") # omit debug info completely under CI (not needed) - if (is_ci) + if(is_ci) string(REPLACE "/Zi" " " ${var_} "${${var_}}") string(REPLACE "/Z7" " " ${var_} "${${var_}}") - endif () - endforeach () + endif() + endforeach() target_compile_options( common INTERFACE # Increase object file max size - -bigobj - # Floating point behavior - -fp:precise - # __cdecl calling convention - -Gd - # Minimal rebuild: disabled - -Gm- - # Function level linking: disabled - -Gy- - # Multiprocessor compilation - -MP - # pragma omp: disabled - -openmp- - # No error reporting to Internet - -errorReport:none - # Suppress login banner - -nologo - # Disable signed/unsigned comparison warnings - -wd4018 - # Disable float to int possible loss of data warnings - -wd4244 - # Disable size_t to T possible loss of data warnings - -wd4267 - # Disable C4800(int to bool performance) - -wd4800 - # Decorated name length exceeded, name was truncated - -wd4503 - $<$: - -EHa - -GR - > - $<$:-Ox> - $<$,$>: - -GS - -Zc:forScope - > - # static runtime - $<$:-MTd> - $<$>:-MT> - $<$:-WX>) + -bigobj + # Floating point behavior + -fp:precise + # __cdecl calling convention + -Gd + # Minimal rebuild: disabled + -Gm- + # Function level linking: disabled + -Gy- + # Multiprocessor compilation + -MP + # pragma omp: disabled + -openmp- + # No error reporting to Internet + -errorReport:none + # Suppress login banner + -nologo + # Disable signed/unsigned comparison warnings + -wd4018 + # Disable float to int possible loss of data warnings + -wd4244 + # Disable size_t to T possible loss of data warnings + -wd4267 + # Disable C4800(int to bool performance) + -wd4800 + # Decorated name length exceeded, name was truncated + -wd4503 + $<$: + -EHa + -GR + > + $<$:-Ox> + $<$,$>: + -GS + -Zc:forScope + > + # static runtime + $<$:-MTd> + $<$>:-MT> + $<$:-WX> + ) target_compile_definitions( common - INTERFACE _WIN32_WINNT=0x6000 - _SCL_SECURE_NO_WARNINGS - _CRT_SECURE_NO_WARNINGS - WIN32_CONSOLE - WIN32_LEAN_AND_MEAN - NOMINMAX - # TODO: Resolve these warnings, don't just silence them - _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS - $<$,$>:_CRTDBG_MAP_ALLOC>) + INTERFACE + _WIN32_WINNT=0x6000 + _SCL_SECURE_NO_WARNINGS + _CRT_SECURE_NO_WARNINGS + WIN32_CONSOLE + WIN32_LEAN_AND_MEAN + NOMINMAX + # TODO: Resolve these warnings, don't just silence them + _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS + $<$,$>:_CRTDBG_MAP_ALLOC> + ) target_link_libraries(common INTERFACE -errorreport:none -machine:X64) -else () +else() target_compile_options( common - INTERFACE -Wall - -Wdeprecated - $<$:-Wno-deprecated-declarations> - $<$:-Wextra - -Wno-unused-parameter> - $<$:-Werror> - -fstack-protector - -Wno-sign-compare - -Wno-unused-but-set-variable - $<$>:-fno-strict-aliasing> - # tweak gcc optimization for debug - $<$,$>:-O0> - # Add debug symbols to release config - $<$:-g>) + INTERFACE + -Wall + -Wdeprecated + $<$:-Wno-deprecated-declarations> + $<$:-Wextra + -Wno-unused-parameter> + $<$:-Werror> + -fstack-protector + -Wno-sign-compare + -Wno-unused-but-set-variable + $<$>:-fno-strict-aliasing> + # tweak gcc optimization for debug + $<$,$>:-O0> + # Add debug symbols to release config + $<$:-g> + ) target_link_libraries( common - INTERFACE -rdynamic - $<$:-Wl,-z,relro,-z,now,--build-id> - # link to static libc/c++ iff: * static option set and * NOT APPLE (AppleClang does not support static - # libc/c++) and * NOT SANITIZERS (sanitizers typically don't work with static libc/c++) - $<$,$>,$>>: - -static-libstdc++ - -static-libgcc - >) -endif () + INTERFACE + -rdynamic + $<$:-Wl,-z,relro,-z,now,--build-id> + # link to static libc/c++ iff: * static option set and * NOT APPLE (AppleClang does not support static + # libc/c++) and * NOT SANITIZERS (sanitizers typically don't work with static libc/c++) + $<$,$>,$>>: + -static-libstdc++ + -static-libgcc + > + ) +endif() # Antithesis instrumentation will only be built and deployed using machines running Linux. -if (voidstar) - if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") - message(FATAL_ERROR "Antithesis instrumentation requires Debug build type, aborting...") - elseif (NOT is_linux) - message(FATAL_ERROR "Antithesis instrumentation requires Linux, aborting...") - elseif (NOT (is_clang AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0)) - message(FATAL_ERROR "Antithesis instrumentation requires Clang version 16 or later, aborting..." +if(voidstar) + if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + message( + FATAL_ERROR + "Antithesis instrumentation requires Debug build type, aborting..." ) - endif () -endif () + elseif(NOT is_linux) + message( + FATAL_ERROR + "Antithesis instrumentation requires Linux, aborting..." + ) + elseif( + NOT (is_clang AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0) + ) + message( + FATAL_ERROR + "Antithesis instrumentation requires Clang version 16 or later, aborting..." + ) + endif() +endif() -if (use_mold) +if(use_mold) # use mold linker if available - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=mold -Wl,--version ERROR_QUIET - OUTPUT_VARIABLE LD_VERSION) - if ("${LD_VERSION}" MATCHES "mold") + execute_process( + COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=mold -Wl,--version + ERROR_QUIET + OUTPUT_VARIABLE LD_VERSION + ) + if("${LD_VERSION}" MATCHES "mold") target_link_libraries(common INTERFACE -fuse-ld=mold) - endif () + endif() unset(LD_VERSION) -elseif (use_gold AND is_gcc) +elseif(use_gold AND is_gcc) # use gold linker if available - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET - OUTPUT_VARIABLE LD_VERSION) + execute_process( + COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=gold -Wl,--version + ERROR_QUIET + OUTPUT_VARIABLE LD_VERSION + ) #[=========================================================[ NOTE: THE gold linker inserts -rpath as DT_RUNPATH by default instead of DT_RPATH, so you might have slightly @@ -175,32 +207,37 @@ elseif (use_gold AND is_gcc) disabling would be to figure out all the settings required to make gold play nicely with jemalloc. #]=========================================================] - if (("${LD_VERSION}" MATCHES "GNU gold") AND (NOT jemalloc)) + if(("${LD_VERSION}" MATCHES "GNU gold") AND (NOT jemalloc)) target_link_libraries( common - INTERFACE -fuse-ld=gold - -Wl,--no-as-needed - #[=========================================================[ + INTERFACE + -fuse-ld=gold + -Wl,--no-as-needed + #[=========================================================[ see https://bugs.launchpad.net/ubuntu/+source/eglibc/+bug/1253638/comments/5 DT_RUNPATH does not work great for transitive dependencies (of which boost has a few) - so just switch to DT_RPATH if doing dynamic linking with gold #]=========================================================] - $<$>:-Wl,--disable-new-dtags>) - endif () + $<$>:-Wl,--disable-new-dtags> + ) + endif() unset(LD_VERSION) -elseif (use_lld) +elseif(use_lld) # use lld linker if available - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=lld -Wl,--version ERROR_QUIET - OUTPUT_VARIABLE LD_VERSION) - if ("${LD_VERSION}" MATCHES "LLD") + execute_process( + COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=lld -Wl,--version + ERROR_QUIET + OUTPUT_VARIABLE LD_VERSION + ) + if("${LD_VERSION}" MATCHES "LLD") target_link_libraries(common INTERFACE -fuse-ld=lld) - endif () + endif() unset(LD_VERSION) -endif () +endif() -if (assert) - foreach (var_ CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE) +if(assert) + foreach(var_ CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE) string(REGEX REPLACE "[-/]DNDEBUG" "" ${var_} "${${var_}}") - endforeach () -endif () + endforeach() +endif() diff --git a/cmake/XrplConfig.cmake b/cmake/XrplConfig.cmake index bf6aa475ba..76f9af14b1 100644 --- a/cmake/XrplConfig.cmake +++ b/cmake/XrplConfig.cmake @@ -3,50 +3,58 @@ include(CMakeFindDependencyMacro) #[=========================================================[ Boost #]=========================================================] -if (static OR APPLE OR MSVC) +if(static OR APPLE OR MSVC) set(Boost_USE_STATIC_LIBS ON) -endif () +endif() set(Boost_USE_MULTITHREADED ON) -if (static OR MSVC) +if(static OR MSVC) set(Boost_USE_STATIC_RUNTIME ON) -else () +else() set(Boost_USE_STATIC_RUNTIME OFF) -endif () -find_dependency(Boost - COMPONENTS - chrono - container - context - coroutine - date_time - filesystem - program_options - regex - system - thread) +endif() +find_dependency( + Boost + COMPONENTS + chrono + container + context + coroutine + date_time + filesystem + program_options + regex + system + thread +) #[=========================================================[ OpenSSL #]=========================================================] -if (NOT DEFINED OPENSSL_ROOT_DIR) - if (DEFINED ENV{OPENSSL_ROOT}) +if(NOT DEFINED OPENSSL_ROOT_DIR) + if(DEFINED ENV{OPENSSL_ROOT}) set(OPENSSL_ROOT_DIR $ENV{OPENSSL_ROOT}) - elseif (APPLE) + elseif(APPLE) find_program(homebrew brew) - if (homebrew) - execute_process(COMMAND ${homebrew} --prefix openssl OUTPUT_VARIABLE OPENSSL_ROOT_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) - endif () - endif () + if(homebrew) + execute_process( + COMMAND ${homebrew} --prefix openssl + OUTPUT_VARIABLE OPENSSL_ROOT_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + endif() + endif() file(TO_CMAKE_PATH "${OPENSSL_ROOT_DIR}" OPENSSL_ROOT_DIR) -endif () +endif() -if (static OR APPLE OR MSVC) +if(static OR APPLE OR MSVC) set(OPENSSL_USE_STATIC_LIBS ON) -endif () +endif() set(OPENSSL_MSVC_STATIC_RT ON) find_dependency(OpenSSL REQUIRED) find_dependency(ZLIB) find_dependency(date) -if (TARGET ZLIB::ZLIB) - set_target_properties(OpenSSL::Crypto PROPERTIES INTERFACE_LINK_LIBRARIES ZLIB::ZLIB) -endif () +if(TARGET ZLIB::ZLIB) + set_target_properties( + OpenSSL::Crypto + PROPERTIES INTERFACE_LINK_LIBRARIES ZLIB::ZLIB + ) +endif() diff --git a/cmake/XrplCore.cmake b/cmake/XrplCore.cmake index cd44f29df9..1c8f5e33d6 100644 --- a/cmake/XrplCore.cmake +++ b/cmake/XrplCore.cmake @@ -11,24 +11,34 @@ include(target_protobuf_sources) add_library(xrpl.libpb) set_target_properties(xrpl.libpb PROPERTIES UNITY_BUILD OFF) target_protobuf_sources(xrpl.libpb xrpl/proto LANGUAGE cpp IMPORT_DIRS include/xrpl/proto - PROTOS include/xrpl/proto/xrpl.proto) + PROTOS include/xrpl/proto/xrpl.proto +) file(GLOB_RECURSE protos "include/xrpl/proto/org/*.proto") target_protobuf_sources(xrpl.libpb xrpl/proto LANGUAGE cpp IMPORT_DIRS include/xrpl/proto - PROTOS "${protos}") + PROTOS "${protos}" +) target_protobuf_sources( xrpl.libpb xrpl/proto LANGUAGE grpc IMPORT_DIRS include/xrpl/proto PROTOS "${protos}" PLUGIN protoc-gen-grpc=$ - GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc) + GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc +) target_compile_options( xrpl.libpb - PUBLIC $<$:-wd4996> $<$: - --system-header-prefix="google/protobuf" -Wno-deprecated-dynamic-exception-spec > - PRIVATE $<$:-wd4065> $<$>:-Wno-deprecated-declarations>) + PUBLIC + $<$:-wd4996> + $<$: + --system-header-prefix="google/protobuf" + -Wno-deprecated-dynamic-exception-spec + > + PRIVATE + $<$:-wd4065> + $<$>:-Wno-deprecated-declarations> +) target_link_libraries(xrpl.libpb PUBLIC protobuf::libprotobuf gRPC::grpc++) @@ -37,19 +47,21 @@ add_library(xrpl.imports.main INTERFACE) target_link_libraries( xrpl.imports.main - INTERFACE absl::random_random - date::date - ed25519::ed25519 - LibArchive::LibArchive - OpenSSL::Crypto - Xrpl::boost - Xrpl::libs - Xrpl::opts - Xrpl::syslibs - secp256k1::secp256k1 - xrpl.libpb - xxHash::xxhash - $<$:antithesis-sdk-cpp>) + INTERFACE + absl::random_random + date::date + ed25519::ed25519 + LibArchive::LibArchive + OpenSSL::Crypto + Xrpl::boost + Xrpl::libs + Xrpl::opts + Xrpl::syslibs + secp256k1::secp256k1 + xrpl.libpb + xxHash::xxhash + $<$:antithesis-sdk-cpp> +) include(add_module) include(target_link_modules) @@ -60,8 +72,12 @@ target_link_libraries(xrpl.libxrpl.beast PUBLIC xrpl.imports.main) include(GitInfo) add_module(xrpl git) -target_compile_definitions(xrpl.libxrpl.git PRIVATE GIT_COMMIT_HASH="${GIT_COMMIT_HASH}" - GIT_BUILD_BRANCH="${GIT_BUILD_BRANCH}") +target_compile_definitions( + xrpl.libxrpl.git + PRIVATE + GIT_COMMIT_HASH="${GIT_COMMIT_HASH}" + GIT_BUILD_BRANCH="${GIT_BUILD_BRANCH}" +) target_link_libraries(xrpl.libxrpl.git PUBLIC xrpl.imports.main) # Level 02 @@ -77,13 +93,17 @@ target_link_libraries(xrpl.libxrpl.crypto PUBLIC xrpl.libxrpl.basics) # Level 04 add_module(xrpl protocol) -target_link_libraries(xrpl.libxrpl.protocol PUBLIC xrpl.libxrpl.crypto xrpl.libxrpl.git - xrpl.libxrpl.json) +target_link_libraries( + xrpl.libxrpl.protocol + PUBLIC xrpl.libxrpl.crypto xrpl.libxrpl.git xrpl.libxrpl.json +) # Level 05 add_module(xrpl core) -target_link_libraries(xrpl.libxrpl.core PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.json - xrpl.libxrpl.protocol) +target_link_libraries( + xrpl.libxrpl.core + PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.json xrpl.libxrpl.protocol +) # Level 06 add_module(xrpl resource) @@ -91,23 +111,46 @@ target_link_libraries(xrpl.libxrpl.resource PUBLIC xrpl.libxrpl.protocol) # Level 07 add_module(xrpl net) -target_link_libraries(xrpl.libxrpl.net PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.json - xrpl.libxrpl.protocol xrpl.libxrpl.resource) +target_link_libraries( + xrpl.libxrpl.net + PUBLIC + xrpl.libxrpl.basics + xrpl.libxrpl.json + xrpl.libxrpl.protocol + xrpl.libxrpl.resource +) add_module(xrpl nodestore) -target_link_libraries(xrpl.libxrpl.nodestore PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.json - xrpl.libxrpl.protocol) +target_link_libraries( + xrpl.libxrpl.nodestore + PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.json xrpl.libxrpl.protocol +) add_module(xrpl shamap) -target_link_libraries(xrpl.libxrpl.shamap PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.crypto - xrpl.libxrpl.protocol xrpl.libxrpl.nodestore) +target_link_libraries( + xrpl.libxrpl.shamap + PUBLIC + xrpl.libxrpl.basics + xrpl.libxrpl.crypto + xrpl.libxrpl.protocol + xrpl.libxrpl.nodestore +) add_module(xrpl rdb) -target_link_libraries(xrpl.libxrpl.rdb PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.core) +target_link_libraries( + xrpl.libxrpl.rdb + PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.core +) add_module(xrpl server) -target_link_libraries(xrpl.libxrpl.server PUBLIC xrpl.libxrpl.protocol xrpl.libxrpl.core - xrpl.libxrpl.rdb xrpl.libxrpl.resource) +target_link_libraries( + xrpl.libxrpl.server + PUBLIC + xrpl.libxrpl.protocol + xrpl.libxrpl.core + xrpl.libxrpl.rdb + xrpl.libxrpl.resource +) add_module(xrpl conditions) target_link_libraries(xrpl.libxrpl.conditions PUBLIC xrpl.libxrpl.server) @@ -115,13 +158,15 @@ target_link_libraries(xrpl.libxrpl.conditions PUBLIC xrpl.libxrpl.server) add_module(xrpl ledger) target_link_libraries( xrpl.libxrpl.ledger - PUBLIC xrpl.libxrpl.basics - xrpl.libxrpl.json - xrpl.libxrpl.protocol - xrpl.libxrpl.rdb - xrpl.libxrpl.server - xrpl.libxrpl.shamap - xrpl.libxrpl.conditions) + PUBLIC + xrpl.libxrpl.basics + xrpl.libxrpl.json + xrpl.libxrpl.protocol + xrpl.libxrpl.rdb + xrpl.libxrpl.server + xrpl.libxrpl.shamap + xrpl.libxrpl.conditions +) add_module(xrpl tx) target_link_libraries(xrpl.libxrpl.tx PUBLIC xrpl.libxrpl.ledger) @@ -131,7 +176,11 @@ set_target_properties(xrpl.libxrpl PROPERTIES OUTPUT_NAME xrpl) add_library(xrpl::libxrpl ALIAS xrpl.libxrpl) -file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/libxrpl/*.cpp") +file( + GLOB_RECURSE sources + CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/src/libxrpl/*.cpp" +) target_sources(xrpl.libxrpl PRIVATE ${sources}) target_link_modules( @@ -152,7 +201,8 @@ target_link_modules( resource server shamap - tx) + tx +) # All headers in libxrpl are in modules. # Uncomment this stanza if you have not yet moved new headers into a module. @@ -163,34 +213,51 @@ target_link_modules( # $ # $) -if (xrpld) +if(xrpld) add_executable(xrpld) - if (tests) + if(tests) target_compile_definitions(xrpld PUBLIC ENABLE_TESTS) - target_compile_definitions(xrpld PRIVATE UNIT_TEST_REFERENCE_FEE=${UNIT_TEST_REFERENCE_FEE}) - endif () - target_include_directories(xrpld PRIVATE $) + target_compile_definitions( + xrpld + PRIVATE UNIT_TEST_REFERENCE_FEE=${UNIT_TEST_REFERENCE_FEE} + ) + endif() + target_include_directories( + xrpld + PRIVATE $ + ) - file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/xrpld/*.cpp") + file( + GLOB_RECURSE sources + CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/src/xrpld/*.cpp" + ) target_sources(xrpld PRIVATE ${sources}) - if (tests) - file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/test/*.cpp") + if(tests) + file( + GLOB_RECURSE sources + CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/src/test/*.cpp" + ) target_sources(xrpld PRIVATE ${sources}) - endif () + endif() target_link_libraries(xrpld Xrpl::boost Xrpl::opts Xrpl::libs xrpl.libxrpl) exclude_if_included(xrpld) # define a macro for tests that might need to # be excluded or run differently in CI environment - if (is_ci) + if(is_ci) target_compile_definitions(xrpld PRIVATE XRPL_RUNNING_IN_CI) - endif () + endif() - if (voidstar) + if(voidstar) target_compile_options(xrpld PRIVATE -fsanitize-coverage=trace-pc-guard) # xrpld requires access to antithesis-sdk-cpp implementation file # antithesis_instrumentation.h, which is not exported as INTERFACE - target_include_directories(xrpld PRIVATE ${CMAKE_SOURCE_DIR}/external/antithesis-sdk) - endif () -endif () + target_include_directories( + xrpld + PRIVATE ${CMAKE_SOURCE_DIR}/external/antithesis-sdk + ) + endif() +endif() diff --git a/cmake/XrplCov.cmake b/cmake/XrplCov.cmake index 62c40407f2..109f5049fd 100644 --- a/cmake/XrplCov.cmake +++ b/cmake/XrplCov.cmake @@ -2,14 +2,17 @@ coverage report target #]===================================================================] -if (NOT coverage) +if(NOT coverage) message(FATAL_ERROR "Code coverage not enabled! Aborting ...") -endif () +endif() -if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - message(WARNING "Code coverage on Windows is not supported, ignoring 'coverage' flag") +if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + message( + WARNING + "Code coverage on Windows is not supported, ignoring 'coverage' flag" + ) return() -endif () +endif() include(ProcessorCount) ProcessorCount(PROCESSOR_COUNT) @@ -21,18 +24,19 @@ include(CodeCoverage) # `CodeCoverage.cmake`) set(GCOVR_ADDITIONAL_ARGS ${coverage_extra_args}) -if (NOT GCOVR_ADDITIONAL_ARGS STREQUAL "") +if(NOT GCOVR_ADDITIONAL_ARGS STREQUAL "") separate_arguments(GCOVR_ADDITIONAL_ARGS) -endif () +endif() -list(APPEND - GCOVR_ADDITIONAL_ARGS - --exclude-throw-branches - --exclude-noncode-lines - --exclude-unreachable-branches - -s - -j - ${PROCESSOR_COUNT}) +list( + APPEND GCOVR_ADDITIONAL_ARGS + --exclude-throw-branches + --exclude-noncode-lines + --exclude-unreachable-branches + -s + -j + ${PROCESSOR_COUNT} +) setup_target_for_coverage_gcovr( NAME @@ -47,6 +51,7 @@ setup_target_for_coverage_gcovr( "${CMAKE_BINARY_DIR}/pb-xrpl.libpb" DEPENDENCIES xrpld - xrpl.tests) + xrpl.tests +) add_code_coverage_to_target(opts INTERFACE) diff --git a/cmake/XrplDocs.cmake b/cmake/XrplDocs.cmake index 4892e390ce..aefffba81b 100644 --- a/cmake/XrplDocs.cmake +++ b/cmake/XrplDocs.cmake @@ -2,44 +2,45 @@ docs target (optional) #]===================================================================] -if (NOT only_docs) +if(NOT only_docs) return() -endif () +endif() find_package(Doxygen) -if (NOT TARGET Doxygen::doxygen) +if(NOT TARGET Doxygen::doxygen) message(STATUS "doxygen executable not found -- skipping docs target") return() -endif () +endif() set(doxygen_output_directory "${CMAKE_BINARY_DIR}/docs") set(doxygen_include_path "${CMAKE_CURRENT_SOURCE_DIR}/src") set(doxygen_index_file "${doxygen_output_directory}/html/index.html") set(doxyfile "${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile") -file(GLOB_RECURSE - doxygen_input - docs/*.md - include/*.h - include/*.cpp - include/*.md - src/*.h - src/*.cpp - src/*.md - Builds/*.md - *.md) +file( + GLOB_RECURSE doxygen_input + docs/*.md + include/*.h + include/*.cpp + include/*.md + src/*.h + src/*.cpp + src/*.md + Builds/*.md + *.md +) list(APPEND doxygen_input external/README.md) set(dependencies "${doxygen_input}" "${doxyfile}") -function (verbose_find_path variable name) +function(verbose_find_path variable name) # find_path sets a CACHE variable, so don't try using a "local" variable. find_path(${variable} "${name}" ${ARGN}) - if (NOT ${variable}) + if(NOT ${variable}) message(NOTICE "could not find ${name}") - else () + else() message(STATUS "found ${name}: ${${variable}}/${name}") - endif () -endfunction () + endif() +endfunction() verbose_find_path(doxygen_plantuml_jar_path plantuml.jar PATH_SUFFIXES share/plantuml) verbose_find_path(doxygen_dot_path dot) @@ -47,26 +48,40 @@ verbose_find_path(doxygen_dot_path dot) # https://en.cppreference.com/w/Cppreference:Archives # https://stackoverflow.com/questions/60822559/how-to-move-a-file-download-from-configure-step-to-build-step set(download_script "${CMAKE_BINARY_DIR}/docs/download-cppreference.cmake") -file(WRITE "${download_script}" - "file(DOWNLOAD \ +file( + WRITE "${download_script}" + "file(DOWNLOAD \ https://github.com/PeterFeicht/cppreference-doc/releases/download/v20250209/html-book-20250209.zip \ ${CMAKE_BINARY_DIR}/docs/cppreference.zip \ EXPECTED_HASH MD5=bda585f72fbca4b817b29a3d5746567b \ )\n \ execute_process( \ COMMAND \"${CMAKE_COMMAND}\" -E tar -xf cppreference.zip \ - )\n") + )\n" +) set(tagfile "${CMAKE_BINARY_DIR}/docs/cppreference-doxygen-web.tag.xml") -add_custom_command(OUTPUT "${tagfile}" COMMAND "${CMAKE_COMMAND}" -P "${download_script}" - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/docs") +add_custom_command( + OUTPUT "${tagfile}" + COMMAND "${CMAKE_COMMAND}" -P "${download_script}" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/docs" +) set(doxygen_tagfiles "${tagfile}=http://en.cppreference.com/w/") add_custom_command( OUTPUT "${doxygen_index_file}" - COMMAND "${CMAKE_COMMAND}" -E env "DOXYGEN_OUTPUT_DIRECTORY=${doxygen_output_directory}" - "DOXYGEN_INCLUDE_PATH=${doxygen_include_path}" "DOXYGEN_TAGFILES=${doxygen_tagfiles}" - "DOXYGEN_PLANTUML_JAR_PATH=${doxygen_plantuml_jar_path}" - "DOXYGEN_DOT_PATH=${doxygen_dot_path}" "${DOXYGEN_EXECUTABLE}" "${doxyfile}" + COMMAND + "${CMAKE_COMMAND}" -E env + "DOXYGEN_OUTPUT_DIRECTORY=${doxygen_output_directory}" + "DOXYGEN_INCLUDE_PATH=${doxygen_include_path}" + "DOXYGEN_TAGFILES=${doxygen_tagfiles}" + "DOXYGEN_PLANTUML_JAR_PATH=${doxygen_plantuml_jar_path}" + "DOXYGEN_DOT_PATH=${doxygen_dot_path}" "${DOXYGEN_EXECUTABLE}" + "${doxyfile}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - DEPENDS "${dependencies}" "${tagfile}") -add_custom_target(docs DEPENDS "${doxygen_index_file}" SOURCES "${dependencies}") + DEPENDS "${dependencies}" "${tagfile}" +) +add_custom_target( + docs + DEPENDS "${doxygen_index_file}" + SOURCES "${dependencies}" +) diff --git a/cmake/XrplInstall.cmake b/cmake/XrplInstall.cmake index 666fc0712f..6ea41b5ffd 100644 --- a/cmake/XrplInstall.cmake +++ b/cmake/XrplInstall.cmake @@ -6,57 +6,71 @@ include(create_symbolic_link) # If no suffix is defined for executables (e.g. Windows uses .exe but Linux # and macOS use none), then explicitly set it to the empty string. -if (NOT DEFINED suffix) +if(NOT DEFINED suffix) set(suffix "") -endif () +endif() -install(TARGETS common - opts - xrpl_boost - xrpl_libs - xrpl_syslibs - xrpl.imports.main - xrpl.libpb - xrpl.libxrpl - xrpl.libxrpl.basics - xrpl.libxrpl.beast - xrpl.libxrpl.conditions - xrpl.libxrpl.core - xrpl.libxrpl.crypto - xrpl.libxrpl.git - xrpl.libxrpl.json - xrpl.libxrpl.rdb - xrpl.libxrpl.ledger - xrpl.libxrpl.net - xrpl.libxrpl.nodestore - xrpl.libxrpl.protocol - xrpl.libxrpl.resource - xrpl.libxrpl.server - xrpl.libxrpl.shamap - xrpl.libxrpl.tx - antithesis-sdk-cpp - EXPORT XrplExports - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib - RUNTIME DESTINATION bin - INCLUDES - DESTINATION include) +install( + TARGETS + common + opts + xrpl_boost + xrpl_libs + xrpl_syslibs + xrpl.imports.main + xrpl.libpb + xrpl.libxrpl + xrpl.libxrpl.basics + xrpl.libxrpl.beast + xrpl.libxrpl.conditions + xrpl.libxrpl.core + xrpl.libxrpl.crypto + xrpl.libxrpl.git + xrpl.libxrpl.json + xrpl.libxrpl.rdb + xrpl.libxrpl.ledger + xrpl.libxrpl.net + xrpl.libxrpl.nodestore + xrpl.libxrpl.protocol + xrpl.libxrpl.resource + xrpl.libxrpl.server + xrpl.libxrpl.shamap + xrpl.libxrpl.tx + antithesis-sdk-cpp + EXPORT XrplExports + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION include +) -install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/xrpl" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") +install( + DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/xrpl" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) -install(EXPORT XrplExports FILE XrplTargets.cmake NAMESPACE Xrpl:: DESTINATION lib/cmake/xrpl) +install( + EXPORT XrplExports + FILE XrplTargets.cmake + NAMESPACE Xrpl:: + DESTINATION lib/cmake/xrpl +) include(CMakePackageConfigHelpers) -write_basic_package_version_file(XrplConfigVersion.cmake VERSION ${xrpld_version} - COMPATIBILITY SameMajorVersion) +write_basic_package_version_file( + XrplConfigVersion.cmake + VERSION ${xrpld_version} + COMPATIBILITY SameMajorVersion +) -if (is_root_project AND TARGET xrpld) +if(is_root_project AND TARGET xrpld) install(TARGETS xrpld RUNTIME DESTINATION bin) set_target_properties(xrpld PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON) # sample configs should not overwrite existing files # install if-not-exists workaround as suggested by # https://cmake.org/Bug/view.php?id=12646 - install(CODE " + install( + CODE + " macro (copy_if_not_exists SRC DEST NEWNAME) if (NOT EXISTS \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/\${DEST}/\${NEWNAME}\") file (INSTALL FILE_PERMISSIONS OWNER_READ OWNER_WRITE DESTINATION \"\${CMAKE_INSTALL_PREFIX}/\${DEST}\" FILES \"\${SRC}\" RENAME \"\${NEWNAME}\") @@ -66,14 +80,22 @@ if (is_root_project AND TARGET xrpld) endmacro() copy_if_not_exists(\"${CMAKE_CURRENT_SOURCE_DIR}/cfg/xrpld-example.cfg\" etc xrpld.cfg) copy_if_not_exists(\"${CMAKE_CURRENT_SOURCE_DIR}/cfg/validators-example.txt\" etc validators.txt) - ") - install(CODE " + " + ) + install( + CODE + " set(CMAKE_MODULE_PATH \"${CMAKE_MODULE_PATH}\") include(create_symbolic_link) create_symbolic_link(xrpld${suffix} \ \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/rippled${suffix}) - ") -endif () + " + ) +endif() -install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/XrplConfig.cmake - ${CMAKE_CURRENT_BINARY_DIR}/XrplConfigVersion.cmake DESTINATION lib/cmake/xrpl) +install( + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/XrplConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/XrplConfigVersion.cmake + DESTINATION lib/cmake/xrpl +) diff --git a/cmake/XrplInterface.cmake b/cmake/XrplInterface.cmake index dbf907c7b4..21fa76501d 100644 --- a/cmake/XrplInterface.cmake +++ b/cmake/XrplInterface.cmake @@ -5,47 +5,55 @@ include(CompilationEnv) # Set defaults for optional variables to avoid uninitialized variable warnings -if (NOT DEFINED voidstar) +if(NOT DEFINED voidstar) set(voidstar OFF) -endif () +endif() add_library(opts INTERFACE) add_library(Xrpl::opts ALIAS opts) target_compile_definitions( opts - INTERFACE BOOST_ASIO_DISABLE_HANDLER_TYPE_REQUIREMENTS - BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT - BOOST_CONTAINER_FWD_BAD_DEQUE - HAS_UNCAUGHT_EXCEPTIONS=1 - $<$: - BOOST_ASIO_NO_DEPRECATED - BOOST_FILESYSTEM_NO_DEPRECATED - > - $<$>: - BOOST_COROUTINES_NO_DEPRECATION_WARNING - BOOST_BEAST_ALLOW_DEPRECATED - BOOST_FILESYSTEM_DEPRECATED - > - $<$:BEAST_NO_UNIT_TEST_INLINE=1> - $<$:BEAST_DONT_AUTOLINK_TO_WIN32_LIBRARIES=1> - $<$:XRPL_SINGLE_IO_SERVICE_THREAD=1> - $<$:ENABLE_VOIDSTAR>) + INTERFACE + BOOST_ASIO_DISABLE_HANDLER_TYPE_REQUIREMENTS + BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT + BOOST_CONTAINER_FWD_BAD_DEQUE + HAS_UNCAUGHT_EXCEPTIONS=1 + $<$: + BOOST_ASIO_NO_DEPRECATED + BOOST_FILESYSTEM_NO_DEPRECATED + > + $<$>: + BOOST_COROUTINES_NO_DEPRECATION_WARNING + BOOST_BEAST_ALLOW_DEPRECATED + BOOST_FILESYSTEM_DEPRECATED + > + $<$:BEAST_NO_UNIT_TEST_INLINE=1> + $<$:BEAST_DONT_AUTOLINK_TO_WIN32_LIBRARIES=1> + $<$:XRPL_SINGLE_IO_SERVICE_THREAD=1> + $<$:ENABLE_VOIDSTAR> +) target_compile_options( opts - INTERFACE $<$,$>:-Wsuggest-override> - $<$:-Wno-maybe-uninitialized> - $<$:-fno-omit-frame-pointer> - $<$:-pg> - $<$,$>:-p>) + INTERFACE + $<$,$>:-Wsuggest-override> + $<$:-Wno-maybe-uninitialized> + $<$:-fno-omit-frame-pointer> + $<$:-pg> + $<$,$>:-p> +) -target_link_libraries(opts INTERFACE $<$:-pg> - $<$,$>:-p>) +target_link_libraries( + opts + INTERFACE + $<$:-pg> + $<$,$>:-p> +) -if (jemalloc) +if(jemalloc) find_package(jemalloc REQUIRED) target_compile_definitions(opts INTERFACE PROFILE_JEMALLOC) target_link_libraries(opts INTERFACE jemalloc::jemalloc) -endif () +endif() #[===================================================================[ xrpld transitive library deps via an interface library @@ -55,31 +63,33 @@ add_library(xrpl_syslibs INTERFACE) add_library(Xrpl::syslibs ALIAS xrpl_syslibs) target_link_libraries( xrpl_syslibs - INTERFACE $<$: - legacy_stdio_definitions.lib - Shlwapi - kernel32 - user32 - gdi32 - winspool - comdlg32 - advapi32 - shell32 - ole32 - oleaut32 - uuid - odbc32 - odbccp32 - crypt32 - > - $<$>:dl> - $<$,$>>:rt>) + INTERFACE + $<$: + legacy_stdio_definitions.lib + Shlwapi + kernel32 + user32 + gdi32 + winspool + comdlg32 + advapi32 + shell32 + ole32 + oleaut32 + uuid + odbc32 + odbccp32 + crypt32 + > + $<$>:dl> + $<$,$>>:rt> +) -if (NOT is_msvc) +if(NOT is_msvc) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads) target_link_libraries(xrpl_syslibs INTERFACE Threads::Threads) -endif () +endif() add_library(xrpl_libs INTERFACE) add_library(Xrpl::libs ALIAS xrpl_libs) diff --git a/cmake/XrplSanitizers.cmake b/cmake/XrplSanitizers.cmake index 6ddc0b7e7d..f9630f6856 100644 --- a/cmake/XrplSanitizers.cmake +++ b/cmake/XrplSanitizers.cmake @@ -44,23 +44,26 @@ include(CompilationEnv) # Read environment variable set(SANITIZERS "") -if (DEFINED ENV{SANITIZERS}) +if(DEFINED ENV{SANITIZERS}) set(SANITIZERS "$ENV{SANITIZERS}") -endif () +endif() # Set SANITIZERS_ENABLED flag for use in other modules -if (SANITIZERS MATCHES "address|thread|undefinedbehavior") +if(SANITIZERS MATCHES "address|thread|undefinedbehavior") set(SANITIZERS_ENABLED TRUE) -else () +else() set(SANITIZERS_ENABLED FALSE) return() -endif () +endif() # Sanitizers are not supported on Windows/MSVC -if (is_msvc) - message(FATAL_ERROR "Sanitizers are not supported on Windows/MSVC. " - "Please unset the SANITIZERS environment variable.") -endif () +if(is_msvc) + message( + FATAL_ERROR + "Sanitizers are not supported on Windows/MSVC. " + "Please unset the SANITIZERS environment variable." + ) +endif() message(STATUS "Configuring sanitizers: ${SANITIZERS}") @@ -74,24 +77,30 @@ set(san_list "${SANITIZERS}") string(REPLACE "," ";" san_list "${san_list}") separate_arguments(san_list) -foreach (san IN LISTS san_list) - if (san STREQUAL "address") +foreach(san IN LISTS san_list) + if(san STREQUAL "address") set(enable_asan TRUE) - elseif (san STREQUAL "thread") + elseif(san STREQUAL "thread") set(enable_tsan TRUE) - elseif (san STREQUAL "undefinedbehavior") + elseif(san STREQUAL "undefinedbehavior") set(enable_ubsan TRUE) - else () - message(FATAL_ERROR "Unsupported sanitizer type: ${san}" - "Supported: address, thread, undefinedbehavior and their combinations.") - endif () -endforeach () + else() + message( + FATAL_ERROR + "Unsupported sanitizer type: ${san}" + "Supported: address, thread, undefinedbehavior and their combinations." + ) + endif() +endforeach() # Validate sanitizer compatibility -if (enable_asan AND enable_tsan) - message(FATAL_ERROR "AddressSanitizer and ThreadSanitizer are incompatible and cannot be enabled simultaneously. " - "Use 'address' or 'thread', optionally with 'undefinedbehavior'.") -endif () +if(enable_asan AND enable_tsan) + message( + FATAL_ERROR + "AddressSanitizer and ThreadSanitizer are incompatible and cannot be enabled simultaneously. " + "Use 'address' or 'thread', optionally with 'undefinedbehavior'." + ) +endif() # Frame pointer is required for meaningful stack traces. Sanitizers recommend minimum of -O1 for reasonable performance set(SANITIZERS_COMPILE_FLAGS "-fno-omit-frame-pointer" "-O1") @@ -99,66 +108,79 @@ set(SANITIZERS_COMPILE_FLAGS "-fno-omit-frame-pointer" "-O1") # Build the sanitizer flags list set(SANITIZER_TYPES) -if (enable_asan) +if(enable_asan) list(APPEND SANITIZER_TYPES "address") -elseif (enable_tsan) +elseif(enable_tsan) list(APPEND SANITIZER_TYPES "thread") -endif () +endif() -if (enable_ubsan) +if(enable_ubsan) # UB sanitizer flags list(APPEND SANITIZER_TYPES "undefined" "float-divide-by-zero") - if (is_clang) + if(is_clang) # Clang supports additional UB checks. More info here # https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html list(APPEND SANITIZER_TYPES "unsigned-integer-overflow") - endif () -endif () + endif() +endif() # Configure code model for GCC on amd64 Use large code model for ASAN to avoid relocation errors Use medium code model # for TSAN (large is not compatible with TSAN) set(SANITIZERS_RELOCATION_FLAGS) # Compiler-specific configuration -if (is_gcc) +if(is_gcc) # Disable mold, gold and lld linkers for GCC with sanitizers Use default linker (bfd/ld) which is more lenient with # mixed code models This is needed since the size of instrumented binary exceeds the limits set by mold, lld and # gold linkers set(use_mold OFF CACHE BOOL "Use mold linker" FORCE) set(use_gold OFF CACHE BOOL "Use gold linker" FORCE) set(use_lld OFF CACHE BOOL "Use lld linker" FORCE) - message(STATUS " Disabled mold, gold, and lld linkers for GCC with sanitizers") + message( + STATUS + " Disabled mold, gold, and lld linkers for GCC with sanitizers" + ) # Suppress false positive warnings in GCC with stringop-overflow list(APPEND SANITIZERS_COMPILE_FLAGS "-Wno-stringop-overflow") - if (is_amd64 AND enable_asan) + if(is_amd64 AND enable_asan) message(STATUS " Using large code model (-mcmodel=large)") list(APPEND SANITIZERS_COMPILE_FLAGS "-mcmodel=large") list(APPEND SANITIZERS_RELOCATION_FLAGS "-mcmodel=large") - elseif (enable_tsan) + elseif(enable_tsan) # GCC doesn't support atomic_thread_fence with tsan. Suppress warnings. list(APPEND SANITIZERS_COMPILE_FLAGS "-Wno-tsan") message(STATUS " Using medium code model (-mcmodel=medium)") list(APPEND SANITIZERS_COMPILE_FLAGS "-mcmodel=medium") list(APPEND SANITIZERS_RELOCATION_FLAGS "-mcmodel=medium") - endif () + endif() # Join sanitizer flags with commas for -fsanitize option list(JOIN SANITIZER_TYPES "," SANITIZER_TYPES_STR) # Add sanitizer to compile and link flags list(APPEND SANITIZERS_COMPILE_FLAGS "-fsanitize=${SANITIZER_TYPES_STR}") - set(SANITIZERS_LINK_FLAGS "${SANITIZERS_RELOCATION_FLAGS}" "-fsanitize=${SANITIZER_TYPES_STR}") - -elseif (is_clang) + set(SANITIZERS_LINK_FLAGS + "${SANITIZERS_RELOCATION_FLAGS}" + "-fsanitize=${SANITIZER_TYPES_STR}" + ) +elseif(is_clang) # Add ignorelist for Clang (GCC doesn't support this) Use CMAKE_SOURCE_DIR to get the path to the ignorelist - set(IGNORELIST_PATH "${CMAKE_SOURCE_DIR}/sanitizers/suppressions/sanitizer-ignorelist.txt") - if (NOT EXISTS "${IGNORELIST_PATH}") - message(FATAL_ERROR "Sanitizer ignorelist not found: ${IGNORELIST_PATH}") - endif () + set(IGNORELIST_PATH + "${CMAKE_SOURCE_DIR}/sanitizers/suppressions/sanitizer-ignorelist.txt" + ) + if(NOT EXISTS "${IGNORELIST_PATH}") + message( + FATAL_ERROR + "Sanitizer ignorelist not found: ${IGNORELIST_PATH}" + ) + endif() - list(APPEND SANITIZERS_COMPILE_FLAGS "-fsanitize-ignorelist=${IGNORELIST_PATH}") + list( + APPEND SANITIZERS_COMPILE_FLAGS + "-fsanitize-ignorelist=${IGNORELIST_PATH}" + ) message(STATUS " Using sanitizer ignorelist: ${IGNORELIST_PATH}") # Join sanitizer flags with commas for -fsanitize option @@ -167,31 +189,35 @@ elseif (is_clang) # Add sanitizer to compile and link flags list(APPEND SANITIZERS_COMPILE_FLAGS "-fsanitize=${SANITIZER_TYPES_STR}") set(SANITIZERS_LINK_FLAGS "-fsanitize=${SANITIZER_TYPES_STR}") -endif () +endif() message(STATUS " Compile flags: ${SANITIZERS_COMPILE_FLAGS}") message(STATUS " Link flags: ${SANITIZERS_LINK_FLAGS}") # Apply the sanitizer flags to the 'common' interface library This is the same library used by XrplCompiler.cmake -target_compile_options(common INTERFACE $<$:${SANITIZERS_COMPILE_FLAGS}> - $<$:${SANITIZERS_COMPILE_FLAGS}>) +target_compile_options( + common + INTERFACE + $<$:${SANITIZERS_COMPILE_FLAGS}> + $<$:${SANITIZERS_COMPILE_FLAGS}> +) # Apply linker flags target_link_options(common INTERFACE ${SANITIZERS_LINK_FLAGS}) # Define SANITIZERS macro for BuildInfo.cpp set(sanitizers_list) -if (enable_asan) +if(enable_asan) list(APPEND sanitizers_list "ASAN") -endif () -if (enable_tsan) +endif() +if(enable_tsan) list(APPEND sanitizers_list "TSAN") -endif () -if (enable_ubsan) +endif() +if(enable_ubsan) list(APPEND sanitizers_list "UBSAN") -endif () +endif() -if (sanitizers_list) +if(sanitizers_list) list(JOIN sanitizers_list "." sanitizers_str) target_compile_definitions(common INTERFACE SANITIZERS=${sanitizers_str}) -endif () +endif() diff --git a/cmake/XrplSanity.cmake b/cmake/XrplSanity.cmake index 489ad026e1..24b4d4d408 100644 --- a/cmake/XrplSanity.cmake +++ b/cmake/XrplSanity.cmake @@ -7,40 +7,49 @@ include(CompilationEnv) get_property(is_multiconfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE) -if (NOT is_multiconfig) - if (NOT CMAKE_BUILD_TYPE) +if(NOT is_multiconfig) + if(NOT CMAKE_BUILD_TYPE) message(STATUS "Build type not specified - defaulting to Release") set(CMAKE_BUILD_TYPE Release CACHE STRING "build type" FORCE) - elseif (NOT (CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL Release)) + elseif( + NOT (CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL Release) + ) # for simplicity, these are the only two config types we care about. Limiting the build types simplifies dealing # with external project builds especially - message(FATAL_ERROR " *** Only Debug or Release build types are currently supported ***") - endif () -endif () + message( + FATAL_ERROR + " *** Only Debug or Release build types are currently supported ***" + ) + endif() +endif() -if (is_clang) # both Clang and AppleClang - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS - 16.0) +if(is_clang) # both Clang and AppleClang + if( + "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" + AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.0 + ) message(FATAL_ERROR "This project requires clang 16 or later") - endif () -elseif (is_gcc) - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0) + endif() +elseif(is_gcc) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0) message(FATAL_ERROR "This project requires GCC 12 or later") - endif () -endif () + endif() +endif() # check for in-source build and fail -if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") - message(FATAL_ERROR "Builds (in-source) are not allowed in " - "${CMAKE_CURRENT_SOURCE_DIR}. Please remove CMakeCache.txt and the CMakeFiles " - "directory from ${CMAKE_CURRENT_SOURCE_DIR} and try building in a separate directory." +if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") + message( + FATAL_ERROR + "Builds (in-source) are not allowed in " + "${CMAKE_CURRENT_SOURCE_DIR}. Please remove CMakeCache.txt and the CMakeFiles " + "directory from ${CMAKE_CURRENT_SOURCE_DIR} and try building in a separate directory." ) -endif () +endif() -if (MSVC AND CMAKE_GENERATOR_PLATFORM STREQUAL "Win32") +if(MSVC AND CMAKE_GENERATOR_PLATFORM STREQUAL "Win32") message(FATAL_ERROR "Visual Studio 32-bit build is not supported.") -endif () +endif() -if (APPLE AND NOT HOMEBREW) +if(APPLE AND NOT HOMEBREW) find_program(HOMEBREW brew) -endif () +endif() diff --git a/cmake/XrplSettings.cmake b/cmake/XrplSettings.cmake index 5c753fdcda..44a727a994 100644 --- a/cmake/XrplSettings.cmake +++ b/cmake/XrplSettings.cmake @@ -5,59 +5,67 @@ include(CompilationEnv) set(is_ci FALSE) -if (DEFINED ENV{CI}) - if ("$ENV{CI}" STREQUAL "true") +if(DEFINED ENV{CI}) + if("$ENV{CI}" STREQUAL "true") set(is_ci TRUE) - endif () -endif () + endif() +endif() get_directory_property(has_parent PARENT_DIRECTORY) -if (has_parent) +if(has_parent) set(is_root_project OFF) -else () +else() set(is_root_project ON) -endif () +endif() option(assert "Enables asserts, even in release builds" OFF) option(xrpld "Build xrpld" ON) option(tests "Build tests" ON) -if (tests) +if(tests) # This setting allows making a separate workflow to test fees other than default 10 - if (NOT UNIT_TEST_REFERENCE_FEE) + if(NOT UNIT_TEST_REFERENCE_FEE) set(UNIT_TEST_REFERENCE_FEE "10" CACHE STRING "") - endif () -endif () + endif() +endif() option(unity "Creates a build using UNITY support in cmake." OFF) -if (unity) - if (NOT is_ci) +if(unity) + if(NOT is_ci) set(CMAKE_UNITY_BUILD_BATCH_SIZE 15 CACHE STRING "") - endif () + endif() set(CMAKE_UNITY_BUILD ON CACHE BOOL "Do a unity build") -endif () +endif() -if (is_clang AND is_linux) +if(is_clang AND is_linux) option(voidstar "Enable Antithesis instrumentation." OFF) -endif () +endif() -if (is_gcc OR is_clang) +if(is_gcc OR is_clang) include(ProcessorCount) ProcessorCount(PROCESSOR_COUNT) option(coverage "Generates coverage info." OFF) option(profile "Add profiling flags" OFF) - set(coverage_format "html-details" CACHE STRING "Output format of the coverage report.") - set(coverage_extra_args "" CACHE STRING "Additional arguments to pass to gcovr.") + set(coverage_format + "html-details" + CACHE STRING + "Output format of the coverage report." + ) + set(coverage_extra_args + "" + CACHE STRING + "Additional arguments to pass to gcovr." + ) option(wextra "compile with extra gcc/clang warnings enabled" ON) -else () +else() set(profile OFF CACHE BOOL "gcc/clang only" FORCE) set(coverage OFF CACHE BOOL "gcc/clang only" FORCE) set(wextra OFF CACHE BOOL "gcc/clang only" FORCE) -endif () +endif() -if (is_linux AND NOT SANITIZER) +if(is_linux AND NOT SANITIZER) option(BUILD_SHARED_LIBS "build shared xrpl libraries" OFF) option(static "link protobuf, openssl, libc++, and boost statically" ON) option(perf "Enables flags that assist with perf recording" OFF) @@ -65,53 +73,83 @@ if (is_linux AND NOT SANITIZER) option(use_mold "enables detection of mold (binutils) linker" ON) # Set a default value for the log flag based on the build type. This provides a sensible default (on for debug, off # for release) while still allowing the user to override it for any build. - if (CMAKE_BUILD_TYPE STREQUAL "Debug") + if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(TRUNCATED_LOGS_DEFAULT ON) - else () + else() set(TRUNCATED_LOGS_DEFAULT OFF) - endif () - option(TRUNCATED_THREAD_NAME_LOGS "Show warnings about truncated thread names on Linux." - ${TRUNCATED_LOGS_DEFAULT}) - if (TRUNCATED_THREAD_NAME_LOGS) + endif() + option( + TRUNCATED_THREAD_NAME_LOGS + "Show warnings about truncated thread names on Linux." + ${TRUNCATED_LOGS_DEFAULT} + ) + if(TRUNCATED_THREAD_NAME_LOGS) add_compile_definitions(TRUNCATED_THREAD_NAME_LOGS) - endif () -else () + endif() +else() # we are not ready to allow shared-libs on windows because it would require export declarations. On macos it's more # feasible, but static openssl produces odd linker errors, thus we disable shared lib builds for now. - set(BUILD_SHARED_LIBS OFF CACHE BOOL "build shared xrpl libraries - OFF for win/macos" FORCE) + set(BUILD_SHARED_LIBS + OFF + CACHE BOOL + "build shared xrpl libraries - OFF for win/macos" + FORCE + ) set(static ON CACHE BOOL "static link, linux only. ON for WIN/macos" FORCE) set(perf OFF CACHE BOOL "perf flags, linux only" FORCE) set(use_gold OFF CACHE BOOL "gold linker, linux only" FORCE) set(use_mold OFF CACHE BOOL "mold linker, linux only" FORCE) -endif () +endif() -if (is_clang) +if(is_clang) option(use_lld "enables detection of lld linker" ON) -else () +else() set(use_lld OFF CACHE BOOL "try lld linker, clang only" FORCE) -endif () +endif() option(jemalloc "Enables jemalloc for heap profiling" OFF) option(werr "treat warnings as errors" OFF) -option(local_protobuf - "Force a local build of protobuf instead of looking for an installed version." OFF) -option(local_grpc "Force a local build of gRPC instead of looking for an installed version." OFF) +option( + local_protobuf + "Force a local build of protobuf instead of looking for an installed version." + OFF +) +option( + local_grpc + "Force a local build of gRPC instead of looking for an installed version." + OFF +) # the remaining options are obscure and rarely used -option(beast_no_unit_test_inline - "Prevents unit test definitions from being inserted into global table" OFF) -option(single_io_service_thread "Restricts the number of threads calling io_context::run to one. \ - This can be useful when debugging." OFF) -option(boost_show_deprecated "Allow boost to fail on deprecated usage. Only useful if you're trying\ - to find deprecated calls." OFF) +option( + beast_no_unit_test_inline + "Prevents unit test definitions from being inserted into global table" + OFF +) +option( + single_io_service_thread + "Restricts the number of threads calling io_context::run to one. \ + This can be useful when debugging." + OFF +) +option( + boost_show_deprecated + "Allow boost to fail on deprecated usage. Only useful if you're trying\ + to find deprecated calls." + OFF +) -if (WIN32) - option(beast_disable_autolink "Disables autolinking of system libraries on WIN32" OFF) -else () +if(WIN32) + option( + beast_disable_autolink + "Disables autolinking of system libraries on WIN32" + OFF + ) +else() set(beast_disable_autolink OFF CACHE BOOL "WIN32 only" FORCE) -endif () +endif() -if (coverage) +if(coverage) message(STATUS "coverage build requested - forcing Debug build") set(CMAKE_BUILD_TYPE Debug CACHE STRING "build type" FORCE) -endif () +endif() diff --git a/cmake/XrplValidatorKeys.cmake b/cmake/XrplValidatorKeys.cmake index 58672aada5..0e511b6a88 100644 --- a/cmake/XrplValidatorKeys.cmake +++ b/cmake/XrplValidatorKeys.cmake @@ -1,20 +1,26 @@ -option(validator_keys - "Enables building of validator-keys tool as a separate target (imported via FetchContent)" - OFF) +option( + validator_keys + "Enables building of validator-keys tool as a separate target (imported via FetchContent)" + OFF +) -if (validator_keys) +if(validator_keys) git_branch(current_branch) # default to tracking VK master branch unless we are on release - if (NOT (current_branch STREQUAL "release")) + if(NOT (current_branch STREQUAL "release")) set(current_branch "master") - endif () + endif() message(STATUS "Tracking ValidatorKeys branch: ${current_branch}") FetchContent_Declare( - validator_keys GIT_REPOSITORY https://github.com/ripple/validator-keys-tool.git - GIT_TAG "${current_branch}") + validator_keys + GIT_REPOSITORY https://github.com/ripple/validator-keys-tool.git + GIT_TAG "${current_branch}" + ) FetchContent_MakeAvailable(validator_keys) - set_target_properties(validator-keys PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") + set_target_properties( + validator-keys + PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" + ) install(TARGETS validator-keys RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - -endif () +endif() diff --git a/cmake/XrplVersion.cmake b/cmake/XrplVersion.cmake index 6eeda7b1eb..595b750d69 100644 --- a/cmake/XrplVersion.cmake +++ b/cmake/XrplVersion.cmake @@ -3,13 +3,13 @@ #]===================================================================] file(STRINGS src/libxrpl/protocol/BuildInfo.cpp BUILD_INFO) -foreach (line_ ${BUILD_INFO}) - if (line_ MATCHES "versionString[ ]*=[ ]*\"(.+)\"") +foreach(line_ ${BUILD_INFO}) + if(line_ MATCHES "versionString[ ]*=[ ]*\"(.+)\"") set(xrpld_version ${CMAKE_MATCH_1}) - endif () -endforeach () -if (xrpld_version) + endif() +endforeach() +if(xrpld_version) message(STATUS "xrpld version: ${xrpld_version}") -else () +else() message(FATAL_ERROR "unable to determine xrpld version") -endif () +endif() diff --git a/cmake/add_module.cmake b/cmake/add_module.cmake index 73618e8be3..5b1864a0bb 100644 --- a/cmake/add_module.cmake +++ b/cmake/add_module.cmake @@ -12,15 +12,23 @@ include(isolate_headers) # add_module(parent a) # add_module(parent b) # target_link_libraries(project.libparent.b PUBLIC project.libparent.a) -function (add_module parent name) +function(add_module parent name) set(target ${PROJECT_NAME}.lib${parent}.${name}) add_library(${target} OBJECT) - file(GLOB_RECURSE sources CONFIGURE_DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/src/lib${parent}/${name}/*.cpp") + file( + GLOB_RECURSE sources + CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/src/lib${parent}/${name}/*.cpp" + ) target_sources(${target} PRIVATE ${sources}) - target_include_directories(${target} PUBLIC "$") + target_include_directories( + ${target} + PUBLIC "$" + ) isolate_headers(${target} "${CMAKE_CURRENT_SOURCE_DIR}/include" - "${CMAKE_CURRENT_SOURCE_DIR}/include/${parent}/${name}" PUBLIC) + "${CMAKE_CURRENT_SOURCE_DIR}/include/${parent}/${name}" PUBLIC + ) isolate_headers(${target} "${CMAKE_CURRENT_SOURCE_DIR}/src" - "${CMAKE_CURRENT_SOURCE_DIR}/src/lib${parent}/${name}" PRIVATE) -endfunction () + "${CMAKE_CURRENT_SOURCE_DIR}/src/lib${parent}/${name}" PRIVATE + ) +endfunction() diff --git a/cmake/create_symbolic_link.cmake b/cmake/create_symbolic_link.cmake index 82ca915f5c..0cd8e1f567 100644 --- a/cmake/create_symbolic_link.cmake +++ b/cmake/create_symbolic_link.cmake @@ -1,19 +1,21 @@ # file(CREATE_SYMLINK) only works on Windows with administrator privileges. https://stackoverflow.com/a/61244115/618906 -function (create_symbolic_link target link) - if (WIN32) - if (NOT IS_SYMLINK "${link}") - if (NOT IS_ABSOLUTE "${target}") +function(create_symbolic_link target link) + if(WIN32) + if(NOT IS_SYMLINK "${link}") + if(NOT IS_ABSOLUTE "${target}") # Relative links work do not work on Windows. set(target "${link}/../${target}") - endif () + endif() file(TO_NATIVE_PATH "${target}" target) file(TO_NATIVE_PATH "${link}" link) - execute_process(COMMAND cmd.exe /c mklink /J "${link}" "${target}") - endif () - else () + execute_process( + COMMAND cmd.exe /c mklink /J "${link}" "${target}" + ) + endif() + else() file(CREATE_LINK "${target}" "${link}" SYMBOLIC) - endif () - if (NOT IS_SYMLINK "${link}") + endif() + if(NOT IS_SYMLINK "${link}") message(ERROR "failed to create symlink: <${link}>") - endif () -endfunction () + endif() +endfunction() diff --git a/cmake/deps/Boost.cmake b/cmake/deps/Boost.cmake index a7b145364d..10dc3e271a 100644 --- a/cmake/deps/Boost.cmake +++ b/cmake/deps/Boost.cmake @@ -1,45 +1,60 @@ include(CompilationEnv) include(XrplSanitizers) -find_package(Boost REQUIRED - COMPONENTS chrono - container - coroutine - date_time - filesystem - json - program_options - regex - system - thread) +find_package( + Boost + REQUIRED + COMPONENTS + chrono + container + coroutine + date_time + filesystem + json + program_options + regex + system + thread +) add_library(xrpl_boost INTERFACE) add_library(Xrpl::boost ALIAS xrpl_boost) target_link_libraries( xrpl_boost - INTERFACE Boost::headers - Boost::chrono - Boost::container - Boost::coroutine - Boost::date_time - Boost::filesystem - Boost::json - Boost::process - Boost::program_options - Boost::regex - Boost::thread) -if (Boost_COMPILER) + INTERFACE + Boost::headers + Boost::chrono + Boost::container + Boost::coroutine + Boost::date_time + Boost::filesystem + Boost::json + Boost::process + Boost::program_options + Boost::regex + Boost::thread +) +if(Boost_COMPILER) target_link_libraries(xrpl_boost INTERFACE Boost::disable_autolinking) -endif () -if (SANITIZERS_ENABLED AND is_clang) +endif() +if(SANITIZERS_ENABLED AND is_clang) # TODO: gcc does not support -fsanitize-blacklist...can we do something else for gcc ? - if (NOT Boost_INCLUDE_DIRS AND TARGET Boost::headers) - get_target_property(Boost_INCLUDE_DIRS Boost::headers INTERFACE_INCLUDE_DIRECTORIES) - endif () + if(NOT Boost_INCLUDE_DIRS AND TARGET Boost::headers) + get_target_property( + Boost_INCLUDE_DIRS + Boost::headers + INTERFACE_INCLUDE_DIRECTORIES + ) + endif() message(STATUS "Adding [${Boost_INCLUDE_DIRS}] to sanitizer blacklist") - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/san_bl.txt "src:${Boost_INCLUDE_DIRS}/*") + file( + WRITE ${CMAKE_CURRENT_BINARY_DIR}/san_bl.txt + "src:${Boost_INCLUDE_DIRS}/*" + ) target_compile_options( - opts INTERFACE # ignore boost headers for sanitizing - -fsanitize-blacklist=${CMAKE_CURRENT_BINARY_DIR}/san_bl.txt) -endif () + opts + INTERFACE # ignore boost headers for sanitizing + -fsanitize-blacklist=${CMAKE_CURRENT_BINARY_DIR}/san_bl.txt + ) +endif() diff --git a/cmake/isolate_headers.cmake b/cmake/isolate_headers.cmake index ef53b3f20a..4053cd6831 100644 --- a/cmake/isolate_headers.cmake +++ b/cmake/isolate_headers.cmake @@ -37,7 +37,7 @@ include(create_symbolic_link) # `${CMAKE_CURRENT_BINARY_DIR}/include/${target}`. # # isolate_headers(target A B scope) -function (isolate_headers target A B scope) +function(isolate_headers target A B scope) file(RELATIVE_PATH C "${A}" "${B}") set(X "${CMAKE_CURRENT_BINARY_DIR}/modules/${target}") set(Y "${X}/${C}") @@ -45,4 +45,4 @@ function (isolate_headers target A B scope) file(MAKE_DIRECTORY "${parent}") create_symbolic_link("${B}" "${Y}") target_include_directories(${target} ${scope} "$") -endfunction () +endfunction() diff --git a/cmake/target_link_modules.cmake b/cmake/target_link_modules.cmake index bcd80591b0..a923d81c66 100644 --- a/cmake/target_link_modules.cmake +++ b/cmake/target_link_modules.cmake @@ -6,9 +6,9 @@ # target_link_libraries(project.libparent.b PUBLIC project.libparent.a) # add_library(project.libparent) # target_link_modules(parent PUBLIC a b) -function (target_link_modules parent scope) +function(target_link_modules parent scope) set(library ${PROJECT_NAME}.lib${parent}) - foreach (name ${ARGN}) + foreach(name ${ARGN}) set(module ${library}.${name}) get_target_property(sources ${library} SOURCES) list(LENGTH sources before) @@ -17,8 +17,11 @@ function (target_link_modules parent scope) list(REMOVE_ITEM sources ${dupes}) list(LENGTH sources after) math(EXPR actual "${before} - ${after}") - message(STATUS "${module} with ${expected} sources took ${actual} sources from ${library}") + message( + STATUS + "${module} with ${expected} sources took ${actual} sources from ${library}" + ) set_target_properties(${library} PROPERTIES SOURCES "${sources}") target_link_libraries(${library} ${scope} ${module}) - endforeach () -endfunction () + endforeach() +endfunction() diff --git a/cmake/target_protobuf_sources.cmake b/cmake/target_protobuf_sources.cmake index bb5de02b53..2a04de9e11 100644 --- a/cmake/target_protobuf_sources.cmake +++ b/cmake/target_protobuf_sources.cmake @@ -35,20 +35,31 @@ find_package(Protobuf REQUIRED) # This prefix should appear at the start of all your consumer includes. # ARGN: # A list of .proto files. -function (target_protobuf_sources target prefix) +function(target_protobuf_sources target prefix) set(dir "${CMAKE_CURRENT_BINARY_DIR}/pb-${target}") file(MAKE_DIRECTORY "${dir}/${prefix}") - protobuf_generate(TARGET ${target} PROTOC_OUT_DIR "${dir}/${prefix}" "${ARGN}") + protobuf_generate( + TARGET ${target} + PROTOC_OUT_DIR "${dir}/${prefix}" + "${ARGN}" + ) target_include_directories( - ${target} SYSTEM + ${target} + SYSTEM PUBLIC # Allows #include used by consumer files. - $ - # Allows #include "path/to/file.proto" used by generated files. - $ - # Allows #include used by consumer files. - $ - # Allows #include "path/to/file.proto" used by generated files. - $) - install(DIRECTORY ${dir}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h") -endfunction () + $ + # Allows #include "path/to/file.proto" used by generated files. + $ + # Allows #include used by consumer files. + $ + # Allows #include "path/to/file.proto" used by generated files. + $ + ) + install( + DIRECTORY ${dir}/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + ) +endfunction() diff --git a/src/tests/libxrpl/CMakeLists.txt b/src/tests/libxrpl/CMakeLists.txt index cfa056b0aa..6bcb6aff89 100644 --- a/src/tests/libxrpl/CMakeLists.txt +++ b/src/tests/libxrpl/CMakeLists.txt @@ -14,7 +14,10 @@ target_link_libraries(xrpl.helpers.test PRIVATE xrpl.libxrpl) # Common library dependencies for the rest of the tests. add_library(xrpl.imports.test INTERFACE) -target_link_libraries(xrpl.imports.test INTERFACE gtest::gtest xrpl.libxrpl xrpl.helpers.test) +target_link_libraries( + xrpl.imports.test + INTERFACE gtest::gtest xrpl.libxrpl xrpl.helpers.test +) # One test for each module. xrpl_add_test(basics) @@ -30,8 +33,8 @@ target_link_libraries(xrpl.test.json PRIVATE xrpl.imports.test) add_dependencies(xrpl.tests xrpl.test.json) # Network unit tests are currently not supported on Windows -if (NOT WIN32) +if(NOT WIN32) xrpl_add_test(net) target_link_libraries(xrpl.test.net PRIVATE xrpl.imports.test) add_dependencies(xrpl.tests xrpl.test.net) -endif () +endif()