benchmark/cmake/GetGitVersion.cmake

37 lines
859 B
CMake
Raw Normal View History

2014-08-01 14:00:43 +00:00
# - Returns a version string from Git tags
#
# This function inspects the annotated git tags for the project and returns a string
# into a CMake variable
#
# get_git_version(<var>)
#
# - Example
#
# include(GetGitVersion)
# get_git_version(GIT_VERSION)
#
2015-10-02 15:05:58 +00:00
# Requires CMake 2.8.11+
find_package(Git)
2014-08-01 14:00:43 +00:00
if(__get_git_version)
return()
endif()
set(__get_git_version INCLUDED)
function(get_git_version var)
2015-10-02 15:05:58 +00:00
if(GIT_EXECUTABLE)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --match "v[0-9]*.[0-9]*.[0-9]*" --abbrev=8 --dirty
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
2015-10-02 15:05:58 +00:00
RESULT_VARIABLE status
OUTPUT_VARIABLE GIT_VERSION
2015-10-02 15:05:58 +00:00
ERROR_QUIET)
if(status)
set(GIT_VERSION "v0.0.0")
endif()
2014-08-01 14:00:43 +00:00
else()
set(GIT_VERSION "v0.0.0")
2014-08-01 14:00:43 +00:00
endif()
set(${var} ${GIT_VERSION} PARENT_SCOPE)
endfunction()