diff --git a/git_helper.cmake b/git_helper.cmake index ebee675..860af68 100644 --- a/git_helper.cmake +++ b/git_helper.cmake @@ -1,43 +1,49 @@ -Function ( GitGetVersion GIT_ROOT OUT_MAJOR OUT_MINOR OUT_PATCH OUT_BUILD OUT_HASH ) - - If ( NOT EXISTS "${GIT_ROOT}/.git" ) - Return ( ) - EndIf ( ) - - Message ( "" ) - - # Execute process to get git revisions +# Execute git command and return the output +Function ( GitExecute COMMAND RESULT ) Execute_Process ( COMMAND - bash -c "git -C ${GIT_ROOT} show-ref --tags | egrep 'refs\/tags\/v?[0-9]+\.[0-9]+(\.[0-9]+(\.[0-9]+))' | head -1" + bash -c "${COMMAND}" RESULT_VARIABLE GIT_RET OUTPUT_VARIABLE GIT_REV ERROR_VARIABLE GIT_ERR ) - If ( NOT ${GIT_RET} EQUAL 0 ) - Message ( FATAL_ERROR "Unable to get git revisions! ${GIT_RET}" ) + If ( NOT ${GIT_RET} EQUAL 0 + OR NOT "${GIT_ERR}" STREQUAL "" + OR "${GIT_REV}" STREQUAL "" ) + Message ( FATAL_ERROR "Unable to execute git command (command=${COMMAND} out=${GIT_REV}; err=${GIT_ERR}; ret=${GIT_RET})" ) + EndIf ( ) + Set ( ${RESULT} "${GIT_REV}" PARENT_SCOPE ) +EndFunction ( ) + +# Get the version by reading the git tag +Function ( GitGetVersion GIT_ROOT OUT_MAJOR OUT_MINOR OUT_PATCH OUT_BUILD OUT_HASH OUT_BEHIND OUT_DIRTY ) + + If ( NOT EXISTS "${GIT_ROOT}/.git" ) + Return ( ) EndIf ( ) - If ( "${GIT_REV}" STREQUAL "" ) - Return () - EndIf () + + # Find the latest git tag + GitExecute ( "git describe --tags --abbrev=1 --match v[0-9].[0-9]* HEAD" TAG ) + GitExecute ( "git status -s -uall" DIRTY ) + GitExecute ( "git rev-parse HEAD" HASH ) # Split the git revision string - String ( REPLACE " " ";" SPLIT ${GIT_REV} ) + String ( REGEX REPLACE "^v" "" TAG "${TAG}" ) + String ( REPLACE "-" ";" SPLIT "${TAG}" ) List ( LENGTH SPLIT COUNT ) - If ( NOT ${COUNT} EQUAL 2 ) - Return ( ) + If ( ${COUNT} LESS 2 ) + Message ( FATAL_ERROR "Unable to split git tag into it's sub components: ${TAG}!" ) EndIf ( ) - List ( GET SPLIT 0 HASH ) - List ( GET SPLIT 1 VERSION ) + List ( GET SPLIT 0 VERSION ) + List ( GET SPLIT 1 BEHIND ) # Split the version String ( STRIP "${VERSION}" SPLIT ) - String ( REGEX REPLACE "refs?\/tags?\/v?" "" SPLIT ${SPLIT} ) - String ( REPLACE "." ";" SPLIT ${SPLIT} ) + String ( REPLACE "." ";" SPLIT "${SPLIT}" ) List ( LENGTH SPLIT COUNT ) If ( ${COUNT} LESS 2 ) - Message ( FATAL_ERROR "Unable to parse version string!" ) + Message ( FATAL_ERROR "Unable to split version string: ${VERSION}!" ) EndIf ( ) # major @@ -61,6 +67,17 @@ Function ( GitGetVersion GIT_ROOT OUT_MAJOR OUT_MINOR OUT_PATCH OUT_BUILD OUT_HA EndIf ( ) # hash + String ( STRIP "${HASH}" HASH ) Set ( ${OUT_HASH} ${HASH} PARENT_SCOPE ) + # behind + Set ( ${OUT_BEHIND} ${BEHIND} PARENT_SCOPE ) + + # dirty + If ( DIRTY ) + Set ( ${OUT_DIRTY} 1 PARENT_SCOPE ) + Else ( ) + Set ( ${OUT_DIRTY} 0 PARENT_SCOPE ) + EndIf ( ) + EndFunction ( ) diff --git a/pedantic.cmake b/pedantic.cmake index be2efde..b2f32d5 100644 --- a/pedantic.cmake +++ b/pedantic.cmake @@ -152,7 +152,7 @@ Function ( Pedantic_Apply_Flags_Target TARGET ) ForEach ( I IN LISTS TMP ) Target_Compile_Options ( ${TARGET} ${ARG_VISIBILITY} - $<$:${I}> ) + ${I} ) EndForEach ( ) EndIf ( ) @@ -164,7 +164,7 @@ Function ( Pedantic_Apply_Flags_Target TARGET ) ForEach ( I IN LISTS TMP ) Target_Compile_Options ( ${TARGET} ${ARG_VISIBILITY} - $<$:${I}> ) + ${I} ) EndForEach ( ) EndIf ( )