diff --git a/code/CMakeModules/GetRevision.cmake b/code/CMakeModules/GetRevision.cmake index dba90c765..94b877438 100644 --- a/code/CMakeModules/GetRevision.cmake +++ b/code/CMakeModules/GetRevision.cmake @@ -72,6 +72,37 @@ IF(EXISTS "${ROOT_DIR}/.hg/") ENDIF() ENDIF() +IF(EXISTS "${ROOT_DIR}/.git/") + FIND_PACKAGE(Git) + + IF(GIT_FOUND) + EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list HEAD --count + WORKING_DIRECTORY ${ROOT_DIR} + RESULT_VARIABLE git_exit_code + OUTPUT_VARIABLE REVISION) + IF(NOT ${git_exit_code} EQUAL 0) + message(WARNING "git rev-list failed, unable to include version.") + ENDIF() + EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD + WORKING_DIRECTORY ${ROOT_DIR} + RESULT_VARIABLE git_exit_code + OUTPUT_VARIABLE CHANGESET) + IF(NOT ${git_exit_code} EQUAL 0) + message(WARNING "git rev-parse failed, unable to include version.") + ENDIF() + EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${ROOT_DIR} + RESULT_VARIABLE git_exit_code + OUTPUT_VARIABLE BRANCH) + IF(NOT ${git_exit_code} EQUAL 0) + message(WARNING "git rev-parse failed, unable to include git branch.") + ENDIF() + STRING(STRIP ${REVISION} REVISION) + STRING(STRIP ${CHANGESET} CHANGESET) + STRING(STRIP ${BRANCH} BRANCH) + ENDIF() +ENDIF() + # if processing exported sources, use "revision" file if exists IF(SOURCE_DIR AND NOT DEFINED REVISION) SET(REVISION_FILE ${SOURCE_DIR}/revision)