forked from Andersbakken/rtags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PkgInfo.cmake
70 lines (64 loc) · 1.76 KB
/
PkgInfo.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
65
66
67
68
69
70
find_package(Git)
if(GIT_FOUND)
set(USE_GIT 1)
else()
set(USE_GIT 0)
endif()
if(${USE_GIT} EQUAL 1)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
RESULT_VARIABLE GIT_DESCRIBE_RESULT
ERROR_VARIABLE GIT_DESCRIBE_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} config --get user.name
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_CONFIG_USERNAME
RESULT_VARIABLE GIT_CONFIG_RESULT
ERROR_VARIABLE GIT_CONFIG_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
set(GIT_DESCRIBE_RESULT -1)
set(GIT_CONFIG_RESULT -1)
endif()
#
# Deal with version first
#
if(GIT_DESCRIBE_RESULT EQUAL 0)
file(WRITE ${CMAKE_BINARY_DIR}/source/VERSION "${GIT_DESCRIBE_VERSION}")
else()
file(READ ${CMAKE_SOURCE_DIR}/VERSION GIT_DESCRIBE_VERSION)
endif()
string(REGEX REPLACE "v([0-9]*)\\.([0-9]*)(-(.*))?"
"\\1;\\2;\\4" VLIST "${GIT_DESCRIBE_VERSION}")
#message(INFO " vlist ${VLIST}")
list(GET VLIST 0 VERSION_MAJOR)
list(GET VLIST 1 VERSION_MINOR)
list(LENGTH VLIST VLISTLEN)
if(VLISTLEN EQUAL 3)
list(GET VLIST 2 VERSION_EXTRA)
endif()
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}-${VERSION_EXTRA}")
#
# Deal with username
#
string(LENGTH "${GIT_CONFIG_USERNAME}" GIT_CONFIG_USERNAME_LENGTH)
#message(INFO "uname <${GIT_CONFIG_USERNAME}>")
#message(INFO "length ${GIT_CONFIG_USERNAME_LENGTH}")
if(GIT_CONFIG_USERNAME_LENGTH EQUAL 0)
set(GIT_CONFIG_RESULT -1)
endif()
if(GIT_CONFIG_RESULT EQUAL -1)
if(WIN32)
set(PKG_USERNAME "$ENV{USERNAME}")
else()
set(PKG_USERNAME "$ENV{USER}")
endif()
else()
set(PKG_USERNAME "${GIT_CONFIG_USERNAME}")
endif()
#message(INFO "user ${PKG_USERNAME}")