1# SPDX-License-Identifier: Apache-2.0
2
3cmake_minimum_required(VERSION 3.20.0)
4
5# Wrapper macro around string(TIMESTAMP ...), that returns the time
6# in either local time or UTC, depending on CONFIG_BINDESC_BUILD_TIME_USE_LOCAL_TIME.
7macro(get_time out_var format)
8  if(BUILD_TIME_TYPE STREQUAL LOCAL)
9    string(TIMESTAMP ${out_var} ${format})
10  else()
11    string(TIMESTAMP ${out_var} ${format} UTC)
12  endif()
13endmacro()
14
15macro(gen_build_time_int_definition def_name format)
16  get_time(${def_name} ${format})
17  # remove leading zeros so that the output will not be interpreted as octal
18  math(EXPR ${def_name} ${${def_name}})
19endmacro()
20
21macro(gen_build_time_str_definition def_name format)
22  get_time(${def_name} ${${format}})
23endmacro()
24
25gen_build_time_int_definition(BUILD_TIME_YEAR "%Y")
26gen_build_time_int_definition(BUILD_TIME_MONTH "%m")
27gen_build_time_int_definition(BUILD_TIME_DAY "%d")
28gen_build_time_int_definition(BUILD_TIME_HOUR "%H")
29gen_build_time_int_definition(BUILD_TIME_MINUTE "%M")
30gen_build_time_int_definition(BUILD_TIME_SECOND "%S")
31gen_build_time_int_definition(BUILD_TIME_UNIX "%s")
32
33gen_build_time_str_definition(BUILD_DATE_TIME_STRING BUILD_DATE_TIME_STRING_FORMAT)
34gen_build_time_str_definition(BUILD_DATE_STRING BUILD_DATE_STRING_FORMAT)
35gen_build_time_str_definition(BUILD_TIME_STRING BUILD_TIME_STRING_FORMAT)
36
37file(READ ${IN_FILE} content)
38string(CONFIGURE "${content}" content)
39file(WRITE ${OUT_FILE} "${content}")
40