summaryrefslogtreecommitdiffstats
path: root/GitVersion.cmake
blob: 527332d4092ba3202979af6522a270a3ce84685e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
find_program(GIT_EXECUTABLE git DOC "path to the git executable")
mark_as_advanced(GIT_EXECUTABLE)

function(git_version RESULT_VAR DIR)
  set(${RESULT_VAR} "" PARENT_SCOPE)
  if(GIT_EXECUTABLE)
    execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty WORKING_DIRECTORY ${DIR} OUTPUT_VARIABLE git_version_OUTPUT ERROR_VARIABLE git_version_ERROR RESULT_VARIABLE git_version_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)

    if(${git_version_RESULT} EQUAL 0)
      set(${RESULT_VAR} "${git_version_OUTPUT}" PARENT_SCOPE)
    endif()
  endif()
endfunction(git_version)