-
Notifications
You must be signed in to change notification settings - Fork 2
/
version.cmake
56 lines (49 loc) · 1.4 KB
/
version.cmake
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
49
50
51
52
53
54
55
56
# set the version from VERSION file, and the build commit and date from git repo
# get git version tag
execute_process(
COMMAND git describe --tags --abbrev=0
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_TAG_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
# get version from git tag if available, else fall back to VERSION file
if(GIT_TAG_VERSION)
set(VERSION_NUMBER ${GIT_TAG_VERSION})
message("using version from git tag: ${VERSION_NUMBER}")
else()
file(READ "${CMAKE_SOURCE_DIR}/VERSION" VERSION_NUMBER)
string(STRIP "${VERSION_NUMBER}" VERSION_NUMBER)
set(VERSION_NUMBER "v${VERSION_NUMBER}")
message("using version from VERSION file: ${VERSION_NUMBER}")
endif()
# get git commit hash
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# get git commit date
execute_process(
COMMAND git log -1 --format=%cd --date=short
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# get build date/time
execute_process(
COMMAND date +%y-%m-%d-%T
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE BUILD_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT BUILD_TYPE)
set(BUILD_TYPE "Unknown")
endif()
# output version details to file
configure_file(
"tools/version.hpp.in"
"tools/version.hpp"
@ONLY
)