summaryrefslogtreecommitdiff
path: root/src/base/GitInfo.cmake.in
blob: 2d02095dd85b42b5e54477f1cd0279251c713a44 (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
33
34
35
set(GIT_BUILD "false")
set(GIT_IS_DIRTY "false")
set(GIT_SHA1 "")
set(GIT_BRANCH "")

if(GIT_FOUND)
  # Get current git branch, result is != 0 if this is not a git repository
  execute_process(
    COMMAND @GIT_EXECUTABLE@ -C @PROJECT_SOURCE_DIR@ rev-parse --abbrev-ref HEAD
    RESULT_VARIABLE GIT_RESULT
    OUTPUT_VARIABLE GIT_BRANCH
    OUTPUT_STRIP_TRAILING_WHITESPACE
  )
  if("${GIT_RESULT}" STREQUAL "0")
    set(GIT_BUILD "true")
    # Extract sha1 of HEAD
    execute_process(
      COMMAND @GIT_EXECUTABLE@ -C @PROJECT_SOURCE_DIR@ rev-parse HEAD
      OUTPUT_VARIABLE GIT_SHA1
      OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    # Result is != 0 if worktree is dirty
    # Note: git diff HEAD shows both staged and unstaged changes.
    execute_process(
      COMMAND @GIT_EXECUTABLE@ -C @PROJECT_SOURCE_DIR@ diff HEAD --quiet
      RESULT_VARIABLE GIT_RESULT
    )
    if(NOT "${GIT_RESULT}" STREQUAL "0")
      set(GIT_IS_DIRTY "true")
    endif()
  endif()
endif()

configure_file(
  @CMAKE_CURRENT_SOURCE_DIR@/git_versioninfo.cpp.in git_versioninfo.cpp)
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback