diff options
Diffstat (limited to 'cmake/modules')
-rw-r--r-- | cmake/modules/GitDescribe.cmake | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cmake/modules/GitDescribe.cmake b/cmake/modules/GitDescribe.cmake new file mode 100644 index 0000000..043f8c0 --- /dev/null +++ b/cmake/modules/GitDescribe.cmake @@ -0,0 +1,28 @@ +function(git_describe VAR) + set(VAR ${ARGV0}) + execute_process( + COMMAND git describe --tags HEAD + WORK_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE DESCRIBE_RESULT + OUTPUT_VARIABLE DESCRIBE_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message(STATUS "describe" " " ${DESCRIBE_RESULT} " " ${DESCRIBE_OUTPUT}) + if(NOT DESCRIBE_RESULT) + set(${VAR} ${DESCRIBE_OUTPUT} PARENT_SCOPE) + else() + execute_process( + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE PARSE_RESULT + OUTPUT_VARIABLE PARSE_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message(STATUS "rev-parse" " " ${PARSE_RESULT} " " ${PARSE_OUTPUT}) + if(NOT PARSE_RESULT) + set(${VAR} "Unknown-g${PARSE_OUTPUT}" PARENT_SCOPE) + else() + set(${VAR} "Unknown" PARENT_SCOPE) + endif() + endif() +endfunction() |