cmake: update git version every build
This commit is contained in:
parent
35dce79296
commit
426d2fee9e
|
@ -119,6 +119,19 @@ ADD_CUSTOM_TARGET(generated_headers
|
||||||
ADD_DEPENDENCIES(${PROJECT_AWE_NAME} 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.
|
# {{{ Manpages.
|
||||||
IF(GENERATE_MANPAGES)
|
IF(GENERATE_MANPAGES)
|
||||||
|
|
||||||
|
|
|
@ -58,16 +58,23 @@ IF(GENERATE_MANPAGES)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
# {{{ git version stamp
|
||||||
# If this is a git repository...
|
# If this is a git repository...
|
||||||
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/HEAD)
|
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/HEAD)
|
||||||
# ...update version
|
|
||||||
IF(GIT_EXECUTABLE)
|
IF(GIT_EXECUTABLE)
|
||||||
|
# get current version
|
||||||
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} describe
|
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} describe
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
OUTPUT_VARIABLE VERSION
|
OUTPUT_VARIABLE VERSION
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
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()
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
# }}}
|
||||||
|
|
||||||
# {{{ Required libraries
|
# {{{ Required libraries
|
||||||
#
|
#
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue