From 71240850c116376edef9ab5e2ddc335ea727c46d Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Sat, 15 Oct 2022 06:27:38 -0400 Subject: [PATCH] move SEQUANT_REVISION dependence into version.cpp to allow ccache do its job properly --- CMakeLists.txt | 34 ++++++++++++++++++++++------------ SeQuant/version.cpp | 14 ++++++++++++++ SeQuant/version.hpp.in | 18 ++++++++++-------- 3 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 SeQuant/version.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 11496e06f..b5158b622 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,19 @@ 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 () + # make SeQuant project project(SeQuant LANGUAGES CXX VERSION "${SEQUANT_VERSION}" DESCRIPTION "SEcond QUANTization toolkit") @@ -170,6 +183,8 @@ add_library(SeQuant-bliss ) add_library(SeQuant + ${PROJECT_BINARY_DIR}/SeQuant/version.hpp + SeQuant/version.cpp SeQuant/core/sequant.cpp SeQuant/core/sequant.hpp SeQuant/core/attr.hpp @@ -244,6 +259,12 @@ 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}\" +) target_link_libraries(SeQuant PUBLIC range-v3::range-v3 Boost::regex Boost::boost SeQuant-bliss Threads::Threads) if (SEQUANT_HAS_EXECUTION_HEADER_STANDALONE OR SEQUANT_HAS_EXECUTION_HEADER_WITH_TBB) @@ -255,6 +276,7 @@ if (SEQUANT_HAS_EXECUTION_HEADER_STANDALONE OR SEQUANT_HAS_EXECUTION_HEADER_WITH endif () target_include_directories(SeQuant PUBLIC $ + $ $) target_compile_features(SeQuant INTERFACE "cxx_std_17") install(TARGETS SeQuant-bliss EXPORT sequant COMPONENT sequant LIBRARY DESTINATION ${SEQUANT_INSTALL_LIBDIR}) @@ -438,18 +460,6 @@ add_subdirectory(doc) # export SeQuant ########################## -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 () - configure_file( ${PROJECT_SOURCE_DIR}/SeQuant/version.hpp.in ${PROJECT_BINARY_DIR}/SeQuant/version.hpp diff --git a/SeQuant/version.cpp b/SeQuant/version.cpp new file mode 100644 index 000000000..c412c8007 --- /dev/null +++ b/SeQuant/version.cpp @@ -0,0 +1,14 @@ +// +// Created by Eduard Valeyev on 10/14/22. +// + +#include + +namespace sequant { + +const char* revision() noexcept { + static const char revision[] = SEQUANT_REVISION; + return revision; +} + +} // namespace sequant diff --git a/SeQuant/version.hpp.in b/SeQuant/version.hpp.in index dbf5551d4..189bf238a 100644 --- a/SeQuant/version.hpp.in +++ b/SeQuant/version.hpp.in @@ -5,22 +5,24 @@ #ifndef SEQUANT_SRC_SEQUANT_VERSION_H_IN_H #define SEQUANT_SRC_SEQUANT_VERSION_H_IN_H -/* Defines a string with the Git SHA1 revision hash tag of SeQuant */ -#define SEQUANT_REVISION "@SEQUANT_REVISION@" - -/* TiledArray version X.Y.Z-id */ +/* SeQuant version X.Y.Z-id */ #define SEQUANT_VERSION "@SEQUANT_VERSION@" -/* TiledArray major version */ +/* SeQuant major version */ #define SEQUANT_MAJOR_VERSION @SEQUANT_MAJOR_VERSION@ -/* TiledArray minor version */ +/* SeQuant minor version */ #define SEQUANT_MINOR_VERSION @SEQUANT_MINOR_VERSION@ -/* TiledArray micro version */ +/* SeQuant micro version */ #define SEQUANT_MICRO_VERSION @SEQUANT_MICRO_VERSION@ -/* TiledArray prerelease id */ +/* SeQuant prerelease id */ #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; +} // namespace sequant + #endif // SEQUANT_SRC_SEQUANT_VERSION_H_IN_H