Skip to content

Commit b156524

Browse files
committed
Require commit ID and tag name via CMake vars if git is not found
On OBS for instance, cmake can be invoked like cmake -DGIT_COMMIT=xxx -DGIT_TAG_NAME=xxx to collect the required information. Fixes probonopd#308
1 parent 296b5e9 commit b156524

File tree

1 file changed

+48
-40
lines changed

1 file changed

+48
-40
lines changed

Diff for: CMakeLists.txt

+48-40
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,59 @@ project(linuxdeployqt)
77

88
find_program(GIT git)
99

10-
# make sure Git revision ID and latest tag is not stored in the CMake cache
11-
# otherwise, one would have to reset the CMake cache on every new commit to make sure the Git commit ID is up to date
12-
unset(GIT_COMMIT CACHE)
13-
unset(GIT_LATEST_TAG CACHE)
14-
1510
if("${GIT}" STREQUAL "GIT-NOTFOUND")
16-
message(FATAL_ERROR "Could not find git")
17-
endif()
11+
message(WARNING "Could not find git, commit and tag info cannot be updated")
1812

19-
# read Git revision ID and latest tag number
20-
execute_process(
21-
COMMAND "${GIT}" rev-parse --short HEAD
22-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
23-
OUTPUT_VARIABLE GIT_COMMIT
24-
OUTPUT_STRIP_TRAILING_WHITESPACE
25-
RESULT_VARIABLE GIT_COMMIT_RESULT
26-
)
27-
if(NOT GIT_COMMIT_RESULT EQUAL 0)
28-
message(FATAL_ERROR "Failed to determine git commit ID")
29-
endif()
30-
mark_as_advanced(GIT_COMMIT GIT_COMMIT_RESULT)
13+
if(NOT GIT_COMMIT)
14+
message(FATAL_ERROR "Commit ID not set, please call with -DGIT_COMMIT=...")
15+
endif()
3116

32-
execute_process(
33-
COMMAND "${GIT}" rev-list --tags --skip=1 --max-count=1
34-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
35-
OUTPUT_VARIABLE GIT_TAG_ID
36-
OUTPUT_STRIP_TRAILING_WHITESPACE
37-
RESULT_VARIABLE GIT_TAG_ID_RESULT
38-
)
39-
if(NOT GIT_TAG_ID_RESULT EQUAL 0)
40-
message(FATAL_ERROR "Failed to determine git tag ID")
41-
endif()
42-
mark_as_advanced(GIT_TAG_ID GIT_TAG_ID_RESULT)
17+
if(NOT GIT_TAG_NAME)
18+
message(FATAL_ERROR "Tag name not set, please call with -DGIT_TAG_NAME=...")
19+
endif()
20+
else()
21+
# make sure Git revision ID and latest tag is not stored in the CMake cache
22+
# otherwise, one would have to reset the CMake cache on every new commit to make sure the Git commit ID is up to date
23+
unset(GIT_COMMIT CACHE)
24+
unset(GIT_LATEST_TAG CACHE)
4325

44-
execute_process(
45-
COMMAND "${GIT}" describe --tags ${GIT_TAG_ID} --abbrev=0
46-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
47-
OUTPUT_VARIABLE GIT_TAG_NAME
48-
OUTPUT_STRIP_TRAILING_WHITESPACE
49-
RESULT_VARIABLE GIT_TAG_NAME_RESULT
50-
)
51-
if(NOT GIT_TAG_NAME_RESULT EQUAL 0)
52-
message(FATAL_ERROR "Failed to determine git tag name")
26+
# read Git revision ID and latest tag number
27+
execute_process(
28+
COMMAND "${GIT}" rev-parse --short HEAD
29+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
30+
OUTPUT_VARIABLE GIT_COMMIT
31+
OUTPUT_STRIP_TRAILING_WHITESPACE
32+
RESULT_VARIABLE GIT_COMMIT_RESULT
33+
)
34+
if(NOT GIT_COMMIT_RESULT EQUAL 0)
35+
message(FATAL_ERROR "Failed to determine git commit ID")
36+
endif()
37+
mark_as_advanced(GIT_COMMIT GIT_COMMIT_RESULT)
38+
39+
execute_process(
40+
COMMAND "${GIT}" rev-list --tags --skip=1 --max-count=1
41+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
42+
OUTPUT_VARIABLE GIT_TAG_ID
43+
OUTPUT_STRIP_TRAILING_WHITESPACE
44+
RESULT_VARIABLE GIT_TAG_ID_RESULT
45+
)
46+
if(NOT GIT_TAG_ID_RESULT EQUAL 0)
47+
message(FATAL_ERROR "Failed to determine git tag ID")
48+
endif()
49+
mark_as_advanced(GIT_TAG_ID GIT_TAG_ID_RESULT)
50+
51+
execute_process(
52+
COMMAND "${GIT}" describe --tags ${GIT_TAG_ID} --abbrev=0
53+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
54+
OUTPUT_VARIABLE GIT_TAG_NAME
55+
OUTPUT_STRIP_TRAILING_WHITESPACE
56+
RESULT_VARIABLE GIT_TAG_NAME_RESULT
57+
)
58+
if(NOT GIT_TAG_NAME_RESULT EQUAL 0)
59+
message(FATAL_ERROR "Failed to determine git tag name")
60+
endif()
61+
mark_as_advanced(GIT_TAG_NAME GIT_TAG_NAME_RESULT)
5362
endif()
54-
mark_as_advanced(GIT_TAG_NAME GIT_TAG_NAME_RESULT)
5563

5664
# set version and build number
5765
set(VERSION 1-alpha)

0 commit comments

Comments
 (0)