-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathzephyrbt-from-behaviourtreecpp-xml.cmake
More file actions
145 lines (126 loc) · 4.57 KB
/
zephyrbt-from-behaviourtreecpp-xml.cmake
File metadata and controls
145 lines (126 loc) · 4.57 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright (c) 2024-2026 O.S. Systems Software LTDA.
# Copyright (c) 2024-2026 Freedom Veiculos Eletricos
# SPDX-License-Identifier: Apache-2.0
include(CheckIncludeFile)
function(zephyrbt_define_from_behaviourtreecpp_xml
target # The current target used to add the generated files
input_file # The behaviour tree input file
output_inc # Output directory of the generated header
output_src # Output directory of the generated sources
stack_size # The amount of RAM used to run the BT
thread_prio # The Thread Priority
thread_yield # The Thread yield option [ True or False ]
)
get_filename_component(zephyrbt_name ${input_file} NAME_WE [CACHE])
get_filename_component(input_file ${input_file} ABSOLUTE)
get_filename_component(output_inc ${output_inc} ABSOLUTE)
get_filename_component(output_src ${output_src} ABSOLUTE)
set(zephyrbt_target "${target}_${zephyrbt_name}")
set(zephyrbt_inc_file "${output_inc}/${zephyrbt_name}.h")
set(zephyrbt_data_file "${output_src}/${zephyrbt_name}_data.c")
set(zephyrbt_stub_file "${output_src}/${zephyrbt_name}_stub.c")
set(zephyrbt_lua_file "${output_src}/${zephyrbt_name}_gen.lua")
file(GLOB_RECURSE zephyrbt_user_include ${CMAKE_CURRENT_SOURCE_DIR}/include/zephyrbt_user.h)
string(LENGTH "${zephyrbt_user_include}" zephyrbt_user_include_valid)
if(${zephyrbt_user_include_valid} GREATER 0)
set(zephyrbt_user_include_file "-u True")
else()
set(zephyrbt_user_include_file "")
endif()
if(${CONFIG_ZEPHYR_BEHAVIOUR_TREE_ALLOW_YIELD})
if(${thread_yield})
set(zephyrbt_thread_yield "-y 1")
else()
set(zephyrbt_thread_yield "-y 0")
endif()
else()
set(zephyrbt_thread_yield "-y 2")
endif()
add_custom_command(
OUTPUT ${zephyrbt_inc_file}
${zephyrbt_data_file}
${zephyrbt_stub_file}
${zephyrbt_lua_file}
DEPENDS ${input_file}
COMMAND ${PYTHON_EXECUTABLE}
${ZEPHYR_ZEPHYRBT_MODULE_DIR}/scripts/generate-zephyrbt-from-behaviourtreecpp-xml
-i ${input_file}
-oi ${zephyrbt_inc_file}
-os ${zephyrbt_data_file}
-ot ${zephyrbt_stub_file}
-s ${stack_size}
-p ${thread_prio}
${zephyrbt_thread_yield}
${zephyrbt_user_include_file}
)
# Embed the generated .lua file as a C string header
# using lua_zephyr's luaz_gen.py script.
if(CONFIG_ZEPHYR_BEHAVIOUR_TREE_LUA_CONDITIONS)
set(zephyrbt_lua_hdr
"${output_inc}/${zephyrbt_name}_gen_lua_script.h")
set(luaz_gen_script
"${ZEPHYR_LUA_MODULE_DIR}/scripts/luaz_gen.py")
set(luaz_template
"${ZEPHYR_LUA_MODULE_DIR}/templates/lua_template.h.in")
add_custom_command(
OUTPUT ${zephyrbt_lua_hdr}
DEPENDS ${zephyrbt_lua_file}
COMMAND ${PYTHON_EXECUTABLE} ${luaz_gen_script}
--mode source
--template ${luaz_template}
--output ${zephyrbt_lua_hdr}
--name "${zephyrbt_name}_gen"
${zephyrbt_lua_file}
COMMENT "Embedding ${zephyrbt_name}_gen.lua"
)
add_custom_target(${zephyrbt_target}_lua
ALL
DEPENDS ${zephyrbt_lua_hdr}
)
add_dependencies(${target} ${zephyrbt_target}_lua)
endif()
add_custom_target(${zephyrbt_target}
ALL
DEPENDS ${input_file} ${zephyrbt_user_include}
)
target_include_directories(${target} PRIVATE
${output_inc}
)
target_sources(${target} PRIVATE
${zephyrbt_data_file}
${zephyrbt_stub_file}
)
endfunction()
# zephyrbt_add_lua_file(target, lua_file)
#
# Embed a user .lua file as a C string header for loading
# as a strong override before the generated weak conditions.
# The header provides const char {name}_lua_script[].
function(zephyrbt_add_lua_file target lua_file)
cmake_path(GET lua_file FILENAME _fname)
cmake_path(REMOVE_EXTENSION _fname OUTPUT_VARIABLE _name)
set(_lua_src "${CMAKE_CURRENT_SOURCE_DIR}/${lua_file}")
set(_lua_hdr
"${CMAKE_CURRENT_BINARY_DIR}/include/${_name}_lua_script.h")
set(luaz_gen_script
"${ZEPHYR_LUA_MODULE_DIR}/scripts/luaz_gen.py")
set(luaz_template
"${ZEPHYR_LUA_MODULE_DIR}/templates/lua_template.h.in")
add_custom_command(
OUTPUT ${_lua_hdr}
DEPENDS ${_lua_src}
COMMAND ${PYTHON_EXECUTABLE} ${luaz_gen_script}
--mode source
--template ${luaz_template}
--output ${_lua_hdr}
--name "${_name}"
${_lua_src}
COMMENT "Embedding ${_name}.lua"
)
add_custom_target(${_name}_lua_header ALL
DEPENDS ${_lua_hdr})
add_dependencies(${target} ${_name}_lua_header)
target_include_directories(${target} PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/include
)
endfunction()