From 861b55d7d8939d4c4560c1a2d6bcdccad2ac1509 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 4 Oct 2017 21:28:55 -0700 Subject: [PATCH] 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. --- CMakeLists.txt | 12 +++++++----- build_tools/git_version_gen.sh | 13 ++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 896f6a9fb..5678450c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/build_tools/git_version_gen.sh b/build_tools/git_version_gen.sh index ac3c26186..791ac8ff7 100755 --- a/build_tools/git_version_gen.sh +++ b/build_tools/git_version_gen.sh @@ -1,9 +1,12 @@ -#!/bin/sh +#!/bin/bash # Originally from the git sources (GIT-VERSION-GEN) # Presumably (C) Junio C Hamano # Reused under GPL v2.0 # Modified for fish by David Adam +# 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 }