# Stamps GitInfo.cpp with the SHA of HEAD as it is NOW. Run with `cmake -P` on every build (see the # JFJochGitInfo target in CMakeLists.txt here), so the hash a binary reports is the commit it was # built from, not the one the tree held when it was last configured - a configure-time stamp once # reported a hash seventeen commits stale. configure_file leaves the output untouched when nothing # changed, so this costs a recompile only when HEAD moves. Also included at configure time, so the # file exists for the generator and the SHA prints with the configure output. # A source tree that is not a git checkout of its own - a downloaded tarball, perhaps unpacked inside # some other repository - has no commit to report: the version from VERSION stands alone and the # commit reads "unknown", and the build goes on. SET(GIT_SHA1 "") SET(GIT_DATE "") if (GIT_EXECUTABLE) EXECUTE_PROCESS(COMMAND "${GIT_EXECUTABLE}" rev-parse --show-toplevel WORKING_DIRECTORY "${GITINFO_SOURCE_DIR}" OUTPUT_VARIABLE GIT_TOPLEVEL ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) if (GIT_TOPLEVEL) FILE(REAL_PATH "${GIT_TOPLEVEL}" GIT_TOPLEVEL) endif () FILE(REAL_PATH "${GITINFO_SOURCE_DIR}" GITINFO_SOURCE_REAL) endif () if (GIT_EXECUTABLE AND GIT_TOPLEVEL STREQUAL GITINFO_SOURCE_REAL) # --dirty: a build from uncommitted changes says so in the hash itself EXECUTE_PROCESS(COMMAND "${GIT_EXECUTABLE}" describe --match=NeVeRmAtCh --always --abbrev=8 --dirty WORKING_DIRECTORY "${GITINFO_SOURCE_DIR}" OUTPUT_VARIABLE GIT_SHA1 ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) EXECUTE_PROCESS(COMMAND "${GIT_EXECUTABLE}" log -1 --format=%ad --date=local WORKING_DIRECTORY "${GITINFO_SOURCE_DIR}" OUTPUT_VARIABLE GIT_DATE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) endif () if (NOT GIT_SHA1) SET(GIT_SHA1 "unknown") endif () CONFIGURE_FILE("${GITINFO_TEMPLATE}" "${GITINFO_OUTPUT}" @ONLY)