[MIPS GlobalISel] Select MSA vector generic and builtin add
[llvm-complete.git] / utils / benchmark / cmake / GetGitVersion.cmake
blob88cebe3a1caac022b39199870c09d8804d45409b
1 # - Returns a version string from Git tags
3 # This function inspects the annotated git tags for the project and returns a string
4 # into a CMake variable
6 #  get_git_version(<var>)
8 # - Example
10 # include(GetGitVersion)
11 # get_git_version(GIT_VERSION)
13 # Requires CMake 2.8.11+
14 find_package(Git)
16 if(__get_git_version)
17   return()
18 endif()
19 set(__get_git_version INCLUDED)
21 function(get_git_version var)
22   if(GIT_EXECUTABLE)
23       execute_process(COMMAND ${GIT_EXECUTABLE} describe --match "v[0-9]*.[0-9]*.[0-9]*" --abbrev=8
24           WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
25           RESULT_VARIABLE status
26           OUTPUT_VARIABLE GIT_VERSION
27           ERROR_QUIET)
28       if(${status})
29           set(GIT_VERSION "v0.0.0")
30       else()
31           string(STRIP ${GIT_VERSION} GIT_VERSION)
32           string(REGEX REPLACE "-[0-9]+-g" "-" GIT_VERSION ${GIT_VERSION})
33       endif()
35       # Work out if the repository is dirty
36       execute_process(COMMAND ${GIT_EXECUTABLE} update-index -q --refresh
37           WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
38           OUTPUT_QUIET
39           ERROR_QUIET)
40       execute_process(COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD --
41           WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
42           OUTPUT_VARIABLE GIT_DIFF_INDEX
43           ERROR_QUIET)
44       string(COMPARE NOTEQUAL "${GIT_DIFF_INDEX}" "" GIT_DIRTY)
45       if (${GIT_DIRTY})
46           set(GIT_VERSION "${GIT_VERSION}-dirty")
47       endif()
48   else()
49       set(GIT_VERSION "v0.0.0")
50   endif()
52   message("-- git Version: ${GIT_VERSION}")
53   set(${var} ${GIT_VERSION} PARENT_SCOPE)
54 endfunction()