Skip to content

Commit

Permalink
Merge pull request #78 from ValeevGroup/evaleev/fix/git-revision
Browse files Browse the repository at this point in the history
SEQUANT_REVISION is now a runtime constant returned by sequant::revision()
  • Loading branch information
evaleev authored Oct 15, 2022
2 parents efa695d + 7124085 commit 8cf6e58
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
34 changes: 22 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -255,6 +276,7 @@ if (SEQUANT_HAS_EXECUTION_HEADER_STANDALONE OR SEQUANT_HAS_EXECUTION_HEADER_WITH
endif ()
target_include_directories(SeQuant PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
target_compile_features(SeQuant INTERFACE "cxx_std_17")
install(TARGETS SeQuant-bliss EXPORT sequant COMPONENT sequant LIBRARY DESTINATION ${SEQUANT_INSTALL_LIBDIR})
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions SeQuant/core/hugenholtz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace sequant {
/// @brief HugenholtzVertex represents a sequence of edges arranged into groups
/// by (topological) equivalence.
/// @tparam Edge the edge type; it must be EqualityComparable
/// @tparam EdgeEquality type of equality tester for Edge objects; @code
/// EdgeEquality(const Edge&, const Edge&) @endcode must be implicitly
/// convertible to bool and evaluate to true for equivalent arguments.
/// @tparam EdgeEquality type of equality tester for Edge objects;
/// `EdgeEquality(const Edge&, const Edge&)` must be implicitly
/// convertible to bool and evaluate to true for equivalent arguments.
template <typename Edge, typename EdgeEquality>
class HugenholtzVertex {
using Group = std::pair<Edge, container::set<size_t>>;
Expand Down
14 changes: 14 additions & 0 deletions SeQuant/version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Created by Eduard Valeyev on 10/14/22.
//

#include <SeQuant/version.hpp>

namespace sequant {

const char* revision() noexcept {
static const char revision[] = SEQUANT_REVISION;
return revision;
}

} // namespace sequant
18 changes: 10 additions & 8 deletions SeQuant/version.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8cf6e58

Please sign in to comment.