build+ci: Synchronize build and CI scripts with ndn-cxx/NFD
This commit also fixes a minor problem causing compilation warnings.
Change-Id: I0c04d58fe9df24f181947b9fde1346283402fc7b
diff --git a/.waf-tools/default-compiler-flags.py b/.waf-tools/default-compiler-flags.py
index 4f53823..2999e8f 100644
--- a/.waf-tools/default-compiler-flags.py
+++ b/.waf-tools/default-compiler-flags.py
@@ -14,22 +14,21 @@
flags = ClangFlags()
else:
flags = CompilerFlags()
- Logs.warn('The code has not been yet tested with %s compiler' % cxx)
+ Logs.warn('The code has not yet been tested with %s compiler' % cxx)
areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
- # General flags will alway be applied (e.g., selecting C++11 mode)
+ # General flags are always applied (e.g., selecting C++11 mode)
generalFlags = flags.getGeneralFlags(conf)
conf.add_supported_cxxflags(generalFlags['CXXFLAGS'])
conf.add_supported_linkflags(generalFlags['LINKFLAGS'])
conf.env.DEFINES += generalFlags['DEFINES']
- # Debug or optimization CXXFLAGS and LINKFLAGS will be applied only if the
+ # Debug or optimized CXXFLAGS and LINKFLAGS are applied only if the
# corresponding environment variables are not set.
- # DEFINES will be always applied
+ # DEFINES are always applied.
if conf.options.debug:
extraFlags = flags.getDebugFlags(conf)
-
if areCustomCxxflagsPresent:
missingFlags = [x for x in extraFlags['CXXFLAGS'] if x not in conf.env.CXXFLAGS]
if len(missingFlags) > 0:
@@ -41,7 +40,7 @@
if not areCustomCxxflagsPresent:
conf.add_supported_cxxflags(extraFlags['CXXFLAGS'])
- conf.add_supported_cxxflags(extraFlags['LINKFLAGS'])
+ conf.add_supported_linkflags(extraFlags['LINKFLAGS'])
conf.env.DEFINES += extraFlags['DEFINES']
@@ -61,7 +60,7 @@
supportedFlags += [flag]
self.end_msg(' '.join(supportedFlags))
- self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
+ self.env.prepend_value('CXXFLAGS', supportedFlags)
@Configure.conf
def add_supported_linkflags(self, linkflags):
@@ -79,77 +78,104 @@
supportedFlags += [flag]
self.end_msg(' '.join(supportedFlags))
- self.env.LINKFLAGS = supportedFlags + self.env.LINKFLAGS
+ self.env.prepend_value('LINKFLAGS', supportedFlags)
class CompilerFlags(object):
def getGeneralFlags(self, conf):
- """Get dict {'CXXFLAGS':[...], LINKFLAGS:[...], DEFINES:[...]} that are always needed"""
+ """Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are always needed"""
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': []}
def getDebugFlags(self, conf):
- """Get tuple {CXXFLAGS, LINKFLAGS, DEFINES} that are needed in debug mode"""
+ """Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in debug mode"""
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': ['_DEBUG']}
def getOptimizedFlags(self, conf):
- """Get tuple {CXXFLAGS, LINKFLAGS, DEFINES} that are needed in optimized mode"""
+ """Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in optimized mode"""
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': ['NDEBUG']}
class GccBasicFlags(CompilerFlags):
- """This class defines base flags that work for gcc and clang compiler"""
+ """
+ This class defines basic flags that work for both gcc and clang compilers
+ """
def getDebugFlags(self, conf):
flags = super(GccBasicFlags, self).getDebugFlags(conf)
- flags['CXXFLAGS'] += ['-pedantic', '-Wall',
- '-O0',
+ flags['CXXFLAGS'] += ['-O0',
'-g3',
+ '-pedantic',
+ '-Wall',
+ '-Wextra',
'-Werror',
+ '-Wno-unused-parameter',
'-Wno-error=maybe-uninitialized', # Bug #1615
- ]
+ '-Wno-error=deprecated-declarations', # Bug #3795
+ ]
return flags
def getOptimizedFlags(self, conf):
flags = super(GccBasicFlags, self).getOptimizedFlags(conf)
- flags['CXXFLAGS'] += ['-pedantic', '-Wall', '-O2', '-g']
+ flags['CXXFLAGS'] += ['-O2',
+ '-g',
+ '-pedantic',
+ '-Wall',
+ '-Wextra',
+ '-Wno-unused-parameter',
+ ]
return flags
class GccFlags(GccBasicFlags):
def getGeneralFlags(self, conf):
flags = super(GccFlags, self).getGeneralFlags(conf)
version = tuple(int(i) for i in conf.env['CC_VERSION'])
- if version < (4, 6, 0):
+ if version < (4, 8, 2):
conf.fatal('The version of gcc you are using (%s) is too old.\n' %
'.'.join(conf.env['CC_VERSION']) +
- 'The minimum supported gcc version is 4.6.0.')
- elif version < (4, 7, 0):
- flags['CXXFLAGS'] += ['-std=c++0x']
+ 'The minimum supported gcc version is 4.8.2.')
else:
flags['CXXFLAGS'] += ['-std=c++11']
- if version < (4, 8, 0):
- flags['DEFINES'] += ['_GLIBCXX_USE_NANOSLEEP'] # Bug #2499
return flags
def getDebugFlags(self, conf):
flags = super(GccFlags, self).getDebugFlags(conf)
+ version = tuple(int(i) for i in conf.env['CC_VERSION'])
+ if version < (5, 1, 0):
+ flags['CXXFLAGS'] += ['-Wno-missing-field-initializers']
flags['CXXFLAGS'] += ['-Og', # gcc >= 4.8
'-fdiagnostics-color', # gcc >= 4.9
- ]
+ ]
+ return flags
+
+ def getOptimizedFlags(self, conf):
+ flags = super(GccFlags, self).getOptimizedFlags(conf)
+ version = tuple(int(i) for i in conf.env['CC_VERSION'])
+ if version < (5, 1, 0):
+ flags['CXXFLAGS'] += ['-Wno-missing-field-initializers']
+ flags['CXXFLAGS'] += ['-fdiagnostics-color'] # gcc >= 4.9
return flags
class ClangFlags(GccBasicFlags):
def getGeneralFlags(self, conf):
flags = super(ClangFlags, self).getGeneralFlags(conf)
- flags['CXXFLAGS'] += ['-std=c++11',
- '-Wno-error=unneeded-internal-declaration', # Bug #1588
- '-Wno-error=deprecated-register',
- '-Wno-error=unused-local-typedef', # Bug #2657
- '-Wno-error=keyword-macro',
- ]
- if Utils.unversioned_sys_platform() == "darwin":
+ flags['CXXFLAGS'] += ['-std=c++11']
+ if Utils.unversioned_sys_platform() == 'darwin':
flags['CXXFLAGS'] += ['-stdlib=libc++']
flags['LINKFLAGS'] += ['-stdlib=libc++']
return flags
def getDebugFlags(self, conf):
flags = super(ClangFlags, self).getDebugFlags(conf)
- flags['CXXFLAGS'] += ['-fcolor-diagnostics']
+ flags['CXXFLAGS'] += ['-fcolor-diagnostics',
+ '-Wno-unused-local-typedef', # Bugs #2657 and #3209
+ '-Wno-error=unneeded-internal-declaration', # Bug #1588
+ '-Wno-error=deprecated-register',
+ '-Wno-error=keyword-macro', # Bug #3235
+ '-Wno-error=infinite-recursion', # Bug #3358
+ ]
+ return flags
+
+ def getOptimizedFlags(self, conf):
+ flags = super(ClangFlags, self).getOptimizedFlags(conf)
+ flags['CXXFLAGS'] += ['-fcolor-diagnostics',
+ '-Wno-unused-local-typedef', # Bugs #2657 and #3209
+ ]
return flags
diff --git a/.waf-tools/sanitizers.py b/.waf-tools/sanitizers.py
new file mode 100644
index 0000000..a8fe55d
--- /dev/null
+++ b/.waf-tools/sanitizers.py
@@ -0,0 +1,22 @@
+# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def options(opt):
+ opt.add_option('--with-sanitizer', action='store', default='', dest='sanitizers',
+ help='Comma-separated list of compiler sanitizers to enable [default=none]')
+
+def configure(conf):
+ for san in conf.options.sanitizers.split(','):
+ if not san:
+ continue
+
+ sanflag = '-fsanitize=%s' % san
+ conf.start_msg('Checking if compiler supports %s' % sanflag)
+
+ if conf.check_cxx(cxxflags=['-Werror', sanflag, '-fno-omit-frame-pointer'],
+ linkflags=[sanflag], mandatory=False):
+ conf.end_msg('yes')
+ conf.env.append_unique('CXXFLAGS', [sanflag, '-fno-omit-frame-pointer'])
+ conf.env.append_unique('LINKFLAGS', [sanflag])
+ else:
+ conf.end_msg('no', color='RED')
+ conf.fatal('%s sanitizer is not supported by the current compiler' % san)