Embed git commit hash in the "About" dialog.

Also, remove usage of __DATE__ and __TIME__ to make the build fully
deterministic. They are redundant once we have the commit hash,
anyway.
pull/4/head
whitequark 2016-04-23 22:53:21 +00:00
parent c6747438e0
commit 2fed0587ea
4 changed files with 40 additions and 4 deletions

View File

@ -17,9 +17,12 @@ set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX
# project # project
include(GetGitCommitHash)
project(solvespace) project(solvespace)
set(solvespace_VERSION_MAJOR 2) set(solvespace_VERSION_MAJOR 2)
set(solvespace_VERSION_MINOR 1) set(solvespace_VERSION_MINOR 1)
string(SUBSTRING "${GIT_COMMIT_HASH}" 0 8 solvespace_GIT_HASH)
if(NOT WIN32 AND NOT APPLE) if(NOT WIN32 AND NOT APPLE)
set(GUI gtk2 CACHE STRING "GUI toolkit to use (one of: gtk2 gtk3)") set(GUI gtk2 CACHE STRING "GUI toolkit to use (one of: gtk2 gtk3)")

View File

@ -0,0 +1,35 @@
function(get_git_commit_hash)
get_filename_component(GIT_DESCRIBE_CMAKE_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
get_filename_component(GIT_ROOT ${GIT_DESCRIBE_CMAKE_DIR} PATH)
set(GIT_DIR "${GIT_ROOT}/.git")
# Add a CMake configure dependency to the currently checked out revision.
set(GIT_DEPENDS ${GIT_DIR}/HEAD)
file(READ ${GIT_DIR}/HEAD HEAD_REF)
if(HEAD_REF MATCHES "ref: (.+)\n")
set(HEAD_REF ${CMAKE_MATCH_1})
if(EXISTS "${GIT_DIR}/${HEAD_REF}")
list(APPEND GIT_DEPENDS ${GIT_DIR}/${HEAD_REF})
file(READ ${GIT_DIR}/${HEAD_REF} HEAD_REF)
elseif(EXISTS "${GIT_DIR}/packed-refs")
list(APPEND GIT_DEPENDS ${GIT_DIR}/packed-refs)
file(READ "${GIT_DIR}/packed-refs" PACKED_REFS)
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
set(HEAD_REF ${CMAKE_MATCH_1})
else()
set(HEAD_REF "")
endif()
else()
set(HEAD_REF "")
endif()
endif()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${GIT_DEPENDS})
string(STRIP ${HEAD_REF} HEAD_REF)
if(HEAD_REF STREQUAL "")
message(WARNING "Cannot determine git HEAD")
else()
set(GIT_COMMIT_HASH ${HEAD_REF} PARENT_SCOPE)
endif()
endfunction()
get_git_commit_hash()

View File

@ -1,7 +1,7 @@
#ifndef __CONFIG_H #ifndef __CONFIG_H
#define __CONFIG_H #define __CONFIG_H
#define PACKAGE_VERSION "@solvespace_VERSION_MAJOR@.@solvespace_VERSION_MINOR@" #define PACKAGE_VERSION "@solvespace_VERSION_MAJOR@.@solvespace_VERSION_MINOR@~@solvespace_GIT_HASH@"
/* MSVC includes a proper stdint.h, but only since VS2008. */ /* MSVC includes a proper stdint.h, but only since VS2008. */
#cmakedefine HAVE_STDINT_H #cmakedefine HAVE_STDINT_H

View File

@ -786,8 +786,6 @@ void SolveSpaceUI::MenuHelp(int id) {
Message( Message(
"This is SolveSpace version " PACKAGE_VERSION ".\n" "This is SolveSpace version " PACKAGE_VERSION ".\n"
"\n" "\n"
"Built " __TIME__ " " __DATE__ ".\n"
"\n"
"For more information, see http://solvespace.com/\n" "For more information, see http://solvespace.com/\n"
"\n" "\n"
"SolveSpace is free software: you are free to modify\n" "SolveSpace is free software: you are free to modify\n"
@ -797,7 +795,7 @@ void SolveSpaceUI::MenuHelp(int id) {
"There is NO WARRANTY, to the extent permitted by\n" "There is NO WARRANTY, to the extent permitted by\n"
"law. For details, visit http://gnu.org/licenses/\n" "law. For details, visit http://gnu.org/licenses/\n"
"\n" "\n"
"© 2008-2013 Jonathan Westhues and other authors.\n" "© 2008-2016 Jonathan Westhues and other authors.\n"
); );
break; break;