simplify git-revision.h generation.

This commit is contained in:
suter_a 2025-05-19 13:29:54 +02:00
parent 005b33c379
commit e525abe614
4 changed files with 22 additions and 73 deletions

View File

@ -224,6 +224,19 @@ else ()
set(IS_GIT_REPO 0)
endif ()
#--- start create git-revision.h ----------------------------------------------
if (IS_GIT_REPO)
execute_process(COMMAND sh ${CMAKE_SOURCE_DIR}/src/git_revision.sh)
set(HAVE_GIT_REV_H "-DHAVE_GIT_REV_H")
set(GIT_REV_H "git-revision.h")
else (IS_GIT_REPO)
set(HAVE_GIT_REV_H "")
set(GIT_REV_H "")
endif (IS_GIT_REPO)
#--- end create git-revision.h ------------------------------------------------
#--- rpath related things -----------------------------------------------------
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)

View File

@ -1,30 +0,0 @@
# configure_musrfit_version_file.cmake.in:
set(SRC_DIR "@CMAKE_SOURCE_DIR@")
set(BIN_DIR "@CMAKE_CURRENT_BINARY_DIR@")
# Set variables
set(CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@")
set(MUSRFIT_VERSION "@MUSRFIT_VERSION@")
# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${SRC_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --pretty="%h, %ci"
WORKING_DIRECTORY ${SRC_DIR}
OUTPUT_VARIABLE GIT_CURRENT_SHA1
OUTPUT_STRIP_TRAILING_WHITESPACE
)
configure_file(
${SRC_DIR}/cmake/git-revision.h.in
${BIN_DIR}/git-revision.h
@ONLY
)
# EOF

View File

@ -22,38 +22,6 @@ if (nexus)
endif (nexus)
set(MUSRFIT_LIBS ${MUSRFIT_LIBS} PMusr)
#--- start create git-revision.h ----------------------------------------------
if (IS_GIT_REPO)
configure_file(
${CMAKE_SOURCE_DIR}/cmake/configure_musrfit_version_file.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/configure_musrfit_version_file.cmake
@ONLY
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/git-revision.h
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/configure_musrfit_version_file.cmake
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/configure_musrfit_version_file.cmake
${CMAKE_SOURCE_DIR}/cmake/git-revision.h.in
COMMENT "Configuring git-revision.h"
VERBATIM
)
add_custom_target(
configure_musrfit_version ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/git-revision.h
)
set(HAVE_GIT_REV_H "-DHAVE_GIT_REV_H")
set(GIT_REV_H "git-revision.h")
else (IS_GIT_REPO)
set(HAVE_GIT_REV_H "")
set(GIT_REV_H "")
endif (IS_GIT_REPO)
#--- end create git-revision.h ------------------------------------------------
#--- add all executables ------------------------------------------------------
add_executable(addRun ${GIT_REV_H} addRun.cpp)
target_compile_options(addRun BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")

View File

@ -1,21 +1,19 @@
#!/bin/bash
echo "Generating header for git hash" $1 $2
GIT_HEADER="$1/$2"
if [ -z "$2" ]; then
GIT_HEADER="$1/git-revision.h"
fi
echo "-- Generating header for git hash"
GIT_HEADER="src/git-revision.h"
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
GIT_VERSION=`git log -n 1 --pretty=format:"%ad - %h"`
if grep --quiet "$GIT_VERSION" $GIT_HEADER; then
echo "No need to generate new $GIT_HEADER - git hash is unchanged"
exit 0;
if [ "$(grep -ics "$GIT_VERSION" $GIT_HEADER)" = 1 ]
then
echo "-- No need to generate new $GIT_HEADER - git hash is unchanged"
exit 0;
fi
echo "git branch is : " $GIT_BRANCH
echo "git version is : " $GIT_VERSION
echo "-- git branch is : " $GIT_BRANCH
echo "-- git version is : " $GIT_VERSION
echo "#ifndef GIT_VERSION_H" > $GIT_HEADER
echo "#define GIT_VERSION_H" >> $GIT_HEADER
@ -25,4 +23,4 @@ echo "#define GIT_CURRENT_SHA1 \"$GIT_VERSION\"" >> $GIT_HEADER
echo "" >> $GIT_HEADER
echo "#endif //GIT_VERSION_H" >> $GIT_HEADER
echo "file is generated into" $GIT_HEADER
echo "-- file is generated into" $GIT_HEADER