waf: tidy interpretation of -Werror

This commit is contained in:
Peter Barker 2023-07-31 11:00:50 +10:00 committed by Andrew Tridgell
parent 09a59bc934
commit 46b262cb32
2 changed files with 23 additions and 14 deletions

View File

@ -774,21 +774,30 @@ class sitl(Board):
# whitelist of compilers which we should build with -Werror # whitelist of compilers which we should build with -Werror
gcc_whitelist = frozenset([ gcc_whitelist = frozenset([
('11','3','0'), ('11','3','0'),
('12','1','0'),
]) ])
werr_enabled_default = bool('g++' == cfg.env.COMPILER_CXX and cfg.env.CC_VERSION in gcc_whitelist) # initialise werr_enabled from defaults:
werr_enabled = bool('g++' in cfg.env.COMPILER_CXX and cfg.env.CC_VERSION in gcc_whitelist)
if werr_enabled_default or cfg.options.Werror: # now process overrides to that default:
if not cfg.options.disable_Werror: if (cfg.options.Werror is not None and
cfg.msg("Enabling -Werror", "yes") cfg.options.Werror == cfg.options.disable_Werror):
if '-Werror' not in env.CXXFLAGS: cfg.fatal("Asked to both enable and disable Werror")
env.CXXFLAGS += [ '-Werror' ]
else: if cfg.options.Werror is not None:
cfg.msg("Enabling -Werror", "no") werr_enabled = cfg.options.Werror
if '-Werror' in env.CXXFLAGS: elif cfg.options.disable_Werror is not None:
env.CXXFLAGS.remove('-Werror') werr_enabled = not cfg.options.disable_Werror
else:
if werr_enabled:
cfg.msg("Enabling -Werror", "yes") cfg.msg("Enabling -Werror", "yes")
if '-Werror' not in env.CXXFLAGS:
env.CXXFLAGS += [ '-Werror' ]
else:
cfg.msg("Enabling -Werror", "no")
if '-Werror' in env.CXXFLAGS:
env.CXXFLAGS.remove('-Werror')
def get_name(self): def get_name(self):
return self.__class__.__name__ return self.__class__.__name__

View File

@ -143,12 +143,12 @@ def options(opt):
g.add_option('--Werror', g.add_option('--Werror',
action='store_true', action='store_true',
default=False, default=None,
help='build with -Werror.') help='build with -Werror.')
g.add_option('--disable-Werror', g.add_option('--disable-Werror',
action='store_true', action='store_true',
default=True, default=None,
help='Disable -Werror.') help='Disable -Werror.')
g.add_option('--toolchain', g.add_option('--toolchain',