Skip to content
Snippets Groups Projects
Commit 5d2862f5 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Version in CMakeLists.txt

- added pastis version
- compilation checks compatibility of version and git revision info
- separates git info and version info for git-less compilation
parent 075fdbab
No related branches found
No related tags found
No related merge requests found
......@@ -10,13 +10,16 @@ include(CheckNotInSources)
#----------------- Main configuration -----------------
#------------------------------------------------------
project (Pastis)
project (Pastis
VERSION 0.0.2)
set(PASTIS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
# Rang (colors? Useless thus necessary!)
include_directories(${CMAKE_SOURCE_DIR}/packages/rang/include)
include_directories(${PASTIS_SOURCE_DIR}/packages/rang/include)
# CLI11
include_directories(${CMAKE_SOURCE_DIR}/packages/CLI11/include)
include_directories(${PASTIS_SOURCE_DIR}/packages/CLI11/include)
# Kokkos
add_subdirectory(${CMAKE_SOURCE_DIR}/packages/kokkos)
......@@ -41,3 +44,4 @@ target_link_libraries(
pastis
kokkos
PastisUtils)
# --------------- get git revision info ---------------
# quite hugly but seems necessary
set(CMAKE_CURRENT_SOURCE_DIR ${INVOCATION_DIR})
list(APPEND CMAKE_MODULE_PATH "${INVOCATION_DIR}/../cmake/cmake-modules")
list(APPEND CMAKE_MODULE_PATH "${PASTIS_SOURCE_DIR}/cmake/cmake-modules")
include(GetGitRevisionDescription)
git_describe(PASTIS_VERSION "--abbrev=0")
get_git_head_revision(PASTIS_HEAD PASTIS_HASH)
git_local_changes(PASTIS_HAS_LOCAL_CHANGES)
git_describe(PASTIS_GIT_TAG "--abbrev=0")
get_git_head_revision(PASTIS_GIT_HEAD PASTIS_GIT_HASH)
git_local_changes(PASTIS_GIT_HAS_LOCAL_CHANGES)
if(${PASTIS_HAS_LOCAL_CHANGES} STREQUAL "CLEAN")
set(PASTIS_IS_CLEAN true)
if(${PASTIS_GIT_HAS_LOCAL_CHANGES} STREQUAL "CLEAN")
set(PASTIS_GIT_IS_CLEAN true)
else()
set(PASTIS_IS_CLEAN false)
set(PASTIS_GIT_IS_CLEAN false)
endif()
string(FIND "${PASTIS_GIT_TAG}" "${CMAKE_PASTIS_VERSION}" FOUND_VERSION_SUBSTR)
if("${FOUND_VERSION_SUBSTR}" STREQUAL "-1")
message("")
message ("###### CMake code version ${CMAKE_PASTIS_VERSION} and")
message ("###### git revision info ${PASTIS_GIT_TAG} do not match!")
message("")
endif()
# Generates revision header file candidate
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/pastis_git_revision.hpp.in" "${CMAKE_CURRENT_BINARY_DIR}/pastis_git_revision" @ONLY)
configure_file("${PASTIS_SOURCE_DIR}/utils/pastis_git_revision.hpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/pastis_git_revision"
@ONLY)
......@@ -14,17 +14,20 @@ int main(int argc, char *argv[])
CLI11_PARSE(app, argc, argv);
std::cout << "Code version: "
<< rang::style::bold << RevisionInfo::version() << rang::style::reset << '\n';
std::cout << "-------------------- "
<< rang::fg::green
<< "git info"
<< rang::fg::reset
<<" -------------------------"
<< '\n';
std::cout << "version: " << rang::fg::reset
<< rang::style::bold << RevisionInfo::version() << rang::style::reset << '\n';
std::cout << "HEAD: " << rang::style::bold << RevisionInfo::head() << rang::style::reset << '\n';
std::cout << "hash: " << rang::style::bold << RevisionInfo::hash() << rang::style::reset << " (";
if (RevisionInfo::isClean()) {
std::cout << "tag: " << rang::fg::reset
<< rang::style::bold << RevisionInfo::gitTag() << rang::style::reset << '\n';
std::cout << "HEAD: " << rang::style::bold << RevisionInfo::gitHead() << rang::style::reset << '\n';
std::cout << "hash: " << rang::style::bold << RevisionInfo::gitHash() << rang::style::reset << " (";
if (RevisionInfo::gitIsClean()) {
std::cout << rang::fgB::green << "clean" << rang::fg::reset;
} else {
std::cout << rang::fgB::red << "dirty" << rang::fg::reset;
......
......@@ -44,15 +44,24 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pastis_git_revision.hpp
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pastis_git_revision
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -DINVOCATION_DIR=${CMAKE_CURRENT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/GetPastisGitRevision.cmake
COMMAND ${CMAKE_COMMAND} -DCMAKE_PASTIS_VERSION=${Pastis_VERSION} -DPASTIS_SOURCE_DIR=${PASTIS_SOURCE_DIR} -P ${PASTIS_SOURCE_DIR}/cmake/GetPastisGitRevision.cmake
COMMENT "Check pastis git status"
VERBATIM
)
# --------- check git revision info at build ----------
configure_file("${PASTIS_SOURCE_DIR}/utils/pastis_version.hpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/pastis_version.hpp"
@ONLY)
list(
APPEND
SOURCES
${CMAKE_CURRENT_BINARY_DIR}/pastis_git_revision.hpp)
${CMAKE_CURRENT_BINARY_DIR}/pastis_git_revision.hpp
${CMAKE_CURRENT_BINARY_DIR}/pastis_version.hpp
)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
......@@ -60,3 +69,4 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_dependencies(
PastisUtils
PastisGitRevison)
#include <RevisionInfo.hpp>
#include <pastis_git_revision.hpp>
#include <pastis_version.hpp>
std::string RevisionInfo::version()
{
return PASTIS_GIT_VERSION;
return PASTIS_VERSION;
}
std::string RevisionInfo::head()
std::string RevisionInfo::gitTag()
{
return PASTIS_GIT_TAG;
}
std::string RevisionInfo::gitHead()
{
return PASTIS_GIT_HEAD;
}
std::string RevisionInfo::hash()
std::string RevisionInfo::gitHash()
{
return PASTIS_GIT_HASH;
}
bool RevisionInfo::isClean()
bool RevisionInfo::gitIsClean()
{
return PASTIS_GIT_IS_CLEAN;
}
......@@ -6,9 +6,10 @@
struct RevisionInfo
{
static std::string version();
static std::string head();
static std::string hash();
static bool isClean();
static std::string gitTag();
static std::string gitHead();
static std::string gitHash();
static bool gitIsClean();
};
#endif // REVISION_INFO_HPP
#ifndef PASTIS_GIT_REVISION_HPP
#define PASTIS_GIT_REVISION_HPP
#define PASTIS_GIT_VERSION "@PASTIS_VERSION@"
#define PASTIS_GIT_HEAD "@PASTIS_HEAD@"
#define PASTIS_GIT_HASH "@PASTIS_HASH@"
#define PASTIS_GIT_HAS_LOCAL_CHANGES "@PASTIS_HAS_LOCAL_CHANGES@"
#define PASTIS_GIT_IS_CLEAN @PASTIS_IS_CLEAN@
#define PASTIS_GIT_TAG "@PASTIS_GIT_TAG@"
#define PASTIS_GIT_HEAD "@PASTIS_GIT_HEAD@"
#define PASTIS_GIT_HASH "@PASTIS_GIT_HASH@"
#define PASTIS_GIT_HAS_LOCAL_CHANGES "@PASTIS_GIT_HAS_LOCAL_CHANGES@"
#define PASTIS_GIT_IS_CLEAN @PASTIS_GIT_IS_CLEAN@
#endif // PASTIS_GIT_REVISION_HPP
#ifndef PASTIS_VERSION_HPP
#define PASTIS_VERSION_HPP
#define PASTIS_VERSION "@Pastis_VERSION@"
#endif // PASTIS_VERSION_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment