fix git-revision.h generation: output to build tree and add missing dependencies
All checks were successful
Build and Deploy Documentation / build-and-deploy (push) Successful in 18s

Generate git-revision.h into CMAKE_BINARY_DIR/src/ (which is in the
include path) instead of the source tree. Remove the header from
add_executable() source lists, and add missing add_dependencies on
git_revision for all Qt5/Qt6 targets.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-29 19:52:16 +01:00
parent 8b054b77b9
commit 9d173203ff
11 changed files with 51 additions and 16 deletions

View File

@@ -241,16 +241,14 @@ endif ()
#--- start create git-revision.h ----------------------------------------------
if (IS_GIT_REPO)
add_custom_target(git_revision ALL
COMMAND sh ${CMAKE_SOURCE_DIR}/src/git_revision.sh
COMMAND sh ${CMAKE_SOURCE_DIR}/src/git_revision.sh ${CMAKE_BINARY_DIR}/src
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Checking git revision"
)
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 ------------------------------------------------

View File

@@ -23,7 +23,7 @@ endif (nexus)
set(MUSRFIT_LIBS ${MUSRFIT_LIBS} PMusr)
#--- add all executables ------------------------------------------------------
add_executable(addRun ${GIT_REV_H} addRun.cpp)
add_executable(addRun addRun.cpp)
target_compile_options(addRun BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")
target_include_directories(addRun
BEFORE PRIVATE
@@ -34,7 +34,7 @@ target_include_directories(addRun
)
target_link_libraries(addRun ${ROOT_LIBRARIES} ${MUSRFIT_LIBS} ${Boost_LIBRARIES})
add_executable(any2many ${GIT_REV_H} any2many.cpp)
add_executable(any2many any2many.cpp)
target_compile_options(any2many BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")
target_include_directories(any2many
BEFORE PRIVATE
@@ -45,7 +45,7 @@ target_include_directories(any2many
)
target_link_libraries(any2many ${ROOT_LIBRARIES} ${MUSRFIT_LIBS})
add_executable(dump_header ${GIT_REV_H} dump_header.cpp)
add_executable(dump_header dump_header.cpp)
target_compile_options(dump_header BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")
target_include_directories(dump_header
BEFORE PRIVATE
@@ -62,7 +62,7 @@ target_include_directories(dump_header
)
target_link_libraries(dump_header ${ROOT_LIBRARIES} ${MUSRFIT_LIBS})
add_executable(msr2data ${GIT_REV_H} msr2data.cpp)
add_executable(msr2data msr2data.cpp)
target_compile_options(msr2data BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")
target_include_directories(msr2data
BEFORE PRIVATE
@@ -76,7 +76,7 @@ target_link_libraries(msr2data ${ROOT_LIBRARIES} ${MUSRFIT_LIBS})
add_executable(msr2msr msr2msr.cpp)
target_link_libraries(msr2msr ${ROOT_LIBRARIES})
add_executable(musrfit ${GIT_REV_H} musrfit.cpp)
add_executable(musrfit musrfit.cpp)
target_compile_options(musrfit BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")
target_include_directories(musrfit
BEFORE PRIVATE
@@ -87,7 +87,7 @@ target_include_directories(musrfit
)
target_link_libraries(musrfit ${ROOT_LIBRARIES} ${MUSRFIT_LIBS})
add_executable(musrFT ${GIT_REV_H} musrFT.cpp)
add_executable(musrFT musrFT.cpp)
target_compile_options(musrFT BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")
target_include_directories(musrFT
BEFORE PRIVATE
@@ -99,7 +99,7 @@ target_include_directories(musrFT
)
target_link_libraries(musrFT FFTW3::FFTW3 ${ROOT_LIBRARIES} ${MUSRFIT_LIBS})
add_executable(musrRootValidation ${GIT_REV_H} musrRootValidation.cpp)
add_executable(musrRootValidation musrRootValidation.cpp)
target_compile_options(musrRootValidation BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")
target_include_directories(musrRootValidation
BEFORE PRIVATE
@@ -110,7 +110,7 @@ target_include_directories(musrRootValidation
)
target_link_libraries(musrRootValidation ${ROOT_LIBRARIES} ${MUSRFIT_LIBS} ${LIBXML2_LIBRARIES})
add_executable(musrt0 ${GIT_REV_H} musrt0.cpp)
add_executable(musrt0 musrt0.cpp)
target_compile_options(musrt0 BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")
target_include_directories(musrt0
BEFORE PRIVATE
@@ -121,7 +121,7 @@ target_include_directories(musrt0
)
target_link_libraries(musrt0 ${ROOT_LIBRARIES} ${MUSRFIT_LIBS})
add_executable(musrview ${GIT_REV_H} musrview.cpp)
add_executable(musrview musrview.cpp)
target_compile_options(musrview BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")
target_include_directories(musrview
BEFORE PRIVATE
@@ -133,7 +133,7 @@ target_include_directories(musrview
)
target_link_libraries(musrview FFTW3::FFTW3 ${ROOT_LIBRARIES} ${MUSRFIT_LIBS})
add_executable(write_musrRoot_runHeader ${GIT_REV_H} write_musrRoot_runHeader.cpp)
add_executable(write_musrRoot_runHeader write_musrRoot_runHeader.cpp)
target_compile_options(write_musrRoot_runHeader BEFORE PRIVATE "-DHAVE_CONFIG_H" "${HAVE_GIT_REV_H}")
target_include_directories(write_musrRoot_runHeader
BEFORE PRIVATE

View File

@@ -1,13 +1,18 @@
#!/bin/bash
# Usage: git_revision.sh <output_dir>
# Generates git-revision.h in the specified output directory.
OUTPUT_DIR="${1:-.}"
echo "-- Generating header for git hash"
GIT_HEADER="src/git-revision.h"
[ -d src ] || mkdir src
GIT_HEADER="${OUTPUT_DIR}/git-revision.h"
[ -d "${OUTPUT_DIR}" ] || mkdir -p "${OUTPUT_DIR}"
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
GIT_VERSION=`git log -n 1 --pretty=format:"%ad - %h"`
if [ "$(grep -ics "$GIT_VERSION" $GIT_HEADER)" = 1 ]
if [ -f "$GIT_HEADER" ] && [ "$(grep -cs "$GIT_VERSION" "$GIT_HEADER")" = 1 ]
then
echo "-- No need to generate new $GIT_HEADER - git hash is unchanged"
exit 0;

View File

@@ -90,6 +90,10 @@ target_include_directories(mupp
#--- use the Widgets and XML modules from Qt5 ---------------------------------
target_link_libraries(mupp PRIVATE Qt5::Widgets Qt5::Xml)
if (IS_GIT_REPO)
add_dependencies(mupp git_revision)
endif (IS_GIT_REPO)
#--- if macOS make an app rather than just a command line executable ----------
set_target_properties(mupp PROPERTIES
VERSION ${mupp_VERSION}

View File

@@ -51,6 +51,10 @@ target_compile_options(musrStep
target_link_libraries(musrStep PRIVATE ${qt_libs})
if (IS_GIT_REPO)
add_dependencies(musrStep git_revision)
endif (IS_GIT_REPO)
#--- installation info --------------------------------------------------------
if (APPLE)
set_target_properties(musrStep PROPERTIES

View File

@@ -55,6 +55,10 @@ target_compile_options(musrWiz
target_link_libraries(musrWiz PRIVATE ${qt_libs})
if (IS_GIT_REPO)
add_dependencies(musrWiz git_revision)
endif (IS_GIT_REPO)
#--- installation info --------------------------------------------------------
if (APPLE)
set_target_properties(musrWiz PROPERTIES

View File

@@ -105,6 +105,10 @@ target_compile_options(musredit
target_link_libraries(musredit PRIVATE ${qt_libs})
if (IS_GIT_REPO)
add_dependencies(musredit git_revision)
endif (IS_GIT_REPO)
#--- installation info --------------------------------------------------------
if (APPLE)
set_target_properties(musredit PROPERTIES

View File

@@ -90,6 +90,10 @@ target_include_directories(mupp
#--- use the Widgets and XML modules from Qt5 ---------------------------------
target_link_libraries(mupp PRIVATE Qt6::Widgets Qt6::Xml)
if (IS_GIT_REPO)
add_dependencies(mupp git_revision)
endif (IS_GIT_REPO)
#--- if macOS make an app rather than just a command line executable ----------
set_target_properties(mupp PROPERTIES
VERSION ${mupp_VERSION}

View File

@@ -51,6 +51,10 @@ target_compile_options(musrStep
target_link_libraries(musrStep PRIVATE ${qt_libs})
if (IS_GIT_REPO)
add_dependencies(musrStep git_revision)
endif (IS_GIT_REPO)
#--- installation info --------------------------------------------------------
if (APPLE)
set_target_properties(musrStep PROPERTIES

View File

@@ -55,6 +55,10 @@ target_compile_options(musrWiz
target_link_libraries(musrWiz PRIVATE ${qt_libs})
if (IS_GIT_REPO)
add_dependencies(musrWiz git_revision)
endif (IS_GIT_REPO)
#--- installation info --------------------------------------------------------
if (APPLE)
set_target_properties(musrWiz PROPERTIES

View File

@@ -104,6 +104,10 @@ target_compile_options(musredit
target_link_libraries(musredit PRIVATE ${qt_libs})
if (IS_GIT_REPO)
add_dependencies(musredit git_revision)
endif (IS_GIT_REPO)
#--- installation info --------------------------------------------------------
if (APPLE)
set_target_properties(musredit PROPERTIES