From bc5df7f35bf2f9e160a4739fbd96da584893cb55 Mon Sep 17 00:00:00 2001 From: Nicolas Hake Date: Wed, 12 Apr 2017 12:29:14 +0200 Subject: [PATCH] CMake: Add date of commit to logfile But only if the build is from a clean index. Otherwise, the logfile will contain the date of build. --- .git_archival | 1 + cmake/GitGetChangesetID.cmake | 15 ++++++++++++++- src/C4Version.h.in | 7 +++++++ src/game/C4Application.cpp | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.git_archival b/.git_archival index ff4124fe6..68307f4f1 100644 --- a/.git_archival +++ b/.git_archival @@ -1 +1,2 @@ node: $Format:%H$ +date: $Format:%ci$ diff --git a/cmake/GitGetChangesetID.cmake b/cmake/GitGetChangesetID.cmake index 0258e3840..7c8f6c4e9 100644 --- a/cmake/GitGetChangesetID.cmake +++ b/cmake/GitGetChangesetID.cmake @@ -37,6 +37,11 @@ function(git_get_changeset_id VAR) APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${GIT_INDEX}" ) + execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND "${GIT_EXECUTABLE}" "show" "--format=%ci" "-s" "HEAD" + OUTPUT_VARIABLE GIT_TIMESTAMP + OUTPUT_STRIP_TRAILING_WHITESPACE + ) endif() endif() if (NOT C4REVISION) @@ -53,9 +58,17 @@ function(git_get_changeset_id VAR) string(SUBSTRING "${C4REVISION}" 6 12 C4REVISION) endif() unset(revlength) + + file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/.git_archival" C4REVISION_TS + LIMIT_COUNT 1 + REGEX "date: .+" + ) + string(SUBSTRING "${C4REVISION_TS}" 6 -1 GIT_TIMESTAMP) endif() if(WORKDIR_DIRTY) - set(C4REVISION "${C4REVISION}+") + set(WORKDIR_DIRTY 1) endif() set(${VAR} "${C4REVISION}" PARENT_SCOPE) + set(${VAR}_DIRTY ${WORKDIR_DIRTY} PARENT_SCOPE) + set(${VAR}_TS "${GIT_TIMESTAMP}" PARENT_SCOPE) endfunction() diff --git a/src/C4Version.h.in b/src/C4Version.h.in index 43ffa9d97..57efb0f5b 100644 --- a/src/C4Version.h.in +++ b/src/C4Version.h.in @@ -32,7 +32,14 @@ #define C4XVER1 @C4XVER1@ #define C4XVER2 @C4XVER2@ +#cmakedefine01 C4REVISION_DIRTY +#if C4REVISION_DIRTY +#define C4REVISION "@C4REVISION@+" +#define C4REVISION_TS __DATE__ " " __TIME__ +#else #define C4REVISION "@C4REVISION@" +#define C4REVISION_TS "@C4REVISION_TS@" +#endif // Build Options #ifdef _DEBUG diff --git a/src/game/C4Application.cpp b/src/game/C4Application.cpp index f32afca2e..69256d1f3 100644 --- a/src/game/C4Application.cpp +++ b/src/game/C4Application.cpp @@ -104,7 +104,7 @@ bool C4Application::DoInit(int argc, char * argv[]) // Engine header message Log(C4ENGINECAPTION); - LogF("Version: %s %s (%s)", C4VERSION, C4_OS, GetRevision()); + LogF("Version: %s %s (%s - %s)", C4VERSION, C4_OS, GetRevision(), C4REVISION_TS); LogF("ExePath: \"%s\"", Config.General.ExePath.getData()); LogF("SystemDataPath: \"%s\"", Config.General.SystemDataPath); LogF("UserDataPath: \"%s\"", Config.General.UserDataPath);