Skip to content

Commit

Permalink
Generate a proper version string when using git archive
Browse files Browse the repository at this point in the history
this enable github-generated tarballs to work correctly
  • Loading branch information
boucman committed Oct 10, 2015
1 parent 07c1810 commit 52f540a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ if(NOT SOURCE_PACKAGE)
EXECUTE_PROCESS(COMMAND git describe --tags HEAD #OUTPUT_VARIABLE PROJECT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND sed "s,^release-,,;s,-,+,;s,-,~,;" OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE PROJECT_VERSION
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

# and here we write out the version into a .h file suitable to be used in the code.
# the file only gets written when the version is actually different to avoid unneeded recompiles
add_custom_target(
generate_version ALL
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/create_version_h.sh ${CMAKE_CURRENT_BINARY_DIR}/src/version_gen.h
COMMENT "Updating version string"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif(NOT SOURCE_PACKAGE)

# and here we write out the version into a .h file suitable to be used in the code.
# the file only gets written when the version is actually different to avoid unneeded recompiles
add_custom_target(
generate_version ALL
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/create_version_h.sh ${CMAKE_CURRENT_BINARY_DIR}/src/version_gen.h
COMMENT "Updating version string"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

#
# Initial cmake/debian/postinst and prerm script for debian package
#
Expand Down
1 change: 1 addition & 0 deletions tools/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create_version_h.sh export-subst
7 changes: 6 additions & 1 deletion tools/create_version_h.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ H_FILE=$1

VERSION_H_NEEDS_UPDATE=1

NEW_VERSION=`git describe --tags HEAD | sed 's,^release-,,;s,-,+,;s,-,~,;'`
NEW_VERSION=`git describe --tags --dirty | sed 's,^release-,,;s,-,+,;s,-,~,;'`

# if we are not in a git checkout, NEW_VERSION is empty
if [ -z "${NEW_VERSION}" ]; then
NEW_VERSION="archive-$Format:%H$"
fi

# version.h exists => check if it containts the up-to-date version
if [ -f ${H_FILE} ]; then
Expand Down

0 comments on commit 52f540a

Please sign in to comment.