-
Notifications
You must be signed in to change notification settings - Fork 13
/
write_compiler_info.cmake
109 lines (98 loc) · 4.6 KB
/
write_compiler_info.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
################################################################################
# This file is part of CMacIonize
# Copyright (C) 2016 Bert Vandenbroucke ([email protected])
#
# CMacIonize is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# CMacIonize is distributed in the hope that it will be useful,
# but WITOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with CMacIonize. If not, see <http://www.gnu.org/licenses/>.
################################################################################
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --dirty
OUTPUT_VARIABLE GIT_BUILD_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(HAVE_WINDOWS)
execute_process(COMMAND WMIC os GET LocalDateTime
OUTPUT_VARIABLE FULL_DATE_BLOCK
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "[^0-9]*([0-9]+)" "\\1" FULL_DATE ${FULL_DATE_BLOCK})
string(REGEX REPLACE "([0-9][0-9][0-9][0-9]).*" "\\1" COMPILATION_TIME_YEAR
${FULL_DATE})
string(REGEX REPLACE "[0-9][0-9][0-9][0-9]([0-9][0-9]).*" "\\1"
COMPILATION_TIME_MONTH ${FULL_DATE})
string(REGEX REPLACE "[0-9][0-9][0-9][0-9][0-9][0-9]([0-9][0-9]).*" "\\1"
COMPILATION_TIME_DAY ${FULL_DATE})
string(REGEX REPLACE "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]([0-9][0-9]).*"
"\\1" COMPILATION_TIME_HOUR ${FULL_DATE})
string(REGEX REPLACE
"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]([0-9][0-9]).*" "\\1"
COMPILATION_TIME_MINUTES ${FULL_DATE})
string(
REGEX REPLACE
"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]([0-9][0-9]).*"
"\\1" COMPILATION_TIME_SECONDS ${FULL_DATE})
set(OS_NAME "Windows")
set(OS_KERNEL_NAME "Windows")
set(OS_KERNEL_RELEASE "Microsoft Windows")
execute_process(COMMAND cmd.exe /c ver
OUTPUT_VARIABLE OS_KERNEL_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE ".*Version (.*)." "\\1" OS_KERNEL_VERSION
${OS_KERNEL_VERSION_STRING})
execute_process(COMMAND WMIC os GET OSArchitecture
OUTPUT_VARIABLE OS_HARDWARE_NAME_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE ".*([0-9][0-9]-bit).*" "\\1" OS_HARDWARE_NAME
${OS_HARDWARE_NAME_STRING})
execute_process(COMMAND hostname
OUTPUT_VARIABLE OS_HOST_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
else(HAVE_WINDOWS)
# We want to get the entire date in one command, to have a single time stamp.
set(DATE_STRING
"+Day: %-d, Month: %-m, Year: %Y, Hour: %-H, Minutes: %-M, Seconds: %-S")
execute_process(COMMAND date ${DATE_STRING}
OUTPUT_VARIABLE FULL_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE)
# We extract the various components and store them in separate variables
string(REGEX REPLACE ".*Day: ([0-9]*).*" "\\1" COMPILATION_TIME_DAY
${FULL_DATE})
string(REGEX REPLACE ".*Month: ([0-9]*).*" "\\1" COMPILATION_TIME_MONTH
${FULL_DATE})
string(REGEX REPLACE ".*Year: ([0-9]*).*" "\\1" COMPILATION_TIME_YEAR
${FULL_DATE})
string(REGEX REPLACE ".*Hour: ([0-9]*).*" "\\1" COMPILATION_TIME_HOUR
${FULL_DATE})
string(REGEX REPLACE ".*Minutes: ([0-9]*).*" "\\1" COMPILATION_TIME_MINUTES
${FULL_DATE})
string(REGEX REPLACE ".*Seconds: ([0-9]*).*" "\\1" COMPILATION_TIME_SECONDS
${FULL_DATE})
# Gather OS information
execute_process(COMMAND uname -o
OUTPUT_VARIABLE OS_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND uname -s
OUTPUT_VARIABLE OS_KERNEL_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND uname -r
OUTPUT_VARIABLE OS_KERNEL_RELEASE
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND uname -v
OUTPUT_VARIABLE OS_KERNEL_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND uname -p
OUTPUT_VARIABLE OS_HARDWARE_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND uname -n
OUTPUT_VARIABLE OS_HOST_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif(HAVE_WINDOWS)
configure_file(${PROJECT_SOURCE_DIR}/src/CompilerInfo.cpp.in
${PROJECT_BINARY_DIR}/src/CompilerInfo.cpp @ONLY)