chore: Do not generate source files and use target_compile_definition… (#2369)

…s to set version

Advantages:
- not modifying src dir in build time (`git clean` will also remove
less)
- simpler codecov (if we decide to move it to separate stage in the
future)
- The cpp file is perfectly valid, so it will be treated as a C++ files
by all the tooling
- No need to use CMAKE_PROJECT_INCLUDE_BEFORE, should work fine without
it
- Instead of generating + recompiling, we will just be doing
recompilation of 1 file
This commit is contained in:
Ayaz Salikhov
2025-07-28 12:49:36 +01:00
committed by GitHub
parent 4a4f8842bd
commit 0e2ba4a64e
7 changed files with 15 additions and 14 deletions

View File

@@ -184,7 +184,6 @@ jobs:
# This is run as part of the build job, because it requires the following: # This is run as part of the build job, because it requires the following:
# - source code # - source code
# - generated source code (Build.cpp)
# - conan packages # - conan packages
# - .gcno files in build directory # - .gcno files in build directory
# #

1
.gitignore vendored
View File

@@ -9,4 +9,3 @@
.sanitizer-report .sanitizer-report
CMakeUserPresets.json CMakeUserPresets.json
config.json config.json
src/util/build/Build.cpp

View File

@@ -1,7 +1,5 @@
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
set(CMAKE_PROJECT_INCLUDE_BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ClioVersion.cmake)
project(clio VERSION ${CLIO_VERSION} HOMEPAGE_URL "https://github.com/XRPLF/clio" project(clio VERSION ${CLIO_VERSION} HOMEPAGE_URL "https://github.com/XRPLF/clio"
DESCRIPTION "An XRP Ledger API Server" DESCRIPTION "An XRP Ledger API Server"
) )

View File

@@ -1,7 +1,3 @@
#[===================================================================[
write version to source
#]===================================================================]
find_package(Git REQUIRED) find_package(Git REQUIRED)
set(GIT_COMMAND describe --tags --exact-match) set(GIT_COMMAND describe --tags --exact-match)
@@ -47,5 +43,3 @@ if (CMAKE_BUILD_TYPE MATCHES Debug)
endif () endif ()
message(STATUS "Build version: ${CLIO_VERSION}") message(STATUS "Build version: ${CLIO_VERSION}")
configure_file(${CMAKE_CURRENT_LIST_DIR}/Build.cpp.in ${CMAKE_CURRENT_LIST_DIR}/../src/util/build/Build.cpp)

View File

@@ -1,9 +1,10 @@
add_subdirectory(build)
add_library(clio_util) add_library(clio_util)
target_sources( target_sources(
clio_util clio_util
PRIVATE Assert.cpp PRIVATE Assert.cpp
build/Build.cpp
Coroutine.cpp Coroutine.cpp
CoroutineGroup.cpp CoroutineGroup.cpp
log/Logger.cpp log/Logger.cpp
@@ -57,6 +58,7 @@ target_link_libraries(
Threads::Threads Threads::Threads
clio_options clio_options
clio_rpc_center clio_rpc_center
clio_build_version
) )
# FIXME: needed on gcc-12, clang-16 and AppleClang for now (known boost 1.82 issue for some compilers) # FIXME: needed on gcc-12, clang-16 and AppleClang for now (known boost 1.82 issue for some compilers)

View File

@@ -23,19 +23,22 @@
namespace util::build { namespace util::build {
static constexpr char versionString[] = "@CLIO_VERSION@"; // NOLINT(readability-identifier-naming) #ifndef CLIO_VERSION
#error "CLIO_VERSION must be defined"
#endif
static constexpr char versionString[] = CLIO_VERSION;
std::string const& std::string const&
getClioVersionString() getClioVersionString()
{ {
static std::string const value = versionString; // NOLINT(readability-identifier-naming) static std::string const value = versionString; // NOLINT(readability-identifier-naming)
return value; return value;
} }
std::string const& std::string const&
getClioFullVersionString() getClioFullVersionString()
{ {
static std::string const value = "clio-" + getClioVersionString(); // NOLINT(readability-identifier-naming) static std::string const value = "clio-" + getClioVersionString(); // NOLINT(readability-identifier-naming)
return value; return value;
} }

View File

@@ -0,0 +1,6 @@
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/ClioVersion.cmake)
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}")