build: Enabling -Werror in debug mode and fixing discovered issues

Change-Id: I29685dcb9240a3e0c8d7eaf28c8bc2ae720e55a1
diff --git a/wscript b/wscript
index 77b8e80..3010174 100644
--- a/wscript
+++ b/wscript
@@ -11,8 +11,6 @@
     nfdopt = opt.add_option_group('NFD Options')
     nfdopt.add_option('--debug',action='store_true',default=False,dest='debug',help='''Compile library debugging mode without all optimizations (-O0)''')
     nfdopt.add_option('--with-tests', action='store_true',default=False,dest='with_tests',help='''Build unit tests''')
-    nfdopt.add_option('--with-ndn-cpp',action='store',type='string',default=None,dest='ndn_cpp_dir',
-                      help='''Use NDN-CPP library from the specified path''')
 
 def configure(conf):
     conf.load("compiler_cxx boost gnu_dirs")
@@ -21,29 +19,30 @@
     except:
         pass
 
+    areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
     if conf.options.debug:
         conf.define('_DEBUG', 1)
-        conf.add_supported_cxxflags(cxxflags = ['-O0',
-                                                '-Wall',
-                                                '-Wno-unused-variable',
-                                                '-g3',
-                                                '-Wno-unused-private-field', # only clang supports
-                                                '-fcolor-diagnostics',       # only clang supports
-                                                '-Qunused-arguments',        # only clang supports
-                                                '-Wno-tautological-compare', # suppress warnings from CryptoPP
-                                                '-Wno-unused-function',      # suppress warnings from CryptoPP
-                                                '-fno-inline',
-                                                ])
-    else:
-        conf.add_supported_cxxflags(cxxflags = ['-O3', '-g', '-Wno-tautological-compare', '-Wno-unused-function'])
+        defaultFlags = ['-O0', '-g3',
+                        '-Werror',
+                        '-Wall',
+                        '-fcolor-diagnostics', # only clang supports
+                        ]
 
-    if not conf.options.ndn_cpp_dir:
-        conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'], uselib_store='NDN_CPP', mandatory=True)
+        if areCustomCxxflagsPresent:
+            missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
+            if len(missingFlags) > 0:
+                Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
+                           % " ".join(conf.env.CXXFLAGS))
+                Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
+        else:
+            conf.add_supported_cxxflags(cxxflags = defaultFlags)
     else:
-        conf.check_cxx(lib='ndn-cpp-dev', uselib_store='NDN_CPP',
-                       cxxflags="-I%s/include" % conf.options.ndn_cpp_dir,
-                       linkflags="-L%s/lib" % conf.options.ndn_cpp_dir,
-                       mandatory=True)
+        defaultFlags = ['-O2', '-g', '-Wall']
+        if not areCustomCxxflagsPresent:
+            conf.add_supported_cxxflags(cxxflags = defaultFlags)
+
+    conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'],
+                   uselib_store='NDN_CPP', mandatory=True)
 
     boost_libs = 'system chrono program_options'
     if conf.options.with_tests:
@@ -64,9 +63,9 @@
     conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False)
     if conf.check_cxx(lib='pcap', uselib_store='PCAP', define_name='HAVE_PCAP', mandatory=False):
         conf.env['HAVE_PCAP'] = True
-    
+
     conf.check_cxx(lib='resolv', uselib_store='RESOLV', mandatory=True)
-    
+
     conf.load('coverage')
 
     conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nfd.conf' % conf.env['SYSCONFDIR'])
@@ -144,7 +143,7 @@
             supportedFlags += [flag]
 
     self.end_msg(' '.join (supportedFlags))
-    self.env.CXXFLAGS += supportedFlags
+    self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
 
 # doxygen docs
 from waflib.Build import BuildContext