Build FISH-BUILD-VERSION-FILE in CMake build

This adds support for creating the FISH-BUILD-VERSION-FILE in the CMake
build. A FISH-BUILD-VERSION-FILE is created in the CMake directory
and only updated when necessary.
This commit is contained in:
ridiculousfish 2017-10-04 21:28:55 -07:00
parent d7baabab8d
commit 861b55d7d8
2 changed files with 15 additions and 10 deletions

View file

@ -30,11 +30,13 @@ SET(FISH_SRCS
src/wgetopt.cpp src/wildcard.cpp src/wutil.cpp
)
# Set up FISH-BUILD-VERSION-FILE
# Note this happens when CMake runs, not when the generated build system runs
EXECUTE_PROCESS(COMMAND build_tools/git_version_gen.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_QUIET)
# Set up the version target.
# This creates the file FISH-BUILD-VERSION-FILE which is only modified if necessary.
ADD_CUSTOM_COMMAND(OUTPUT "FISH-BUILD-VERSION-FILE"
DEPENDS CHECK-FISH-BUILD-VERSION-FILE)
ADD_CUSTOM_TARGET("CHECK-FISH-BUILD-VERSION-FILE"
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/git_version_gen.sh)
# Set up config.h
INCLUDE(CMakeFiles/ConfigureChecks.cmake)

View file

@ -1,9 +1,12 @@
#!/bin/sh
#!/bin/bash
# Originally from the git sources (GIT-VERSION-GEN)
# Presumably (C) Junio C Hamano <junkio@cox.net>
# Reused under GPL v2.0
# Modified for fish by David Adam <zanchey@ucc.gu.uwa.edu.au>
# Find the fish git directory as two levels up from this directory.
GIT_DIR=$(dirname $(dirname "${BASH_SOURCE[0]}"))
FBVF=FISH-BUILD-VERSION-FILE
DEF_VER=unknown
@ -12,17 +15,17 @@ DEF_VER=unknown
if test -f version
then
VN=$(cat version) || VN="$DEF_VER"
elif ! VN=$(git describe --always --dirty 2>/dev/null); then
elif ! VN=$(git -C "$GIT_DIR" describe --always --dirty 2>/dev/null); then
VN="$DEF_VER"
fi
if test -r $FBVF
then
VC=$(sed -e 's/^FISH_BUILD_VERSION = //' <$FBVF)
VC=$(sed -e 's/^FISH_BUILD_VERSION=//' <$FBVF)
else
VC=unset
fi
test "$VN" = "$VC" || {
echo >&2 "FISH_BUILD_VERSION = $VN"
echo "FISH_BUILD_VERSION = $VN" >$FBVF
echo >&2 "FISH_BUILD_VERSION=$VN"
echo "FISH_BUILD_VERSION=$VN" >$FBVF
}