From 0e2ba4a64e8e530517ccbc454cdf4938a36db8bb Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Mon, 28 Jul 2025 12:49:36 +0100 Subject: [PATCH] =?UTF-8?q?chore:=20Do=20not=20generate=20source=20files?= =?UTF-8?q?=20and=20use=20target=5Fcompile=5Fdefinition=E2=80=A6=20(#2369)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …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 --- .github/workflows/build_impl.yml | 1 - .gitignore | 1 - CMakeLists.txt | 2 -- cmake/ClioVersion.cmake | 6 ------ src/util/CMakeLists.txt | 4 +++- cmake/Build.cpp.in => src/util/build/Build.cpp | 9 ++++++--- src/util/build/CMakeLists.txt | 6 ++++++ 7 files changed, 15 insertions(+), 14 deletions(-) rename cmake/Build.cpp.in => src/util/build/Build.cpp (83%) create mode 100644 src/util/build/CMakeLists.txt diff --git a/.github/workflows/build_impl.yml b/.github/workflows/build_impl.yml index 739ef6ca..da881bfb 100644 --- a/.github/workflows/build_impl.yml +++ b/.github/workflows/build_impl.yml @@ -184,7 +184,6 @@ jobs: # This is run as part of the build job, because it requires the following: # - source code - # - generated source code (Build.cpp) # - conan packages # - .gcno files in build directory # diff --git a/.gitignore b/.gitignore index f9f86f4a..9053fefb 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ .sanitizer-report CMakeUserPresets.json config.json -src/util/build/Build.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 92a7c581..ce7d3cec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,5 @@ 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" DESCRIPTION "An XRP Ledger API Server" ) diff --git a/cmake/ClioVersion.cmake b/cmake/ClioVersion.cmake index 9f963803..5f8ab450 100644 --- a/cmake/ClioVersion.cmake +++ b/cmake/ClioVersion.cmake @@ -1,7 +1,3 @@ -#[===================================================================[ - write version to source -#]===================================================================] - find_package(Git REQUIRED) set(GIT_COMMAND describe --tags --exact-match) @@ -47,5 +43,3 @@ if (CMAKE_BUILD_TYPE MATCHES Debug) endif () message(STATUS "Build version: ${CLIO_VERSION}") - -configure_file(${CMAKE_CURRENT_LIST_DIR}/Build.cpp.in ${CMAKE_CURRENT_LIST_DIR}/../src/util/build/Build.cpp) diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 3bf3ef4b..11394320 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -1,9 +1,10 @@ +add_subdirectory(build) + add_library(clio_util) target_sources( clio_util PRIVATE Assert.cpp - build/Build.cpp Coroutine.cpp CoroutineGroup.cpp log/Logger.cpp @@ -57,6 +58,7 @@ target_link_libraries( Threads::Threads clio_options 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) diff --git a/cmake/Build.cpp.in b/src/util/build/Build.cpp similarity index 83% rename from cmake/Build.cpp.in rename to src/util/build/Build.cpp index 4ae43918..f05f9fc0 100644 --- a/cmake/Build.cpp.in +++ b/src/util/build/Build.cpp @@ -23,19 +23,22 @@ 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& getClioVersionString() { - static std::string const value = versionString; // NOLINT(readability-identifier-naming) + static std::string const value = versionString; // NOLINT(readability-identifier-naming) return value; } std::string const& 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; } diff --git a/src/util/build/CMakeLists.txt b/src/util/build/CMakeLists.txt new file mode 100644 index 00000000..cf7a5b0d --- /dev/null +++ b/src/util/build/CMakeLists.txt @@ -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}")