From 9d173203ffe77f5b4ef2001f262de49894429558 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Thu, 29 Jan 2026 19:52:16 +0100 Subject: [PATCH] fix git-revision.h generation: output to build tree and add missing dependencies 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 --- CMakeLists.txt | 4 +--- src/CMakeLists.txt | 20 ++++++++++---------- src/git_revision.sh | 11 ++++++++--- src/musredit_qt5/mupp/CMakeLists.txt | 4 ++++ src/musredit_qt5/musrStep/CMakeLists.txt | 4 ++++ src/musredit_qt5/musrWiz/CMakeLists.txt | 4 ++++ src/musredit_qt5/musredit/CMakeLists.txt | 4 ++++ src/musredit_qt6/mupp/CMakeLists.txt | 4 ++++ src/musredit_qt6/musrStep/CMakeLists.txt | 4 ++++ src/musredit_qt6/musrWiz/CMakeLists.txt | 4 ++++ src/musredit_qt6/musredit/CMakeLists.txt | 4 ++++ 11 files changed, 51 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a586e727..d2a22048 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ------------------------------------------------ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 861c5b10..12267f70 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/git_revision.sh b/src/git_revision.sh index 827df694..94984c1a 100755 --- a/src/git_revision.sh +++ b/src/git_revision.sh @@ -1,13 +1,18 @@ #!/bin/bash +# Usage: git_revision.sh +# 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; diff --git a/src/musredit_qt5/mupp/CMakeLists.txt b/src/musredit_qt5/mupp/CMakeLists.txt index bcdbb482..3920404c 100644 --- a/src/musredit_qt5/mupp/CMakeLists.txt +++ b/src/musredit_qt5/mupp/CMakeLists.txt @@ -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} diff --git a/src/musredit_qt5/musrStep/CMakeLists.txt b/src/musredit_qt5/musrStep/CMakeLists.txt index c6f00199..24219df3 100644 --- a/src/musredit_qt5/musrStep/CMakeLists.txt +++ b/src/musredit_qt5/musrStep/CMakeLists.txt @@ -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 diff --git a/src/musredit_qt5/musrWiz/CMakeLists.txt b/src/musredit_qt5/musrWiz/CMakeLists.txt index 3d6a35ba..1b4b9776 100644 --- a/src/musredit_qt5/musrWiz/CMakeLists.txt +++ b/src/musredit_qt5/musrWiz/CMakeLists.txt @@ -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 diff --git a/src/musredit_qt5/musredit/CMakeLists.txt b/src/musredit_qt5/musredit/CMakeLists.txt index 8c287f8f..76683614 100644 --- a/src/musredit_qt5/musredit/CMakeLists.txt +++ b/src/musredit_qt5/musredit/CMakeLists.txt @@ -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 diff --git a/src/musredit_qt6/mupp/CMakeLists.txt b/src/musredit_qt6/mupp/CMakeLists.txt index 6202c328..0c99621a 100644 --- a/src/musredit_qt6/mupp/CMakeLists.txt +++ b/src/musredit_qt6/mupp/CMakeLists.txt @@ -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} diff --git a/src/musredit_qt6/musrStep/CMakeLists.txt b/src/musredit_qt6/musrStep/CMakeLists.txt index b70b517c..f611c3a2 100644 --- a/src/musredit_qt6/musrStep/CMakeLists.txt +++ b/src/musredit_qt6/musrStep/CMakeLists.txt @@ -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 diff --git a/src/musredit_qt6/musrWiz/CMakeLists.txt b/src/musredit_qt6/musrWiz/CMakeLists.txt index 72cd3fa7..fc3c3da1 100644 --- a/src/musredit_qt6/musrWiz/CMakeLists.txt +++ b/src/musredit_qt6/musrWiz/CMakeLists.txt @@ -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 diff --git a/src/musredit_qt6/musredit/CMakeLists.txt b/src/musredit_qt6/musredit/CMakeLists.txt index 08c18eca..a74e3fd4 100644 --- a/src/musredit_qt6/musredit/CMakeLists.txt +++ b/src/musredit_qt6/musredit/CMakeLists.txt @@ -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