forked from cryptonotefoundation/cryptonotewallet
-
Notifications
You must be signed in to change notification settings - Fork 38
/
cn_version.cmake
64 lines (59 loc) · 2.38 KB
/
cn_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
57
58
59
60
61
62
63
64
# Read project version from git tag.
cmake_policy(SET CMP0007 OLD)
find_package(Git)
message(STATUS "Found Git: ${GIT_FOUND}")
if(GIT_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --abbrev=0 --match "v*"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cryptonote/"
RESULT_VARIABLE PROJECT_GIT_RESULT
OUTPUT_VARIABLE PROJECT_GIT_TAG
ERROR_VARIABLE PROJECT_GIT_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)
if(NOT PROJECT_GIT_RESULT EQUAL 0)
set(PROJECT_GIT_TAG "0.0.0")
set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 0)
message(WARNING "Failed to execute Git: ${PROJECT_GIT_ERROR}")
else()
string(REPLACE "v." "" PROJECT_GIT_TAG ${PROJECT_GIT_TAG})
# Parse and split a version number into separate components
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" "\\1;\\2;\\3;\\4" VERSION_MATCHES ${PROJECT_GIT_TAG})
list(GET VERSION_MATCHES 0 version_major)
set(PROJECT_VERSION_MAJOR ${version_major})
list(GET VERSION_MATCHES 1 version_minor)
set(PROJECT_VERSION_MINOR ${version_minor})
list(GET VERSION_MATCHES 2 version_patch)
set(PROJECT_VERSION_PATCH ${version_patch})
message(STATUS "Core git tag: ${PROJECT_GIT_TAG}")
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cryptonote/"
RESULT_VARIABLE PROJECT_GIT_RESULT
OUTPUT_VARIABLE PROJECT_GIT_COMMIT_ID
ERROR_VARIABLE PROJECT_GIT_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)
if(NOT PROJECT_GIT_RESULT EQUAL 0)
set(PROJECT_GIT_COMMIT_ID "unknown")
message(WARNING "Failed to execute Git: ${PROJECT_GIT_ERROR}")
else()
message(STATUS "Git commit ID: ${PROJECT_GIT_COMMIT_ID}")
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-list --count HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cryptonote/"
OUTPUT_VARIABLE PROJECT_GIT_COMMIT_COUNT
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT PROJECT_GIT_RESULT EQUAL 0)
message(WARNING "Failed to execute Git: ${PROJECT_GIT_ERROR}")
set(PROJECT_VERSION_REV 0)
else()
message(STATUS "Git commit count: ${PROJECT_GIT_COMMIT_COUNT}")
set(PROJECT_VERSION_REV ${PROJECT_GIT_COMMIT_COUNT})
endif()
configure_file("cryptonote/src/version.h.in" "version.h")
endif()