From a83ef111c8d527f9d8a6ef764d55c5baa06d5b54 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sun, 13 Mar 2016 17:07:04 +0100 Subject: Fix git commit tracking --- CMakeLists.txt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc06bb6..aada20f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,8 +19,16 @@ set (project_version "0.9.2") # we could also detect dirty worktrees but that's very hard to get right. find_package (Git) set (git_head "${PROJECT_SOURCE_DIR}/.git/HEAD") -if (GIT_FOUND AND EXISTS ${git_head}) - configure_file (${git_head} git-head.tag COPYONLY) +if (GIT_FOUND AND EXISTS "${git_head}") + configure_file ("${git_head}" git-head.tag COPYONLY) + file (READ "${git_head}" git_head_content) + if (git_head_content MATCHES "^ref: ([^\r\n]+)") + set (git_ref "${PROJECT_SOURCE_DIR}/.git/${CMAKE_MATCH_1}") + if (EXISTS "${git_ref}") + configure_file ("${git_ref}" git-ref.tag COPYONLY) + endif (EXISTS "${git_ref}") + endif (git_head_content MATCHES "^ref: ([^\r\n]+)") + execute_process (COMMAND ${GIT_EXECUTABLE} describe --tags --match v* WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE git_describe_result @@ -28,7 +36,7 @@ if (GIT_FOUND AND EXISTS ${git_head}) if (NOT git_describe_result) string (REGEX REPLACE "^v" "" project_version "${git_describe}") endif (NOT git_describe_result) -endif (GIT_FOUND AND EXISTS ${git_head}) +endif (GIT_FOUND AND EXISTS "${git_head}") # Dashes make filenames confusing and upset packaging software string (REPLACE "-" "+" project_version_safe "${project_version}") -- cgit v1.2.3-70-g09d2