Skip to content

Commit 18fbc20

Browse files
committed
Merge pull request #498 from klickverbot/cmake-version-tag
Prefer named tags to Git revision hashes for LDC verison.
2 parents 1c36a35 + f9e141a commit 18fbc20

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

CMakeLists.txt

+14-3
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,21 @@ set(LDC_GENERATED
167167
# Gather source files.
168168
#
169169
include(GetGitRevisionDescription)
170-
get_git_head_revision(REFSPEC HASH)
171-
if(NOT HASH STREQUAL "GITDIR-NOTFOUND")
172-
string(SUBSTRING "${HASH}" 0 6 LDC_VERSION)
170+
git_get_exact_tag(TAG)
171+
if(NOT TAG MATCHES "NOTFOUND")
172+
if(TAG MATCHES "v[0-9].*")
173+
# For a version tag, remove the leading 'v'.
174+
string(SUBSTRING "${TAG}" 1 -1 LDC_VERSION)
175+
else()
176+
set(LDC_VERSION "${TAG}")
177+
endif()
178+
else()
179+
get_git_head_revision(REFSPEC HASH)
180+
if(NOT HASH STREQUAL "GITDIR-NOTFOUND")
181+
string(SUBSTRING "${HASH}" 0 6 LDC_VERSION)
182+
endif()
173183
endif()
184+
message(STATUS "LDC version identifier: ${LDC_VERSION}")
174185
configure_file(driver/ldc-version.cpp.in driver/ldc-version.cpp)
175186

176187
# Also add the header files to the build so that they are available in IDE

cmake/Modules/GetGitRevisionDescription.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ function(git_describe _var)
118118
endfunction()
119119

120120
function(git_get_exact_tag _var)
121-
git_describe(out --exact-match ${ARGN})
121+
git_describe(out --exact-match --tag ${ARGN})
122122
set(${_var} "${out}" PARENT_SCOPE)
123123
endfunction()

0 commit comments

Comments
 (0)