Skip to content

Commit a2e6f06

Browse files
committed
CMake: added XRAY build ID calculation
This was ported to CMake from C++
1 parent 046c287 commit a2e6f06

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
3838

3939
include(utils)
4040

41+
calculate_xray_build_id(XRAY_BUILD_ID)
42+
message(STATUS "XRAY_BUILD_ID: ${XRAY_BUILD_ID}")
43+
4144
set_git_info()
4245

4346
# Output all libraries and executable to one folder

cmake/utils.cmake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,43 @@ function(set_git_info)
7575
message(STATUS "git branch: ${GIT_BRANCH}")
7676
endfunction()
7777

78+
function(calculate_xray_build_id output)
79+
set(XRAY_START_DAY 31)
80+
set(XRAY_START_MONTH 1)
81+
set(XRAY_START_YEAR 1999)
82+
83+
set(DAYS_IN_MONTH 0 31 28 31 30 31 30 31 31 30 31 30 31) # first is dummy
84+
85+
# Acquire timestamp in "date month year" format
86+
string(TIMESTAMP current_date "%d %m %Y")
87+
88+
# Transform string into a list, then extract 3 separate variables
89+
string(REPLACE " " ";" current_date_list ${current_date})
90+
list(GET current_date_list 0 CURRENT_DATE_DAY)
91+
list(GET current_date_list 1 CURRENT_DATE_MONTH)
92+
list(GET current_date_list 2 CURRENT_DATE_YEAR)
93+
94+
# Calculate XRAY build ID
95+
math(EXPR build_id "(${CURRENT_DATE_YEAR} - ${XRAY_START_YEAR}) * 365 + ${CURRENT_DATE_DAY} - ${XRAY_START_DAY}")
96+
97+
set(it 1)
98+
while(it LESS CURRENT_DATE_MONTH)
99+
list(GET DAYS_IN_MONTH ${it} days)
100+
math(EXPR build_id "${build_id} + ${days}")
101+
102+
math(EXPR it "${it} + 1")
103+
endwhile()
104+
105+
set(it 1)
106+
while(it LESS XRAY_START_MONTH)
107+
list(GET DAYS_IN_MONTH ${it} days)
108+
math(EXPR build_id "${build_id} - ${days}")
109+
110+
math(EXPR it "${it} + 1")
111+
endwhile()
112+
113+
# Set requested variable
114+
set(${output} ${build_id} PARENT_SCOPE)
115+
endfunction()
116+
78117
include(packaging)

0 commit comments

Comments
 (0)