forked from zephyrproject-rtos/openthread
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
238 lines (189 loc) · 7.23 KB
/
CMakeLists.txt
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
if (CONFIG_NET_L2_OPENTHREAD)
# Invoke OpenThread's external autoconf-based build system.
include(ExternalProject)
# Construct a list of commands to give to ExternalProject_Add()
#
# See https://cmake.org/cmake/help/latest/module/ExternalProject.html
# for documentation on ExternalProject_Add
set(cmd "")
set(ot_name ot)
list(APPEND cmd
${ot_name}
)
set(ot_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/Install/${ot_name})
#--Configure step-------------
if(EXTERNAL_PROJECT_PATH_OPENTHREAD)
set(ot_SOURCE_DIR ${EXTERNAL_PROJECT_PATH_OPENTHREAD})
else()
execute_process(
COMMAND
${WEST} list -f {posixpath} openthread
OUTPUT_VARIABLE ot_SOURCE_DIR
)
# Trim a trailing whitespace.
string(STRIP ${ot_SOURCE_DIR} ot_SOURCE_DIR)
endif()
list(APPEND cmd
SOURCE_DIR ${ot_SOURCE_DIR}
)
# TODO: Can we omit this, does OpenThread need to use install?
# TODO: Move this to host-tools?
find_program(INSTALL install)
# It looks like OpenThread requires a *nix system to build for
# embedded.
#
# https://github.com/openthread/openthread/blob/master/examples/drivers/windows/README.md
# TODO: Use different includes for C and CXX
zephyr_get_include_directories_for_lang_as_string( C includes)
zephyr_get_system_include_directories_for_lang_as_string(C system_includes)
zephyr_get_compile_definitions_for_lang_as_string( C definitions)
zephyr_get_compile_options_for_lang_as_string(C c_options)
zephyr_get_compile_options_for_lang_as_string(CXX cxx_options)
# TODO: What happens if a CFLAG is added after this build script has
# been run?
# TODO: Does OpenThread need all flags, or just some? Should we
# whitelist, or blacklist flags?
# TODO: What is all this? $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
set(exec_prefix zephyr)
# For zephyr-mbedtls-config.h
set(ot_port_path "$ENV{ZEPHYR_BASE}/subsys/net/lib/openthread")
set(commoncflags "-DOPENTHREAD_CONFIG_LOG_LEVEL=${CONFIG_OPENTHREAD_LOG_LEVEL}")
set(commoncflags "${commoncflags} -DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\\\"openthread-core-zephyr-config.h\\\"")
set(commoncflags "${commoncflags} -I${ot_port_path}/platform")
if(CONFIG_OPENTHREAD_COMMISSIONER)
set(commoncflags "${commoncflags} -DOPENTHREAD_CONFIG_COMMISSIONER_ENABLE=1")
endif()
if(CONFIG_OPENTHREAD_JAM_DETECTION)
set(commoncflags "${commoncflags} -DOPENTHREAD_CONFIG_JAM_DETECTION_ENABLE=1")
endif()
if(CONFIG_OPENTHREAD_JOINER)
set(commoncflags "${commoncflags} -DOPENTHREAD_CONFIG_JOINER_ENABLE=1")
endif()
if(CONFIG_OPENTHREAD_DHCP6_CLIENT)
set(commoncflags "${commoncflags} -DOPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE=1")
endif()
if(CONFIG_OPENTHREAD_DHCP6_SERVER)
set(commoncflags "${commoncflags} -DOPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE=1")
endif()
if(CONFIG_OPENTHREAD_DIAG)
set(commoncflags "${commoncflags} -DOPENTHREAD_CONFIG_DIAG_ENABLE=1")
endif()
get_property(RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
set(configure_flags
"INSTALL=${INSTALL} -p"
"CPP=${CMAKE_C_COMPILER} -E" # TODO: Find CPP in toolchain-gcc.cmake and use that instead?
"CC=${RULE_LAUNCH_COMPILE} ${CMAKE_C_COMPILER}"
"CXX=${RULE_LAUNCH_COMPILE} ${CMAKE_CXX_COMPILER}"
OBJC="" # TODO: Omit this?
"OBJCXX=${OBJCXX}" # TODO: Omit this?
"AR=${CMAKE_AR}"
"RANLIB=${CMAKE_RANLILB}"
"NM=${CROSS_COMPILE}nm" # TODO: Find NM in toolchain-gcc.cmake and use that instead?
"STRIP=${CMAKE_STRIP}"
"CPPFLAGS=${definitions} ${commoncflags} ${includes} ${system_includes}"
"CFLAGS=${c_options} ${commoncflags} ${includes} ${system_includes}"
"CXXFLAGS=${cxx_options} ${commoncflags} ${includes} ${system_includes}" # TODO: Do we need includes here?
LDFLAGS="" # TODO: What does a networking stack need to use the linker for?
--host=arm-none-eabi
--prefix=/
--exec-prefix=/${exec_prefix}
--target=arm-none-eabi # TODO: Is Kconfig expressing that OT is ARM-only?
--enable-no-executables-hack
--disable-docs
--with-platform-info=zephyr
--enable-builtin-mbedtls=no
)
# TODO: Simplify
set(ZEPHYR_MBEDTLS_CPPFLAGS "${ZEPHYR_MBEDTLS_CPPFLAGS} -DMBEDTLS_CONFIG_FILE='\"${CONFIG_MBEDTLS_CFG_FILE}\"'")
set(ZEPHYR_MBEDTLS_CPPFLAGS "${ZEPHYR_MBEDTLS_CPPFLAGS} -I$ENV{ZEPHYR_BASE}/../modules/crypto/mbedtls/include")
set(ZEPHYR_MBEDTLS_CPPFLAGS "${ZEPHYR_MBEDTLS_CPPFLAGS} -I$ENV{ZEPHYR_BASE}/../modules/crypto/mbedtls/configs")
list(APPEND configure_flags
"MBEDTLS_CPPFLAGS=${ZEPHYR_MBEDTLS_CPPFLAGS}"
)
if(CONFIG_OPENTHREAD_FTD)
list(APPEND configure_flags
--enable-ftd
)
elseif(CONFIG_OPENTHREAD_MTD)
list(APPEND configure_flags
--enable-mtd
)
endif()
if(CONFIG_OPENTHREAD_SHELL)
list(APPEND configure_flags
--enable-cli
)
endif()
list(APPEND cmd
CONFIGURE_COMMAND ${ot_SOURCE_DIR}/configure ${configure_flags}
)
#--Build step-----------------
# Invoke OpenThread's build system from the root of it's source
# directory
# TODO: Support out-of-source builds
set(ot_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/build)
list(APPEND cmd
BINARY_DIR ${ot_BINARY_DIR}
INSTALL_DIR ${ot_INSTALL_DIR}
)
set(make_flags
-j99 # TODO: Why 99?
--no-print-directory
)
list(APPEND cmd
BUILD_COMMAND make ${make_flags} all
INSTALL_COMMAND make ${make_flags} DESTDIR=${ot_INSTALL_DIR} install
)
# TODO: Find out how to make this work.
set(ot_include_dir ${ot_SOURCE_DIR}/include)
set(ot_generated_dir ${ot_BINARY_DIR}/include)
# For platform.h
set(ot_platforms_dir ${ot_SOURCE_DIR}/examples/platforms)
# TODO: Is this only needed by alarm.c?
zephyr_system_include_directories(${ot_include_dir})
zephyr_system_include_directories(${ot_generated_dir})
zephyr_system_include_directories(${ot_platforms_dir})
# TODO: Why doesn't app get this path from the above function call?
target_include_directories(app SYSTEM PRIVATE ${ot_include_dir})
target_include_directories(app SYSTEM PRIVATE ${ot_generated_dir})
target_include_directories(app SYSTEM PRIVATE ${ot_platforms_dir})
#set_target_properties(ot_lib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ot_include_dir})
zephyr_include_directories(${ot_include_dir})
zephyr_include_directories(${ot_generated_dir})
zephyr_include_directories(${ot_platforms_dir})
# Determine which libs should be linked in
set(ot_libs
openthread-platform-utils
)
if(CONFIG_OPENTHREAD_FTD)
list(APPEND ot_libs openthread-ftd)
set(cli_lib openthread-cli-ftd)
elseif(CONFIG_OPENTHREAD_MTD)
list(APPEND ot_libs openthread-mtd)
set(cli_lib openthread-cli-mtd)
endif()
if(CONFIG_OPENTHREAD_SHELL)
list(APPEND ot_libs ${cli_lib})
endif()
foreach(ot_lib ${ot_libs})
set(build_byproducts ${build_byproducts} ${ot_INSTALL_DIR}/${exec_prefix}/lib/lib${ot_lib}.a)
endforeach()
list(APPEND cmd
BUILD_BYPRODUCTS ${build_byproducts}
)
ExternalProject_Add(${cmd})
ExternalProject_Add_Step(
${ot_name} bootstrap # Names of project and custom step
COMMAND ./bootstrap # Command line invoked by this step
COMMENT "bootstrapping..." # Text printed when step executes
DEPENDEES download # Steps on which this step depends
DEPENDERS configure # Steps that depend on this step
WORKING_DIRECTORY ${ot_SOURCE_DIR}
)
# Create wrapper CMake libraries
foreach(ot_lib ${ot_libs})
zephyr_library_import(${ot_lib}
${ot_INSTALL_DIR}/${exec_prefix}/lib/lib${ot_lib}.a
)
endforeach()
endif()