feat(CMakeLists.txt): use bin/package_version if needed

1) When git sha1 is available:

    Lean (version 0.2.0, commit 4a119a0424, Release)

2) When git sha1 is not available, but there is bin/package_version file

    Lean (version 0.2.0, package 0.2.0~ubuntu1~12.04, Release)

3) Git sha1 is not available, bin/package_version does not exist.

    Lean (version 0.2.0, Release)

Close #229
This commit is contained in:
Soonho Kong 2014-10-07 16:51:43 -07:00
parent 92c424936a
commit 826166c257
3 changed files with 19 additions and 2 deletions

View file

@ -266,6 +266,16 @@ include_directories(${LEAN_SOURCE_DIR})
# Git HASH
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
set(LEAN_PACKAGE_VERSION "NOT-FOUND")
if(${GIT_SHA1} MATCHES "GITDIR-NOTFOUND")
message(STATUS "Failed to read git_sha1")
if(EXISTS "${LEAN_SOURCE_DIR}/../bin/package_version")
file(STRINGS "${LEAN_SOURCE_DIR}/../bin/package_version" LEAN_PACKAGE_VERSION)
message(STATUS "Package version detected: ${LEAN_PACKAGE_VERSION}")
endif()
else()
message(STATUS "git commit sha1: ${GIT_SHA1}")
endif()
configure_file("${LEAN_SOURCE_DIR}/githash.h.in" "${LEAN_BINARY_DIR}/githash.h")
# Version

View file

@ -64,7 +64,11 @@ static void on_ctrl_c(int ) {
static void display_header(std::ostream & out) {
out << "Lean (version " << LEAN_VERSION_MAJOR << "."
<< LEAN_VERSION_MINOR << "." << LEAN_VERSION_PATCH;
if (!std::strcmp(g_githash, "GITDIR-NOTFOUND")) {
if (std::strcmp(g_githash, "GITDIR-NOTFOUND") == 0) {
if (std::strcmp(LEAN_PACKAGE_VERSION, "NOT-FOUND") != 0) {
out << ", package " << LEAN_PACKAGE_VERSION;
}
} else {
out << ", commit " << std::string(g_githash).substr(0, 12);
}
out << ", " << LEAN_STR(LEAN_BUILD_TYPE) << ")\n";

View file

@ -1,4 +1,7 @@
// the configured options and settings for Tutorial
#define LEAN_VERSION_MAJOR @LEAN_VERSION_MAJOR@
#define LEAN_VERSION_MINOR @LEAN_VERSION_MINOR@
#define LEAN_VERSION_PATCH @LEAN_VERSION_PATCH@
// When git_sha1 is not avilable, lean reads bin/version file and
// assign its contents to LEAN_PACKAGE_VERSION
#define LEAN_PACKAGE_VERSION "@LEAN_PACKAGE_VERSION@"