From e59928a3a9c885297fd9aec309a39c8665c3ad59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20N=C3=B6ske?= Date: Thu, 5 Dec 2019 11:05:44 +0100 Subject: [PATCH] * Added git helper to get commit hash only --- cmake/git_helper.cmake | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 ( )