set(CMLIB_GIT_REV "N/A") set(CMLIB_GIT_DIFF "") set(CMLIB_GIT_TAG "N/A") set(CMLIB_GIT_BRANCH "N/A") find_program(GIT_EXECUTABLE git) if(GIT_EXECUTABLE) execute_process(COMMAND git log --pretty=format:'%h' -n 1 OUTPUT_VARIABLE CMLIB_GIT_REV ERROR_QUIET) # Check whether we got any revision (which isn't # always the case, e.g. when someone downloaded a zip # file from Github instead of a checkout) if(NOT "${CMLIB_GIT_REV}" STREQUAL "") execute_process(COMMAND bash -c "git diff --quiet --exit-code || echo +" OUTPUT_VARIABLE CMLIB_GIT_DIFF) execute_process(COMMAND git describe --exact-match --tags OUTPUT_VARIABLE CMLIB_GIT_TAG ERROR_QUIET) execute_process(COMMAND git rev-parse --abbrev-ref HEAD OUTPUT_VARIABLE CMLIB_GIT_BRANCH) string(STRIP "${CMLIB_GIT_REV}" CMLIB_GIT_REV) string(SUBSTRING "${CMLIB_GIT_REV}" 1 7 CMLIB_GIT_REV) string(STRIP "${CMLIB_GIT_DIFF}" CMLIB_GIT_DIFF) string(STRIP "${CMLIB_GIT_TAG}" CMLIB_GIT_TAG) string(STRIP "${CMLIB_GIT_BRANCH}" CMLIB_GIT_BRANCH) endif() endif() configure_file(${CMLIB_MODULE_DIR}/hpp/cmlib_git_version.hpp.in ${CMLIB_GIT_VERSION_FILE})