Fix cmake when build directory not child of source directory

When the build directory was not a child of the source directory
fetching the git information about the current commit would fail
leading to this information not being included in the executable
which in turn resulted in failing tests.
This commit is contained in:
Sven Klemm 2022-08-02 18:42:57 +02:00 committed by Sven Klemm
parent d639cd8985
commit bbfdcaccd5
3 changed files with 4 additions and 1 deletions

View File

@ -640,7 +640,6 @@ add_custom_target(licensecheck
if(CODECOVERAGE)
add_subdirectory(codecov)
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E remove ${GITREV_TMP})
if(IS_DIRECTORY ${PROJECT_SOURCE_DIR}/.git)
configure_file(${PROJECT_SOURCE_DIR}/scripts/githooks/commit_msg.py
${PROJECT_SOURCE_DIR}/.git/hooks/commit-msg COPYONLY)

View File

@ -69,6 +69,7 @@ add_custom_target(
gitcheck
COMMAND
${CMAKE_COMMAND} "-DGIT_FOUND=${GIT_FOUND}"
"-DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
"-DGIT_EXECUTABLE=${GIT_EXECUTABLE}"
"-DINPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/gitcommit.h.in"
"-DOUTPUT_FILE=${GITREV_TMP}" -P ${CMAKE_CURRENT_SOURCE_DIR}/gitcommit.cmake

View File

@ -7,6 +7,7 @@ if(GIT_FOUND)
# also add some additional information if we are not on the tag.
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --dirty --always --tags
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE EXT_GIT_COMMIT_TAG
RESULT_VARIABLE _describe_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE)
@ -15,12 +16,14 @@ if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE EXT_GIT_COMMIT_HASH
WORKING_DIRECTORY ${SOURCE_DIR}
RESULT_VARIABLE _revparse_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Fetch the date of the head commit
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%cI
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE EXT_GIT_COMMIT_TIME
RESULT_VARIABLE _log_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE)