Skip to content

Commit aa0e314

Browse files
pinotreedragotin
authored andcommitted
Extract Git info at build time only if possible
The build system tries to extract some Git build details (e.g. branch and SHA). The problem is that it assumes that both 'git' is installed, and that the sources are in a Git repository: while this is true during a Git build, they are both not true when building from release tarballs (e.g. as done by distributions). Hence, manually search for 'git' and that the current sources are a Git repository: - if both are valid, extract the build details as done so far - if neither is available, still try to use '.tag' for the SHA, setting the value for the branch as well to it
1 parent f2f34b5 commit aa0e314

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

CMakeLists.txt

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,27 @@ set(AKO_PREFIX "KPim6")
2121

2222
message("Akonadi Prefix is ${AKO_PREFIX}")
2323

24-
include(GetGitRevisionDescription)
25-
26-
# set git revision info
27-
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
28-
# if we cannot get it from git, directly try .tag (packages)
29-
# this will work if the tar balls have been properly created
30-
# via git-archive.
31-
if ("${GIT_SHA1}" STREQUAL "GITDIR-NOTFOUND")
24+
find_package(Git QUIET)
25+
if (Git_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
26+
include(GetGitRevisionDescription)
27+
28+
# set git revision info
29+
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
30+
31+
execute_process(
32+
COMMAND git rev-parse --abbrev-ref HEAD
33+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
34+
OUTPUT_VARIABLE GIT_BRANCH
35+
OUTPUT_STRIP_TRAILING_WHITESPACE
36+
)
37+
38+
message(STATUS "Git dynamic information")
39+
message("GIT_SHA1: ${GIT_SHA1}")
40+
message("GIT_BRANCH: ${GIT_BRANCH}")
41+
else()
42+
# if we cannot get it from git, directly try .tag (packages)
43+
# this will work if the tar balls have been properly created
44+
# via git-archive.
3245
if (EXISTS "${CMAKE_SOURCE_DIR}/.tag")
3346
file(READ ${CMAKE_SOURCE_DIR}/.tag sha1_candidate)
3447
string(REPLACE "\n" "" sha1_candidate ${sha1_candidate})
@@ -39,19 +52,9 @@ if ("${GIT_SHA1}" STREQUAL "GITDIR-NOTFOUND")
3952
else()
4053
set (GIT_SHA1 "unknown")
4154
endif()
55+
set(GIT_BRANCH "${GIT_SHA1}")
4256
endif()
4357

44-
message(STATUS "Git dynamic information")
45-
message("GIT_SHA1: ${GIT_SHA1}")
46-
47-
execute_process(
48-
COMMAND git rev-parse --abbrev-ref HEAD
49-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
50-
OUTPUT_VARIABLE GIT_BRANCH
51-
OUTPUT_STRIP_TRAILING_WHITESPACE
52-
)
53-
message("GIT_BRANCH: ${GIT_BRANCH}")
54-
5558
if($ENV{SOURCE_DATE_EPOCH})
5659
set(BUILD_HOST_NAME "reproduciblebuild")
5760
else ()

0 commit comments

Comments
 (0)