mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-04 23:18:28 -04:00
a36a766e1a
Recursively collect objects from dependency libraries and create a single library. That way we just need to pass down one single library to PX4Firmware build system.
123 lines
3.8 KiB
Python
123 lines
3.8 KiB
Python
#!/usr/bin/env python
|
|
# encoding: utf-8
|
|
|
|
"""
|
|
Waf tool for PX4 build
|
|
"""
|
|
|
|
from waflib import Task, Utils
|
|
from waflib.TaskGen import after_method, before_method, feature
|
|
|
|
import os
|
|
|
|
_dynamic_env_data = {}
|
|
def _load_dynamic_env_data(bld):
|
|
bldnode = bld.bldnode.make_node('modules/PX4Firmware')
|
|
for name in ('cxx_flags', 'include_dirs', 'definitions'):
|
|
_dynamic_env_data[name] = bldnode.find_node(name).read().split(';')
|
|
|
|
_dynamic_env_data['DEFINES'] = [
|
|
'NUTTX_GIT_VERSION="%s"' % bld.git_submodule_head_hash('PX4NuttX')[:8],
|
|
'PX4_GIT_VERSION="%s"' % bld.git_submodule_head_hash('PX4Firmware')[:8],
|
|
]
|
|
|
|
@feature('px4_ap_stlib', 'px4_ap_program')
|
|
@before_method('process_source')
|
|
def px4_dynamic_env(self):
|
|
# The generated files from configuration possibly don't exist if it's just
|
|
# a list command (TODO: figure out a better way to address that).
|
|
if self.bld.cmd == 'list':
|
|
return
|
|
|
|
if not _dynamic_env_data:
|
|
_load_dynamic_env_data(self.bld)
|
|
|
|
self.env.append_value('INCLUDES', _dynamic_env_data['include_dirs'])
|
|
self.env.prepend_value('CXXFLAGS', _dynamic_env_data['cxx_flags'])
|
|
self.env.prepend_value('CXXFLAGS', _dynamic_env_data['definitions'])
|
|
self.env.append_value('DEFINES', _dynamic_env_data['DEFINES'])
|
|
|
|
# Single static library
|
|
# NOTE: This only works only for local static libraries dependencies - fake
|
|
# libraries aren't supported yet
|
|
@feature('px4_ap_program')
|
|
@after_method('apply_link')
|
|
@before_method('process_use')
|
|
def px4_import_objects_from_use(self):
|
|
queue = Utils.to_list(getattr(self, 'use', []))
|
|
names = set()
|
|
|
|
while queue:
|
|
name = queue.pop(0)
|
|
if name in names:
|
|
continue
|
|
names.add(name)
|
|
|
|
try:
|
|
tg = self.bld.get_tgen_by_name(name)
|
|
except Errors.WafError:
|
|
continue
|
|
|
|
tg.post()
|
|
for t in getattr(tg, 'compiled_tasks', []):
|
|
self.link_task.set_inputs(t.outputs)
|
|
|
|
queue.extend(Utils.to_list(getattr(tg, 'use', [])))
|
|
|
|
def configure(cfg):
|
|
cfg.load('cmake')
|
|
|
|
env = cfg.env
|
|
|
|
env.AP_PROGRAM_FEATURES += ['px4_ap_program']
|
|
env.AP_STLIB_FEATURES += ['px4_ap_stlib']
|
|
|
|
def srcpath(path):
|
|
return cfg.srcnode.make_node(path).abspath()
|
|
|
|
env.PX4_CMAKE_VARS = dict(
|
|
CONFIG='nuttx_px4fmu-v%s_apm' % env.get_flat('PX4_VERSION'),
|
|
CMAKE_MODULE_PATH=srcpath('Tools/ardupilotwaf/px4/cmake'),
|
|
UAVCAN_LIBUAVCAN_PATH=srcpath('modules/uavcan'),
|
|
NUTTX_SRC=srcpath('modules/PX4NuttX'),
|
|
EXTRA_CXX_FLAGS=' '.join((
|
|
# NOTE: these "-Wno-error=*" flags should be removed as we update
|
|
# the submodule
|
|
'-Wno-error=double-promotion',
|
|
'-Wno-error=reorder',
|
|
# NOTE: *Temporarily* using this definition so that both
|
|
# PX4Firmware build systems (cmake and legacy make-based) can live
|
|
# together
|
|
'-DCMAKE_BUILD',
|
|
'-I%s' % bldpath('libraries/GCS_MAVLink'),
|
|
'-Wl,--gc-sections',
|
|
)),
|
|
EXTRA_C_FLAGS=' '.join((
|
|
# NOTE: *Temporarily* using this definition so that both
|
|
# PX4Firmware build systems (cmake and legacy make-based) can live
|
|
# together
|
|
'-DCMAKE_BUILD',
|
|
)),
|
|
)
|
|
|
|
def build(bld):
|
|
version = bld.env.get_flat('PX4_VERSION')
|
|
px4 = bld(
|
|
features='cmake_configure',
|
|
name='px4',
|
|
cmake_src=bld.srcnode.find_dir('modules/PX4Firmware'),
|
|
cmake_vars=bld.env.PX4_CMAKE_VARS,
|
|
group='dynamic_sources',
|
|
)
|
|
|
|
px4.cmake_build(
|
|
'msg_gen',
|
|
group='dynamic_sources',
|
|
cmake_output_patterns='src/modules/uORB/topics/*.h',
|
|
)
|
|
px4.cmake_build(
|
|
'prebuild_targets',
|
|
group='dynamic_sources',
|
|
cmake_output_patterns='px4fmu-v%s/NuttX/nuttx-export/**/*.h' % version,
|
|
)
|