9
9
zephyr_linker_sources(ROM_START SORT_KEY 0x1bindesc bindesc.ld)
10
10
endif ()
11
11
12
- # Wrapper macro around string(TIMESTAMP ...), that returns the time
13
- # in either local time or UTC, depending on CONFIG_BINDESC_BUILD_TIME_USE_LOCAL_TIME.
14
- macro (get_time out_var format)
15
- if (CONFIG_BINDESC_BUILD_TIME_USE_LOCAL_TIME)
16
- string (TIMESTAMP ${out_var} ${format} )
17
- else ()
18
- string (TIMESTAMP ${out_var} ${format} UTC)
19
- endif ()
20
- endmacro ()
21
-
22
- macro (gen_build_time_int_definition def_name format)
23
- if (CONFIG_BINDESC_${def_name} )
24
- get_time(${def_name} ${format} )
25
- # remove leading zeros so that the output will not be interpreted as octal
26
- math (EXPR ${def_name} ${${def_name} })
27
- zephyr_library_compile_definitions(${def_name} =${${def_name} })
28
- endif ()
29
- endmacro ()
30
-
31
- macro (gen_build_time_str_definition def_name format)
32
- if (CONFIG_BINDESC_${def_name} )
33
- get_time(${def_name} ${${format} })
34
- zephyr_library_compile_definitions(${def_name} ="${${def_name} }" )
35
- endif ()
36
- endmacro ()
37
-
38
12
macro (gen_str_definition def_name value )
39
13
if (CONFIG_BINDESC_${def_name} )
40
14
zephyr_library_compile_definitions(${def_name} ="${value} " )
@@ -43,31 +17,37 @@ endmacro()
43
17
44
18
if (CONFIG_BINDESC_DEFINE_BUILD_TIME)
45
19
zephyr_library_sources(bindesc_build_time.c)
46
- gen_build_time_int_definition(BUILD_TIME_YEAR "%Y" )
47
- gen_build_time_int_definition(BUILD_TIME_MONTH "%m" )
48
- gen_build_time_int_definition(BUILD_TIME_DAY "%d" )
49
- gen_build_time_int_definition(BUILD_TIME_HOUR "%H" )
50
- gen_build_time_int_definition(BUILD_TIME_MINUTE "%M" )
51
- gen_build_time_int_definition(BUILD_TIME_SECOND "%S" )
52
- gen_build_time_int_definition(BUILD_TIME_UNIX "%s" )
53
20
54
- gen_build_time_str_definition(BUILD_DATE_TIME_STRING
55
- CONFIG_BINDESC_BUILD_DATE_TIME_STRING_FORMAT)
56
- gen_build_time_str_definition(BUILD_DATE_STRING
57
- CONFIG_BINDESC_BUILD_DATE_STRING_FORMAT)
58
- gen_build_time_str_definition(BUILD_TIME_STRING
59
- CONFIG_BINDESC_BUILD_TIME_STRING_FORMAT)
21
+ set (gen_header ${PROJECT_BINARY_DIR} /include /generated /bindesc_build_time.h)
22
+
23
+ if (CONFIG_BINDESC_BUILD_TIME_USE_LOCAL_TIME)
24
+ set (BUILD_TIME "LOCAL" )
25
+ else ()
26
+ set (BUILD_TIME "UTC" )
27
+ endif ()
28
+
29
+ set (GEN_COMMAND ${CMAKE_COMMAND}
30
+ -DIN_FILE=${CMAKE_CURRENT_LIST_DIR} /bindesc_build_time.h.in
31
+ -DOUT_FILE=${gen_header}
32
+ -DBUILD_TIME_TYPE="${BUILD_TIME} "
33
+ -DBUILD_DATE_TIME_STRING_FORMAT="${CONFIG_BINDESC_BUILD_DATE_TIME_STRING_FORMAT} "
34
+ -DBUILD_DATE_STRING_FORMAT="${CONFIG_BINDESC_BUILD_DATE_STRING_FORMAT} "
35
+ -DBUILD_TIME_STRING_FORMAT="${CONFIG_BINDESC_BUILD_TIME_STRING_FORMAT} "
36
+ -P ${CMAKE_CURRENT_LIST_DIR} /gen_bindesc_build_time_h.cmake)
60
37
61
38
if (CONFIG_BINDESC_BUILD_TIME_ALWAYS_REBUILD)
62
- # By adding a custom target that invokes cmake,
63
- # CMake is forced to rebuild this target on every build. This is
64
- # done to ensure that the timestamp is always up to date.
65
- add_custom_target (
66
- bindesc_time_force_rebuild
67
- COMMAND ${CMAKE_COMMAND} ${CMAKE_BINARY_DIR}
39
+ add_custom_target (gen_bindesc_build_time
40
+ COMMAND ${GEN_COMMAND}
41
+ BYPRODUCTS ${gen_header}
68
42
)
69
- zephyr_library_add_dependencies(bindesc_time_force_rebuild)
43
+ else ()
44
+ add_custom_command (OUTPUT ${gen_header}
45
+ COMMAND ${GEN_COMMAND}
46
+ )
47
+ add_custom_target (gen_bindesc_build_time DEPENDS ${gen_header} )
70
48
endif ()
49
+
50
+ zephyr_library_add_dependencies(gen_bindesc_build_time)
71
51
endif ()
72
52
73
53
if (CONFIG_BINDESC_DEFINE_VERSION)
0 commit comments