From f9e141a006f5c1411dc88be75e00e2f929ced9f9 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Wed, 9 Oct 2013 16:05:29 +0200 Subject: [PATCH] Prefer named tags to Git revision hashes for LDC verison. This allows for building of release packages without manually overriding the version string. The --tag argument is needed to pick up un-annotated tags as well. --- CMakeLists.txt | 17 ++++++++++++++--- cmake/Modules/GetGitRevisionDescription.cmake | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8095ea5..e77ec831 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -167,10 +167,21 @@ set(LDC_GENERATED # Gather source files. # include(GetGitRevisionDescription) -get_git_head_revision(REFSPEC HASH) -if(NOT HASH STREQUAL "GITDIR-NOTFOUND") - string(SUBSTRING "${HASH}" 0 6 LDC_VERSION) +git_get_exact_tag(TAG) +if(NOT TAG MATCHES "NOTFOUND") + if(TAG MATCHES "v[0-9].*") + # For a version tag, remove the leading 'v'. + string(SUBSTRING "${TAG}" 1 -1 LDC_VERSION) + else() + set(LDC_VERSION "${TAG}") + endif() +else() + get_git_head_revision(REFSPEC HASH) + if(NOT HASH STREQUAL "GITDIR-NOTFOUND") + string(SUBSTRING "${HASH}" 0 6 LDC_VERSION) + endif() endif() +message(STATUS "LDC version identifier: ${LDC_VERSION}") configure_file(driver/ldc-version.cpp.in driver/ldc-version.cpp) # Also add the header files to the build so that they are available in IDE diff --git a/cmake/Modules/GetGitRevisionDescription.cmake b/cmake/Modules/GetGitRevisionDescription.cmake index 1bf02300..d3d5f1eb 100644 --- a/cmake/Modules/GetGitRevisionDescription.cmake +++ b/cmake/Modules/GetGitRevisionDescription.cmake @@ -118,6 +118,6 @@ function(git_describe _var) endfunction() function(git_get_exact_tag _var) - git_describe(out --exact-match ${ARGN}) + git_describe(out --exact-match --tag ${ARGN}) set(${_var} "${out}" PARENT_SCOPE) endfunction()