@@ -75,4 +75,43 @@ function(set_git_info)
7575 message (STATUS "git branch: ${GIT_BRANCH} " )
7676endfunction ()
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+
78117include (packaging)
0 commit comments