waf: add --define command-line option

Allows CPP defines to be specified on command-line

Eases enable/disable of optional features
This commit is contained in:
Peter Barker 2022-06-27 10:38:38 +10:00 committed by Andrew Tridgell
parent 6c17fd7bac
commit c0243772b4
2 changed files with 11 additions and 0 deletions

View File

@ -563,6 +563,10 @@ arducopter and upload it to my board".
action='store_true',
help='Output all test programs.')
g.add_option('--define',
action='append',
help='Add C++ define to build.')
g = opt.ap_groups['clean']
g.add_option('--clean-all-sigs',

View File

@ -136,6 +136,13 @@ class Board:
# make easy to override them. Convert back to list before consumption.
env.DEFINES = {}
# potentially set extra defines from an environment variable:
if cfg.options.define is not None:
for (n, v) in [d.split("=") for d in cfg.options.define]:
cfg.msg("Defining: %s" % (n, ), v)
env.CFLAGS += ['-D%s=%s' % (n, v)]
env.CXXFLAGS += ['-D%s=%s' % (n, v)]
env.CFLAGS += [
'-ffunction-sections',
'-fdata-sections',