diff --git a/cmake/git_helper.cmake b/cmake/git_helper.cmake index e55696e..22ed057 100644 --- a/cmake/git_helper.cmake +++ b/cmake/git_helper.cmake @@ -100,3 +100,21 @@ Function ( GitGetVersion GIT_ROOT OUT_MAJOR OUT_MINOR OUT_PATCH OUT_BUILD OUT_HA EndIf ( ) EndFunction ( ) + +# Get the git hash og the current commit +Function ( GitGetHash GIT_ROOT OUT_HASH ) + + If ( NOT EXISTS "${GIT_ROOT}/.git" ) + Return ( ) + EndIf ( ) + + GitExecute ( "git -C ${CMAKE_CURRENT_SOURCE_DIR} rev-parse HEAD" True HASH SUCCESS ) + If ( NOT ${SUCCESS} ) + Return ( ) + EndIf ( ) + + # hash + String ( STRIP "${HASH}" HASH ) + Set ( ${OUT_HASH} ${HASH} PARENT_SCOPE ) + +EndFunction ( )