diff --git a/CMakeLists.txt b/CMakeLists.txt index f784ceb1..84fa9dba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,9 +17,12 @@ set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX # project +include(GetGitCommitHash) + project(solvespace) set(solvespace_VERSION_MAJOR 2) set(solvespace_VERSION_MINOR 1) +string(SUBSTRING "${GIT_COMMIT_HASH}" 0 8 solvespace_GIT_HASH) if(NOT WIN32 AND NOT APPLE) set(GUI gtk2 CACHE STRING "GUI toolkit to use (one of: gtk2 gtk3)") diff --git a/cmake/GetGitCommitHash.cmake b/cmake/GetGitCommitHash.cmake new file mode 100644 index 00000000..f67a844a --- /dev/null +++ b/cmake/GetGitCommitHash.cmake @@ -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() diff --git a/src/config.h.in b/src/config.h.in index 4008c4bf..5253d4cd 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -1,7 +1,7 @@ #ifndef __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. */ #cmakedefine HAVE_STDINT_H diff --git a/src/solvespace.cpp b/src/solvespace.cpp index 5180e4b9..4bb634a4 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -786,8 +786,6 @@ void SolveSpaceUI::MenuHelp(int id) { Message( "This is SolveSpace version " PACKAGE_VERSION ".\n" "\n" -"Built " __TIME__ " " __DATE__ ".\n" -"\n" "For more information, see http://solvespace.com/\n" "\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" "law. For details, visit http://gnu.org/licenses/\n" "\n" -"© 2008-2013 Jonathan Westhues and other authors.\n" +"© 2008-2016 Jonathan Westhues and other authors.\n" ); break;