simplify git-revision.h generation.
This commit is contained in:
parent
005b33c379
commit
e525abe614
@ -224,6 +224,19 @@ else ()
|
|||||||
set(IS_GIT_REPO 0)
|
set(IS_GIT_REPO 0)
|
||||||
endif ()
|
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 -----------------------------------------------------
|
#--- rpath related things -----------------------------------------------------
|
||||||
# use, i.e. don't skip the full RPATH for the build tree
|
# use, i.e. don't skip the full RPATH for the build tree
|
||||||
set(CMAKE_SKIP_BUILD_RPATH FALSE)
|
set(CMAKE_SKIP_BUILD_RPATH FALSE)
|
||||||
|
@ -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
|
|
@ -22,38 +22,6 @@ if (nexus)
|
|||||||
endif (nexus)
|
endif (nexus)
|
||||||
set(MUSRFIT_LIBS ${MUSRFIT_LIBS} PMusr)
|
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 all executables ------------------------------------------------------
|
||||||
add_executable(addRun ${GIT_REV_H} addRun.cpp)
|
add_executable(addRun ${GIT_REV_H} addRun.cpp)
|
||||||
target_compile_options(addRun BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")
|
target_compile_options(addRun BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")
|
||||||
|
@ -1,21 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo "Generating header for git hash" $1 $2
|
echo "-- Generating header for git hash"
|
||||||
GIT_HEADER="$1/$2"
|
GIT_HEADER="src/git-revision.h"
|
||||||
if [ -z "$2" ]; then
|
|
||||||
GIT_HEADER="$1/git-revision.h"
|
|
||||||
fi
|
|
||||||
|
|
||||||
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
|
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
|
||||||
|
|
||||||
GIT_VERSION=`git log -n 1 --pretty=format:"%ad - %h"`
|
GIT_VERSION=`git log -n 1 --pretty=format:"%ad - %h"`
|
||||||
if grep --quiet "$GIT_VERSION" $GIT_HEADER; then
|
if [ "$(grep -ics "$GIT_VERSION" $GIT_HEADER)" = 1 ]
|
||||||
echo "No need to generate new $GIT_HEADER - git hash is unchanged"
|
then
|
||||||
exit 0;
|
echo "-- No need to generate new $GIT_HEADER - git hash is unchanged"
|
||||||
|
exit 0;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "git branch is : " $GIT_BRANCH
|
echo "-- git branch is : " $GIT_BRANCH
|
||||||
echo "git version is : " $GIT_VERSION
|
echo "-- git version is : " $GIT_VERSION
|
||||||
|
|
||||||
echo "#ifndef GIT_VERSION_H" > $GIT_HEADER
|
echo "#ifndef GIT_VERSION_H" > $GIT_HEADER
|
||||||
echo "#define 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 "" >> $GIT_HEADER
|
||||||
echo "#endif //GIT_VERSION_H" >> $GIT_HEADER
|
echo "#endif //GIT_VERSION_H" >> $GIT_HEADER
|
||||||
|
|
||||||
echo "file is generated into" $GIT_HEADER
|
echo "-- file is generated into" $GIT_HEADER
|
||||||
|
Loading…
x
Reference in New Issue
Block a user