px4_add_board.cmake
9.73 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
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
############################################################################
#
# Copyright (c) 2018 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
#=============================================================================
#
# px4_add_board
#
# This function creates a PX4 board.
#
# Usage:
# px4_add_board(
# PLATFORM <string>
# VENDOR <string>
# MODEL <string>
# [ LABEL <string> ]
# [ TOOLCHAIN <string> ]
# [ ARCHITECTURE <string> ]
# [ ROMFSROOT <string> ]
# [ BUILD_BOOTLOADER ]
# [ IO <string> ]
# [ UAVCAN_INTERFACES <string> ]
# [ UAVCAN_PERIPHERALS <list> ]
# [ DRIVERS <list> ]
# [ MODULES <list> ]
# [ SYSTEMCMDS <list> ]
# [ EXAMPLES <list> ]
# [ SERIAL_PORTS <list> ]
# [ CONSTRAINED_FLASH ]
# [ CONSTRAINED_MEMORY ]
# [ TESTING ]
# [ LINKER_PREFIX <string> ]
# [ EMBEDDED_METADATA <string> ]
# [ ETHERNET ]
# )
#
# Input:
# PLATFORM : PX4 platform name (posix, nuttx, qurt)
# VENDOR : name of board vendor/manufacturer/brand/etc
# MODEL : name of board model
# LABEL : optional label, set to default if not specified
# TOOLCHAIN : cmake toolchain
# ARCHITECTURE : name of the CPU CMake is building for (used by the toolchain)
# ROMFSROOT : relative path to the ROMFS root directory
# BUILD_BOOTLOADER : flag to enable building and including the bootloader config
# IO : name of IO board to be built and included in the ROMFS (requires a valid ROMFSROOT)
# UAVCAN_INTERFACES : number of interfaces for UAVCAN
# UAVCAN_PERIPHERALS : list of UAVCAN peripheral firmware to build and embed
# DRIVERS : list of drivers to build for this board (relative to src/drivers)
# MODULES : list of modules to build for this board (relative to src/modules)
# SYSTEMCMDS : list of system commands to build for this board (relative to src/systemcmds)
# EXAMPLES : list of example modules to build for this board (relative to src/examples)
# SERIAL_PORTS : mapping of user configurable serial ports and param facing name
# EMBEDDED_METADATA : list of metadata to embed to ROMFS
# CONSTRAINED_FLASH : flag to enable constrained flash options (eg limit init script status text)
# CONSTRAINED_MEMORY : flag to enable constrained memory options (eg limit maximum number of uORB publications)
# TESTING : flag to enable automatic inclusion of PX4 testing modules
# LINKER_PREFIX : optional to prefix on the Linker script.
# ETHERNET : flag to indicate that ethernet is enabled
#
#
# Example:
# px4_add_board(
# PLATFORM nuttx
# VENDOR px4
# MODEL fmu-v5
# TOOLCHAIN arm-none-eabi
# ARCHITECTURE cortex-m7
# ROMFSROOT px4fmu_common
# IO px4_io-v2_default
# SERIAL_PORTS
# GPS1:/dev/ttyS0
# TEL1:/dev/ttyS1
# TEL2:/dev/ttyS2
# TEL4:/dev/ttyS3
# DRIVERS
# barometer/ms5611
# gps
# imu/bosch/bmi055
# imu/invensense/mpu6000
# magnetometer/isentek/ist8310
# pwm_out
# px4io
# rgbled
# MODULES
# commander
# ekf2
# land_detector
# mavlink
# mc_att_control
# mc_pos_control
# navigator
# sensors
# MODULES
# mixer
# mtd
# param
# perf
# pwm
# reboot
# shutdown
# top
# topic_listener
# tune_control
# )
#
function(px4_add_board)
px4_parse_function_args(
NAME px4_add_board
ONE_VALUE
PLATFORM
VENDOR
MODEL
LABEL
TOOLCHAIN
ARCHITECTURE
ROMFSROOT
IO
UAVCAN_INTERFACES
UAVCAN_TIMER_OVERRIDE
LINKER_PREFIX
MULTI_VALUE
DRIVERS
MODULES
SYSTEMCMDS
EXAMPLES
SERIAL_PORTS
UAVCAN_PERIPHERALS
EMBEDDED_METADATA
OPTIONS
BUILD_BOOTLOADER
CONSTRAINED_FLASH
CONSTRAINED_MEMORY
TESTING
ETHERNET
REQUIRED
PLATFORM
VENDOR
MODEL
ARGN ${ARGN})
set(PX4_BOARD_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE STRING "PX4 board directory" FORCE)
include_directories(${PX4_BOARD_DIR}/src)
set(PX4_BOARD ${VENDOR}_${MODEL} CACHE STRING "PX4 board" FORCE)
# board name is uppercase with no underscores when used as a define
string(TOUPPER ${PX4_BOARD} PX4_BOARD_NAME)
string(REPLACE "-" "_" PX4_BOARD_NAME ${PX4_BOARD_NAME})
set(PX4_BOARD_NAME ${PX4_BOARD_NAME} CACHE STRING "PX4 board define" FORCE)
set(PX4_BOARD_VENDOR ${VENDOR} CACHE STRING "PX4 board vendor" FORCE)
set(PX4_BOARD_MODEL ${MODEL} CACHE STRING "PX4 board model" FORCE)
if(LABEL)
set(PX4_BOARD_LABEL ${LABEL} CACHE STRING "PX4 board label" FORCE)
else()
set(PX4_BOARD_LABEL "default" CACHE STRING "PX4 board label" FORCE)
endif()
set(PX4_CONFIG "${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_${PX4_BOARD_LABEL}" CACHE STRING "PX4 config" FORCE)
# set OS, and append specific platform module path
set(PX4_PLATFORM ${PLATFORM} CACHE STRING "PX4 board OS" FORCE)
list(APPEND CMAKE_MODULE_PATH ${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake)
# platform-specific include path
include_directories(${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/src/px4/common/include)
if(ARCHITECTURE)
set(CMAKE_SYSTEM_PROCESSOR ${ARCHITECTURE} CACHE INTERNAL "system processor" FORCE)
endif()
if(TOOLCHAIN)
set(CMAKE_TOOLCHAIN_FILE Toolchain-${TOOLCHAIN} CACHE INTERNAL "toolchain file" FORCE)
endif()
set(romfs_extra_files)
set(config_romfs_extra_dependencies)
foreach(metadata ${EMBEDDED_METADATA})
if(${metadata} STREQUAL "parameters")
list(APPEND romfs_extra_files ${PX4_BINARY_DIR}/parameters.json.xz)
list(APPEND romfs_extra_dependencies parameters_xml)
else()
message(FATAL_ERROR "invalid value for EMBEDDED_METADATA: ${metadata}")
endif()
endforeach()
list(APPEND romfs_extra_files ${PX4_BINARY_DIR}/component_general.json.xz)
list(APPEND romfs_extra_dependencies component_general_json)
set(config_romfs_extra_files ${romfs_extra_files} CACHE INTERNAL "extra ROMFS files" FORCE)
set(config_romfs_extra_dependencies ${romfs_extra_dependencies} CACHE INTERNAL "extra ROMFS deps" FORCE)
if(SERIAL_PORTS)
set(board_serial_ports ${SERIAL_PORTS} PARENT_SCOPE)
endif()
# ROMFS
if(ROMFSROOT)
set(config_romfs_root ${ROMFSROOT} CACHE INTERNAL "ROMFS root" FORCE)
if(BUILD_BOOTLOADER)
set(config_build_bootloader "1" CACHE INTERNAL "build bootloader" FORCE)
endif()
# IO board (placed in ROMFS)
if(IO)
set(config_io_board ${IO} CACHE INTERNAL "IO" FORCE)
endif()
if(UAVCAN_PERIPHERALS)
set(config_uavcan_peripheral_firmware ${UAVCAN_PERIPHERALS} CACHE INTERNAL "UAVCAN peripheral firmware" FORCE)
endif()
endif()
if(UAVCAN_INTERFACES)
set(config_uavcan_num_ifaces ${UAVCAN_INTERFACES} CACHE INTERNAL "UAVCAN interfaces" FORCE)
endif()
if(UAVCAN_TIMER_OVERRIDE)
set(config_uavcan_timer_override ${UAVCAN_TIMER_OVERRIDE} CACHE INTERNAL "UAVCAN TIMER OVERRIDE" FORCE)
endif()
# OPTIONS
if(CONSTRAINED_FLASH)
set(px4_constrained_flash_build "1" CACHE INTERNAL "constrained flash build" FORCE)
add_definitions(-DCONSTRAINED_FLASH)
endif()
if(CONSTRAINED_MEMORY)
set(px4_constrained_memory_build "1" CACHE INTERNAL "constrained memory build" FORCE)
add_definitions(-DCONSTRAINED_MEMORY)
endif()
if(TESTING)
set(PX4_TESTING "1" CACHE INTERNAL "testing enabled" FORCE)
endif()
if(ETHERNET)
set(PX4_ETHERNET "1" CACHE INTERNAL "ethernet enabled" FORCE)
endif()
if(LINKER_PREFIX)
set(PX4_BOARD_LINKER_PREFIX ${LINKER_PREFIX} CACHE STRING "PX4 board linker prefix" FORCE)
else()
set(PX4_BOARD_LINKER_PREFIX "" CACHE STRING "PX4 board linker prefix" FORCE)
endif()
include(px4_impl_os)
px4_os_prebuild_targets(OUT prebuild_targets BOARD ${PX4_BOARD})
###########################################################################
# Modules (includes drivers, examples, modules, systemcmds)
set(config_module_list)
if(DRIVERS)
foreach(driver ${DRIVERS})
list(APPEND config_module_list drivers/${driver})
endforeach()
endif()
if(MODULES)
foreach(module ${MODULES})
list(APPEND config_module_list modules/${module})
endforeach()
endif()
if(SYSTEMCMDS)
foreach(systemcmd ${SYSTEMCMDS})
list(APPEND config_module_list systemcmds/${systemcmd})
endforeach()
endif()
if(EXAMPLES)
foreach(example ${EXAMPLES})
list(APPEND config_module_list examples/${example})
endforeach()
endif()
# add board config directory src to build modules
file(RELATIVE_PATH board_support_src_rel ${PX4_SOURCE_DIR}/src ${PX4_BOARD_DIR})
list(APPEND config_module_list ${board_support_src_rel}/src)
set(config_module_list ${config_module_list} PARENT_SCOPE)
endfunction()