summaryrefslogtreecommitdiff
path: root/src/base/GitInfo.cmake.in
blob: 56a1c5fdb91f9690806fb895ad5de8cd1131f69c (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
36
37
38
39
40
41
42
43
44
45
46
47
48
###############################################################################
# Top contributors (to current version):
#   Aina Niemetz, Mathias Preiner
#
# This file is part of the cvc5 project.
#
# Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
# in the top-level source directory and their institutional affiliations.
# All rights reserved.  See the file COPYING in the top-level source
# directory for licensing information.
# #############################################################################
##

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