wscript: WafToolchainFlags
This commit is contained in:
parent
c097aa5a38
commit
4263a92024
79
wscript
79
wscript
|
@ -109,6 +109,85 @@ def detect_platform(conf):
|
|||
conf.end_msg(name, color='CYAN')
|
||||
break
|
||||
|
||||
class WafToolchainFlags:
|
||||
"""
|
||||
Waf helper class for handling set of CFLAGS
|
||||
and related. The flush() method will
|
||||
prepend so to allow supplied by (downstream/distro/builder) waf caller flags
|
||||
to override the upstream flags in wscript.
|
||||
TODO: upstream this or find alternative easy way of doing the same
|
||||
"""
|
||||
def __init__(self, conf):
|
||||
"""
|
||||
:param conf: Waf configuration object
|
||||
"""
|
||||
self.conf = conf
|
||||
self.flags = {}
|
||||
for x in ('CPPFLAGS', 'CFLAGS', 'CXXFLAGS', 'LINKFLAGS'):
|
||||
self.flags[x] = []
|
||||
|
||||
def flush(self):
|
||||
"""
|
||||
Flush flags to the configuration object
|
||||
Prepend is used so to allow supplied by
|
||||
(downstream/distro/builder) waf caller flags
|
||||
to override the upstream flags in wscript.
|
||||
"""
|
||||
for key, val in self.flags.items():
|
||||
self.conf.env.prepend_value(key, val)
|
||||
|
||||
def add(self, key, val):
|
||||
"""
|
||||
:param key: Set to add flags to. 'CPPFLAGS', 'CFLAGS', 'CXXFLAGS' or 'LINKFLAGS'
|
||||
:param val: string or list of strings
|
||||
"""
|
||||
flags = self.flags[key]
|
||||
if isinstance(val, list):
|
||||
#flags.extend(val)
|
||||
for x in val:
|
||||
if not isinstance(x, str):
|
||||
raise Exception("value must be string or list of strings. ", type(x))
|
||||
flags.append(x)
|
||||
elif isinstance(val, str):
|
||||
flags.append(val)
|
||||
else:
|
||||
raise Exception("value must be string or list of strings")
|
||||
|
||||
def add_cpp(self, value):
|
||||
"""
|
||||
Add flag or list of flags to CPPFLAGS
|
||||
:param value: string or list of strings
|
||||
"""
|
||||
self.add('CPPFLAGS', value)
|
||||
|
||||
def add_c(self, value):
|
||||
"""
|
||||
Add flag or list of flags to CFLAGS
|
||||
:param value: string or list of strings
|
||||
"""
|
||||
self.add('CFLAGS', value)
|
||||
|
||||
def add_cxx(self, value):
|
||||
"""
|
||||
Add flag or list of flags to CXXFLAGS
|
||||
:param value: string or list of strings
|
||||
"""
|
||||
self.add('CXXFLAGS', value)
|
||||
|
||||
def add_candcxx(self, value):
|
||||
"""
|
||||
Add flag or list of flags to CFLAGS and CXXFLAGS
|
||||
:param value: string or list of strings
|
||||
"""
|
||||
self.add_c(value)
|
||||
self.add_cxx(value)
|
||||
|
||||
def add_link(self, value):
|
||||
"""
|
||||
Add flag or list of flags to LINKFLAGS
|
||||
:param value: string or list of strings
|
||||
"""
|
||||
self.add('LINKFLAGS', value)
|
||||
|
||||
def configure(conf):
|
||||
conf.load('compiler_cxx')
|
||||
|
|
Loading…
Reference in New Issue