summaryrefslogtreecommitdiffstats
path: root/Source/CMakeVersionSource.cmake
blob: 4f22ded7a1de3776f4543061556baa028e57e88a (plain)
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
# Try to identify the current development source version.
set(CMake_VERSION_SOURCE "")
if(EXISTS ${CMake_SOURCE_DIR}/.git/HEAD)
  find_program(GIT_EXECUTABLE NAMES git git.cmd)
  mark_as_advanced(GIT_EXECUTABLE)
  if(GIT_EXECUTABLE)
    execute_process(
      COMMAND ${GIT_EXECUTABLE} rev-parse --verify -q --short=4 HEAD
      OUTPUT_VARIABLE head
      OUTPUT_STRIP_TRAILING_WHITESPACE
      WORKING_DIRECTORY ${CMake_SOURCE_DIR}
      )
    if(head)
      set(CMake_VERSION_SOURCE "g${head}")
      execute_process(
        COMMAND ${GIT_EXECUTABLE} update-index -q --refresh
        WORKING_DIRECTORY ${CMake_SOURCE_DIR}
        )
      execute_process(
        COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD --
        OUTPUT_VARIABLE dirty
        OUTPUT_STRIP_TRAILING_WHITESPACE
        WORKING_DIRECTORY ${CMake_SOURCE_DIR}
        )
      if(dirty)
        set(CMake_VERSION_IS_DIRTY 1)
      else()
        set(CMake_VERSION_IS_DIRTY 0)
      endif()
    endif()
  endif()
endif()