From 64580005d6df60d4be594586dc072802f403bfdc Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 6 Nov 2014 13:16:43 +0000 Subject: [PATCH] Use simpler build revision approach. I deleted my CMake cache, and CMake would no longer find Git, though I had it installed in my Program Files (x86) folder beside CMake. The new approach doesn't require Git, it just reads the HEAD revision ID and shortens it to 8 characters. --- CMakeLists.txt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 348c8ed8..54e98669 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,12 +13,19 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) include(GetGitRevisionDescription) -git_describe(GIT_COMMIT_STRING --tags --long) +get_git_head_revision(GIT_REFSPEC GIT_COMMIT_STRING --tags --long) -# We just want the shortened commit ID, so get that. -string(FIND ${GIT_COMMIT_STRING} "-g" REV_POS REVERSE) -MATH(EXPR REV_POS "${REV_POS} + 2") -string(SUBSTRING ${GIT_COMMIT_STRING} ${REV_POS} -1 GIT_COMMIT_STRING) +IF (GIT_COMMIT_STRING MATCHES "GITDIR-NOTFOUND") + set(GIT_COMMIT_STRING "unknown") +ELSE () + # Get a shortened ID. Although knowing the shortest unique string requires Git, + # 8 characters should be a good compromise between chance of ambiguity and length, + # especially since the version numbers would narrow down the range of possibly + # ambiguous commits. + string(SUBSTRING ${GIT_COMMIT_STRING} 0 8 GIT_COMMIT_STRING) +ENDIF () + +message(STATUS "Git revision: ${GIT_COMMIT_STRING}") # Write to file. configure_file("${CMAKE_SOURCE_DIR}/src/backend/globals.cpp.in" "${CMAKE_BINARY_DIR}/generated/globals.cpp" @ONLY)