File: GetGitVersion.cmake

package info (click to toggle)
benchmark 1.9.5-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,820 kB
  • sloc: cpp: 14,339; python: 2,399; ansic: 38; sh: 28; makefile: 14
file content (36 lines) | stat: -rw-r--r-- 859 bytes parent folder | download | duplicates (21)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# - 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)
#
# Requires CMake 2.8.11+
find_package(Git)

if(__get_git_version)
  return()
endif()
set(__get_git_version INCLUDED)

function(get_git_version var)
  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}
          RESULT_VARIABLE status
          OUTPUT_VARIABLE GIT_VERSION
          ERROR_QUIET)
      if(status)
          set(GIT_VERSION "v0.0.0")
      endif()
  else()
      set(GIT_VERSION "v0.0.0")
  endif()

  set(${var} ${GIT_VERSION} PARENT_SCOPE)
endfunction()