Skip to content

Commit

Permalink
waf: allow any custom build option to be specified in waf configure
Browse files Browse the repository at this point in the history
this makes it easy to configure with any option from build_options.py
  • Loading branch information
tridge committed Sep 8, 2024
1 parent 1e8e250 commit ad9a107
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
13 changes: 11 additions & 2 deletions Tools/ardupilotwaf/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# modify our search path:
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../libraries/AP_HAL_ChibiOS/hwdef/scripts'))
import chibios_hwdef
import build_options

class BoardMeta(type):
def __init__(cls, name, bases, dct):
Expand Down Expand Up @@ -159,8 +160,16 @@ def srcpath(path):
)
cfg.msg("Enabled custom controller", 'no', color='YELLOW')

if cfg.options.enable_ppp:
env.CXXFLAGS += ['-DAP_NETWORKING_BACKEND_PPP=1']
# support enabling any option in build_options.py
for opt in build_options.BUILD_OPTIONS:
enable_option = opt.config_option().replace("-","_")
disable_option = "disable_" + enable_option[len("enable-"):]
if getattr(cfg.options, enable_option, False):
env.CXXFLAGS += ['-D%s=1' % opt.define]
cfg.msg("Enabled %s" % opt.label, 'yes', color='GREEN')
elif getattr(cfg.options, disable_option, False):
env.CXXFLAGS += ['-D%s=0' % opt.define]
cfg.msg("Enabled %s" % opt.label, 'no', color='GREEN')

if cfg.options.disable_networking:
env.CXXFLAGS += ['-DAP_NETWORKING_ENABLED=0']
Expand Down
13 changes: 11 additions & 2 deletions Tools/scripts/build_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ def __init__(self,
define,
description,
default,
dependency):
dependency,
configure_option=None):
self.category = category
self.label = label
self.define = define
self.description = description
self.default = default
self.dependency = dependency
self.configure_option = configure_option

def config_option(self):
conf_option = self.configure_option
if conf_option is None:
conf_option = "enable-" + self.label.replace(" ","-")
return conf_option



# list of build options to offer NOTE: the dependencies must be
Expand Down Expand Up @@ -413,7 +422,7 @@ def __init__(self,
Feature('Filesystem', 'FILESYSTEM_SYS', 'AP_FILESYSTEM_SYS_ENABLED', 'Enable @SYS/ filesystem', 0, None),
Feature('Filesystem', 'APJ_TOOL_PARAMETERS', 'FORCE_APJ_DEFAULT_PARAMETERS', 'Enable apj_tool parameter area', 0, None),

Feature('Networking', 'PPP Support', 'AP_NETWORKING_BACKEND_PPP', 'Enable PPP networking', 0, None),
Feature('Networking', 'PPP Support', 'AP_NETWORKING_BACKEND_PPP', 'Enable PPP networking', 0, None, "enable-ppp"),

Feature('DroneCAN', 'DroneCAN', 'HAL_ENABLE_DRONECAN_DRIVERS', 'Enable DroneCAN support', 0, None),
]
Expand Down
21 changes: 16 additions & 5 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import subprocess
import json
import fnmatch
sys.path.insert(0, 'Tools/ardupilotwaf/')
sys.path.insert(0, 'Tools/scripts/')

import ardupilotwaf
import boards
import shutil
import build_options

from waflib import Build, ConfigSet, Configure, Context, Utils
from waflib.Configure import conf
Expand Down Expand Up @@ -204,11 +206,6 @@ def options(opt):
default=False,
help='enable OS level thread statistics.')

g.add_option('--enable-ppp',
action='store_true',
default=False,
help='enable PPP networking.')

g.add_option('--bootloader',
action='store_true',
default=False,
Expand Down Expand Up @@ -446,6 +443,20 @@ configuration in order to save typing.
action='store_true',
default=False,
help='enables checking of new to ensure NEW_NOTHROW is used')

# support enabling any option in build_options.py
for opt in build_options.BUILD_OPTIONS:
enable_option = "--" + opt.config_option()
disable_option = enable_option.replace("--enable", "--disable")
g.add_option(enable_option,
action='store_true',
default=False,
help='enable %s' % opt.label)
g.add_option(disable_option,
action='store_true',
default=False,
help='disable %s' % opt.label)


def _collect_autoconfig_files(cfg):
for m in sys.modules.values():
Expand Down

0 comments on commit ad9a107

Please sign in to comment.