Generate FISH_BUILD_VERSION info for cmake builds

Correctly generate FISH_BUILD_VERSION for use in fish_version.h/cpp and
fish.pc to allow `fish --version` and `echo $version` to work again.

Not needing the same convoluted measures used by Makefile builds to
prevent the regeneration of the fish version file when it hasn't
changed.

Purposely created a new `cmake_git_version_gen.sh` file so that the old
`git_version_gen.sh` remains compatible with the existing Makefile build
script. Same reason why `fish.pc.in` was not modified to use a lowercase
variable name to match the CMAKE variable of the same name.

Closes #4626
This commit is contained in:
Mahmoud Al-Qudsi 2017-12-30 17:34:16 -06:00
parent 69f066dc1b
commit 25839b8c36
5 changed files with 49 additions and 16 deletions

View File

@ -55,16 +55,19 @@ SET(FISH_SRCS
# Header files are just globbed.
FILE(GLOB FISH_HEADERS src/*.h)
# 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)
# git_version_gen.sh creates FISH-BUILD-VERSION-FILE if it does not exist, and updates it
# only if it is out-of-date.
execute_process(
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/build_tools/cmake_git_version_gen.sh"
OUTPUT_VARIABLE FISH_BUILD_VERSION)
ADD_CUSTOM_TARGET("CHECK-FISH-BUILD-VERSION-FILE"
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/git_version_gen.sh)
SET(FBVF "FISH-BUILD-VERSION-FILE")
message(STATUS "FISH_BUILD_VERSION: ${FISH_BUILD_VERSION}")
ADD_DEFINITIONS(-DFISH_BUILD_VERSION="${FISH_BUILD_VERSION}")
# Set up fish-build-version.h
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/fish_build_version.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/include/fish_build_version.h")
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
# Set up config.h
INCLUDE(cmake/ConfigureChecks.cmake)
@ -75,8 +78,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
# Set up standard directories.
INCLUDE(GNUInstallDirs)
ADD_DEFINITIONS(-D_UNICODE=1
-DFISH_BUILD_VERSION="${FISH_BUILD_VERSION}"
ADD_DEFINITIONS(-DCMAKE
-D_UNICODE=1
-DLOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}"
-DPREFIX=L"${CMAKE_INSTALL_PREFIX}"
-DDATADIR=L"${CMAKE_INSTALL_FULL_DATADIR}"

View File

@ -0,0 +1,24 @@
#!/bin/sh
# 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>
# Obtain directory containing this script in POSIX-compatible manner
# See https://stackoverflow.com/a/43919044/17027 (public domain)
a="/$0"; a="${a%/*}"; a="${a:-.}"; a="${a#/}/"; BASEDIR=$(cd "$a"; pwd)
# Find the fish git directory as two levels up from this directory.
GIT_DIR=$(dirname "$a")
DEF_VER=unknown
# First see if there is a version file (included in release tarballs),
# then try git-describe, then default.
if test -f version
then
VN=$(cat version) || VN="$DEF_VER"
elif ! VN=$(git -C "$GIT_DIR" describe --always --dirty 2>/dev/null); then
VN="$DEF_VER"
fi
echo -n "$VN"

View File

@ -109,11 +109,10 @@ FISH_CREATE_DIRS(${rel_datadir}/pkgconfig ${extra_completionsdir}
# @echo "Installing pkgconfig file"
# $v $(INSTALL) -m 644 fish.pc $(DESTDIR)$(datadir)/pkgconfig
CONFIGURE_FILE(fish.pc.in fish.pc.noversion)
ADD_CUSTOM_COMMAND(OUTPUT fish.pc
COMMAND awk -v `cat ${FBVF}` '/^Version:/ {$$0=$$0 FISH_BUILD_VERSION} 1' fish.pc.noversion > fish.pc
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${FBVF} ${CMAKE_CURRENT_BINARY_DIR}/fish.pc.noversion)
# main CMakeFiles.txt sets ${FISH_BUILD_VERSION}, not ${fish_build_version}
set(fish_build_version ${FISH_BUILD_VERSION})
CONFIGURE_FILE(fish.pc.in fish.pc)
ADD_CUSTOM_TARGET(build_fish_pc ALL DEPENDS fish.pc)
@ -181,7 +180,7 @@ INSTALL(FILES ${MANUALS} DESTINATION ${mandir}/man1/ OPTIONAL)
INSTALL(FILES share/lynx.lss DESTINATION ${rel_datadir}/fish/)
# Group install targets into a InstallTargets folder
SET_PROPERTY(TARGET CHECK-FISH-BUILD-VERSION-FILE build_fish_pc
SET_PROPERTY(TARGET build_fish_pc
test_invocation test_fishscript
test_prep tests_buildroot_target
build_lexicon_filter

View File

@ -0,0 +1,4 @@
#pragma once
//to be filled in by cmake
#define FISH_BUILD_VERSION "@FISH_BUILD_VERSION@"

View File

@ -1,2 +1,5 @@
// Prototype for version receiver.
#ifdef CMAKE
#include <fish_build_version.h>
#endif
const char *get_fish_version();