diff --git a/CMakeLists.txt b/CMakeLists.txt index 3edafc61..bbd1d91b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,6 +119,19 @@ ADD_CUSTOM_TARGET(generated_headers ADD_DEPENDENCIES(${PROJECT_AWE_NAME} generated_headers) # }}} +# {{{ version stamp +IF(BUILD_FROM_GIT) + ADD_CUSTOM_TARGET(version_stamp ALL + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build-utils/git-version-stamp.sh + ${VERSION_STAMP_FILE} + ${CMAKE_CURRENT_BINARY_DIR}/awesome-version-internal.h + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + + ADD_DEPENDENCIES(${PROJECT_AWE_NAME} version_stamp) + ADD_DEPENDENCIES(${PROJECT_AWECLIENT_NAME} version_stamp) +ENDIF() +# }}} + # {{{ Manpages. IF(GENERATE_MANPAGES) diff --git a/awesomeConfig.cmake b/awesomeConfig.cmake index 6b083134..614129b0 100644 --- a/awesomeConfig.cmake +++ b/awesomeConfig.cmake @@ -58,16 +58,23 @@ IF(GENERATE_MANPAGES) ENDIF() # }}} +# {{{ git version stamp # If this is a git repository... IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/HEAD) - # ...update version IF(GIT_EXECUTABLE) + # get current version EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} describe - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + # file the git-version-stamp.sh script will look into + SET(VERSION_STAMP_FILE ${CMAKE_CURRENT_BINARY_DIR}/.version_stamp) + FILE(WRITE ${VERSION_STAMP_FILE} ${VERSION}) + # create a version_stamp target later + SET(BUILD_FROM_GIT TRUE) ENDIF() ENDIF() +# }}} # {{{ Required libraries # diff --git a/build-utils/git-version-stamp.sh b/build-utils/git-version-stamp.sh new file mode 100755 index 00000000..2703a9c7 --- /dev/null +++ b/build-utils/git-version-stamp.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# +# $1 file containing the last git-describe output +# $2 the file in which to update the version string +# +# TODO: proper error handling + +die() { + echo "$0: WARNING: version stamp update failed." + #exit 1 # not important enough to stop the build. + exit 0 +} + +STAMP=`cat "$1" 2> /dev/null` +CURRENT=`git-describe 2>/dev/null` + +if [[ -z "$STAMP" || -z "$CURRENT" ]]; then + die +fi + +if [ "$STAMP" != "$CURRENT" ]; then + echo "git version changed: $STAMP -> $CURRENT" + sed -e s/$STAMP/$CURRENT/g "$2" 1> "$2.new" || die + mv "$2.new" "$2" + echo -n "$CURRENT" > "$1" +fi