build: Limit auto-versioning to git revision hash

When building from a git checkout and HEAD does not exactly match
a tag, append the shortened revision hash to the hardcoded version
string. Do not attempt to provide any information beyond that.

This brings the PulseView versioning in line with the other modules
in the sigrok stack.
This commit is contained in:
Daniel Elstner 2015-11-02 22:14:39 +01:00
parent db8a1b5c7e
commit 812c0e3592
3 changed files with 8 additions and 28 deletions

View File

@ -107,7 +107,7 @@ function(git_describe _var)
execute_process(COMMAND
"${GIT_EXECUTABLE}"
describe
# ${hash} commented to make --dirty work
${hash}
${ARGN}
WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}"

View File

@ -1,7 +0,0 @@
# Include a version file in source packages, so that the version derived
# from the git repository becomes available for builds from source tarballs.
if(NOT CPACK_INSTALL_CMAKE_PROJECTS)
file(WRITE "${CPACK_TEMPORARY_DIRECTORY}/VERSION"
"${CPACK_SOURCE_PACKAGE_FILE_NAME}")
endif()

View File

@ -124,26 +124,14 @@ set(PV_DESCRIPTION "A GUI for sigrok")
set(PV_VERSION_STRING "0.3.0")
include(GetGitRevisionDescription)
git_describe(PV_TAG_VERSION_STRING --tags --dirty)
if(NOT PV_TAG_VERSION_STRING AND EXISTS "${PROJECT_SOURCE_DIR}/VERSION")
# Read the version from a file that is distributed with
# the source package (see writepackageversion.cmake).
file(STRINGS "${PROJECT_SOURCE_DIR}/VERSION" PV_TAG_VERSION_STRING LIMIT_COUNT 1)
endif()
if(PV_TAG_VERSION_STRING MATCHES
"^pulseview-([0-9]+\\.[0-9]+\\.[0-9]+)(-[0-9a-z]+)?(-g[-0-9a-z]+)?$")
set(PV_TAG_VERSION ${CMAKE_MATCH_1})
set(PV_TAG_PATCHLEVEL ${CMAKE_MATCH_2})
set(PV_TAG_REVHASH ${CMAKE_MATCH_3})
if(PV_VERSION_STRING VERSION_GREATER ${PV_TAG_VERSION})
# Tagged version older than current one: indicate pre-release.
set(PV_VERSION_STRING "${PV_VERSION_STRING}-pre${PV_TAG_REVHASH}")
else()
# For post-release changes, indicate the patch level.
set(PV_VERSION_STRING "${PV_TAG_VERSION}${PV_TAG_PATCHLEVEL}${PV_TAG_REVHASH}")
# Append the revision hash unless we are exactly on a tagged release.
git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
if(NOT PV_TAG_VERSION_STRING)
get_git_head_revision(PV_REVSPEC PV_HASH)
if(PV_HASH)
string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
endif()
endif()
@ -472,7 +460,6 @@ set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_INSTALL_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/CMake/writepackageversion.cmake)
include(CPack)