diff --git a/CMakeLists.txt b/CMakeLists.txt index e66f212fb..a5b311999 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,18 +34,9 @@ else (SEQUANT_PRERELEASE_ID) set(SEQUANT_EXT_VERSION "${SEQUANT_VERSION}") endif (SEQUANT_PRERELEASE_ID) -# extract git revision -if (EXISTS ${PROJECT_SOURCE_DIR}/.git) - find_package(Git REQUIRED) - execute_process( - COMMAND ${GIT_EXECUTABLE} rev-parse -q HEAD - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE SEQUANT_REVISION) - string(REGEX MATCH "[0-9a-f]*" - SEQUANT_REVISION "${SEQUANT_REVISION}") -else () - set(SEQUANT_REVISION "unknown") -endif () +# extract git metadata +include(GetGitMetadata) +vgkit_cmake_git_metadata() # make SeQuant project project(SeQuant LANGUAGES CXX VERSION "${SEQUANT_VERSION}" DESCRIPTION "SEcond QUANTization toolkit") @@ -81,7 +72,6 @@ include(FetchContent) include(AddCustomTargetSubproject) include(FeatureSummary) include(CMakePackageConfigHelpers) -include(external/versions.cmake) ########################## # Standard build variables @@ -261,11 +251,11 @@ add_library(SeQuant SeQuant/domain/mbpt/antisymmetrizer.hpp SeQuant/domain/mbpt/rdm.hpp ) -# feed SEQUANT_REVISION to SeQuant/version.cpp only to avoid recompiling everything -set_property( - SOURCE SeQuant/version.cpp - PROPERTY COMPILE_DEFINITIONS - SEQUANT_REVISION=\"${SEQUANT_REVISION}\" +# feed SEQUANT_GIT_REVISION and SEQUANT_GIT_DESCRIPTION to SeQuant/version.cpp only to avoid recompiling everything +set_source_files_properties( + SeQuant/version.cpp + PROPERTIES COMPILE_DEFINITIONS + "SEQUANT_GIT_REVISION=\"${SEQUANT_GIT_REVISION}\";SEQUANT_GIT_DESCRIPTION=\"${SEQUANT_GIT_DESCRIPTION}\"" ) target_link_libraries(SeQuant PUBLIC range-v3::range-v3 Boost::regex Boost::boost SeQuant-bliss Threads::Threads) diff --git a/SeQuant/version.cpp b/SeQuant/version.cpp index c412c8007..742ff4502 100644 --- a/SeQuant/version.cpp +++ b/SeQuant/version.cpp @@ -7,8 +7,13 @@ namespace sequant { const char* revision() noexcept { - static const char revision[] = SEQUANT_REVISION; + static const char revision[] = SEQUANT_GIT_REVISION; return revision; } +const char* git_description() noexcept { + static const char description[] = SEQUANT_GIT_DESCRIPTION; + return description; +} + } // namespace sequant diff --git a/SeQuant/version.hpp.in b/SeQuant/version.hpp.in index 189bf238a..e52962ee5 100644 --- a/SeQuant/version.hpp.in +++ b/SeQuant/version.hpp.in @@ -21,8 +21,17 @@ #define SEQUANT_PRERELEASE_ID "@SEQUANT_PRERELEASE_ID@" namespace sequant { + /** \return a string with the Git SHA1 revision hash tag of SeQuant */ -const char* revision() noexcept; +const char* git_revision() noexcept; + +/** + * \return a string with the human-readable description of the current source + * tree of SeQuant + * \note see `git describe --dirty` for the format description + * */ +const char* git_description() noexcept; + } // namespace sequant #endif // SEQUANT_SRC_SEQUANT_VERSION_H_IN_H