build: use git-describe with just .git / add 'Using version from …' msg (#1302)

With Git submodules there is only a `.git` file typically, e.g.:

> gitdir: /home/user/Vcs/awesome-www/.git/modules/src
This commit is contained in:
Daniel Hahler 2016-12-25 23:17:54 +01:00 committed by GitHub
parent 58fed31d88
commit fdc93e68da
1 changed files with 4 additions and 1 deletions

View File

@ -87,7 +87,8 @@ endif()
# {{{ Version stamp
if(OVERRIDE_VERSION)
set(VERSION ${OVERRIDE_VERSION})
elseif(EXISTS ${SOURCE_DIR}/.git/HEAD AND GIT_EXECUTABLE)
message(STATUS "Using version from OVERRIDE_VERSION: ${VERSION}")
elseif(EXISTS ${SOURCE_DIR}/.git AND GIT_EXECUTABLE)
# get current version
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --dirty
@ -99,9 +100,11 @@ elseif(EXISTS ${SOURCE_DIR}/.git/HEAD AND GIT_EXECUTABLE)
file(WRITE ${VERSION_STAMP_FILE} ${VERSION})
# create a version_stamp target later
set(BUILD_FROM_GIT TRUE)
message(STATUS "Using version from git: ${VERSION}")
elseif( EXISTS ${SOURCE_DIR}/.version_stamp )
# get version from version stamp
file(READ ${SOURCE_DIR}/.version_stamp VERSION)
message(STATUS "Using version from ${SOURCE_DIR}/.version_stamp: ${VERSION}")
endif()
# }}}