build: Enabling -Werror in debug mode and updating behavior of CXXFLAGS overriding

Change-Id: Ieee3ad85bf0e3eb283b2d42a6df8d3942cf11a51
diff --git a/.waf-tools/flags.py b/.waf-tools/flags.py
index 5b437eb..dea80b8 100644
--- a/.waf-tools/flags.py
+++ b/.waf-tools/flags.py
@@ -1,28 +1,40 @@
 # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
 
-from waflib import Configure
+from waflib import Logs, Configure
 
 def configure(conf):
+    areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
     if conf.options.debug:
-        conf.define ('_DEBUG', 1)
-        flags = ['-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',      # another annoying warning from CryptoPP
+        conf.define('_DEBUG', 1)
+        defaultFlags = ['-O0', '-g3',
+                        '-Werror',
+                        '-Wall',
+                        '-fcolor-diagnostics', # only clang supports
 
-                 '-Wno-deprecated-declarations',
-                 ]
+                        # # to disable known warnings
+                        # '-Wno-unused-variable', # cryptopp
+                        # '-Wno-unused-function',
+                        # '-Wno-deprecated-declarations',
+                        ]
 
-        conf.add_supported_cxxflags (cxxflags = flags)
+        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:
-        flags = ['-O3', '-g', '-Wno-tautological-compare','-Wno-unused-variable',
-                         '-Wno-unused-function', '-Wno-deprecated-declarations']
-        conf.add_supported_cxxflags (cxxflags = flags)
+        defaultFlags = ['-O2', '-g', '-Wall',
+
+                        # # to disable known warnings
+                        # '-Wno-unused-variable', # cryptopp
+                        # '-Wno-unused-function',
+                        # '-Wno-deprecated-declarations',
+                        ]
+        if not areCustomCxxflagsPresent:
+            conf.add_supported_cxxflags(cxxflags=defaultFlags)
 
 @Configure.conf
 def add_supported_cxxflags(self, cxxflags):
@@ -38,4 +50,3 @@
 
     self.end_msg (' '.join (supportedFlags))
     self.env.CXXFLAGS += supportedFlags
-
diff --git a/src/nrd.cpp b/src/nrd.cpp
index 239f940..bad2265 100644
--- a/src/nrd.cpp
+++ b/src/nrd.cpp
@@ -35,7 +35,7 @@
   };
 
 void
-Nrd::setInterestFilterFailed(const Name& name, const std::string& msg) 
+Nrd::setInterestFilterFailed(const Name& name, const std::string& msg)
 {
   std::cerr << "Error in setting interest filter (" << name << "): " << msg << std::endl;
   m_face.shutdown();
@@ -47,14 +47,14 @@
                    COMMAND_VERBS + (sizeof(COMMAND_VERBS) / sizeof(VerbAndProcessor)))
 {
   //check whether the components of localhop and localhost prefixes are same
-  BOOST_ASSERT(COMMAND_PREFIX.size() == REMOTE_COMMAND_PREFIX.size ()); 
+  BOOST_ASSERT(COMMAND_PREFIX.size() == REMOTE_COMMAND_PREFIX.size());
 
   std::cerr << "Setting interest filter on: " << COMMAND_PREFIX.toUri() << std::endl;
   m_face.setController(m_nfdController);
   m_face.setInterestFilter(COMMAND_PREFIX.toUri(),
                            bind(&Nrd::onRibRequest, this, _2),
                            bind(&Nrd::setInterestFilterFailed, this, _1, _2));
-  
+
   std::cerr << "Setting interest filter on: " << REMOTE_COMMAND_PREFIX.toUri() << std::endl;
   m_face.setInterestFilter(REMOTE_COMMAND_PREFIX.toUri(),
                            bind(&Nrd::onRibRequest, this, _2),
@@ -105,7 +105,7 @@
       return;
     }
 
-  //REMOTE_COMMAND_PREFIX number of componenets are same as 
+  //REMOTE_COMMAND_PREFIX number of componenets are same as
   // NRD_COMMAND_PREFIX's so no extra checks are required.
   const Name::Component& verb = command.get(COMMAND_PREFIX.size());
   VerbDispatchTable::const_iterator verbProcessor = m_verbDispatch.find(verb);
@@ -127,7 +127,7 @@
         }
 
       // \todo add proper log support
-      std::cout << "Received options (name, faceid, cost): " << options.getName() << 
+      std::cout << "Received options (name, faceid, cost): " << options.getName() <<
                    ", " << options.getFaceId() << ", "  << options.getCost() << std::endl;
 
       nfd::ControlResponse response;
@@ -143,8 +143,8 @@
 Nrd::extractOptions(const Interest& request,
                     PrefixRegOptions& extractedOptions)
 {
-  const Name& command = request.getName();
-  //REMOTE_COMMAND_PREFIX is same in size of NRD_COMMAND_PREFIX 
+  // const Name& command = request.getName();
+  //REMOTE_COMMAND_PREFIX is same in size of NRD_COMMAND_PREFIX
   //so no extra processing is required.
   const size_t optionCompIndex = COMMAND_PREFIX.size() + 1;
 
@@ -167,15 +167,15 @@
 }
 
 void
-Nrd::onCommandError(const std::string& error, 
-                    const Interest& request, 
+Nrd::onCommandError(const std::string& error,
+                    const Interest& request,
                     const PrefixRegOptions& options)
 {
   nfd::ControlResponse response;
-  
+
   response.setCode(400);
   response.setText(error);
-  
+
   std::cout << "Error: " << error << std::endl;
   sendResponse(request.getName(), response);
   m_managedRib.erase(options);
@@ -185,13 +185,13 @@
 Nrd::onUnRegSuccess(const Interest& request, const PrefixRegOptions& options)
 {
   nfd::ControlResponse response;
-  
+
   response.setCode(200);
   response.setText("Success");
   response.setBody(options.wireEncode());
- 
-  std::cout << "Success: Name unregistered (" << 
-                options.getName() << ", " << 
+
+  std::cout << "Success: Name unregistered (" <<
+                options.getName() << ", " <<
                 options.getFaceId() << ")" << std::endl;
   sendResponse(request.getName(), response);
   m_managedRib.erase(options);
@@ -201,12 +201,12 @@
 Nrd::onRegSuccess(const Interest& request, const PrefixRegOptions& options)
 {
   nfd::ControlResponse response;
-  
+
   response.setCode(200);
   response.setText("Success");
   response.setBody(options.wireEncode());
-  
-  std::cout << "Success: Name registered (" << options.getName() << ", " << 
+
+  std::cout << "Success: Name registered (" << options.getName() << ", " <<
                                                options.getFaceId() << ")" << std::endl;
   sendResponse(request.getName(), response);
 }
@@ -265,7 +265,7 @@
 {
   Name enable("/localhost/nfd/control-header/in-faceid/enable");
   Interest enableCommand(enable);
- 
+
   m_keyChain.sign(enableCommand);
   m_face.expressInterest(enableCommand,
                          ndn::bind(&Nrd::onControlHeaderSuccess, this),
diff --git a/wscript b/wscript
index a1f7a76..89c8f40 100644
--- a/wscript
+++ b/wscript
@@ -1,32 +1,35 @@
 # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
 
-from waflib import Build, Logs, Utils, Task, TaskGen, Configure
-import os
+from waflib import Logs
 
 def options(opt):
     opt.load('compiler_cxx gnu_dirs')
     opt.load('flags boost doxygen coverage', tooldir=['.waf-tools'])
 
     nrdopt = opt.add_option_group('NRD Options')
-    nrdopt.add_option('--debug',action='store_true',default=False,dest='debug',help='''Compile library debugging mode without all optimizations (-O0)''')
-    nrdopt.add_option('--with-tests', action='store_true',default=False,dest='with_tests',help='''Build unit tests''')
+    nrdopt.add_option('--debug', action='store_true', default=False,
+                      dest='debug',
+                      help='''Compile library debugging mode without all optimizations (-O0)''')
+    nrdopt.add_option('--with-tests', action='store_true',
+                      default=False, dest='with_tests', help='''Build unit tests''')
 
 def configure(conf):
     conf.load("compiler_cxx gnu_dirs boost flags")
 
-    conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'], uselib_store='NDN_CPP', mandatory=True)
+    conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'],
+                   uselib_store='NDN_CPP', mandatory=True)
 
-    boost_libs='system'
+    boost_libs = 'system'
     if conf.options.with_tests:
         conf.env['WITH_TESTS'] = 1
         conf.define('WITH_TESTS', 1);
-        boost_libs+=' unit_test_framework'
+        boost_libs += ' unit_test_framework'
 
     conf.check_boost(lib=boost_libs)
     if conf.env.BOOST_VERSION_NUMBER < 104800:
-        Logs.error ("Minimum required boost version is 1.48")
-        Logs.error ("Please upgrade your distribution or install custom boost libraries" +
-                    " (http://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)")
+        Logs.error("Minimum required boost version is 1.48")
+        Logs.error("Please upgrade your distribution or install custom boost libraries" +
+                   " (http://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)")
         return
 
     # conf.load('coverage')
@@ -40,25 +43,26 @@
 
 def build (bld):
     bld(
-        features=['cxx'],
-        name="nrd-objects",
-        source = bld.path.ant_glob('src/*.cpp', excl='src/main.cpp'),
-        use = 'NDN_CPP BOOST',
+        features='cxx',
+        name='nrd-objects',
+        source=bld.path.ant_glob('src/*.cpp',
+                                 excl='src/main.cpp'),
+        use='NDN_CPP BOOST',
         )
 
     bld.program(
-        target = 'nrd',
-        source = 'src/main.cpp',
-        use = 'nrd-objects'
+        target='nrd',
+        source='src/main.cpp',
+        use='nrd-objects'
         )
 
     # Unit tests
     if bld.env['WITH_TESTS']:
-        unit_tests = unittests = bld.program(
+        unit_tests = bld.program(
             target='unit-tests',
-            features = 'cxx cxxprogram',
-            source = bld.path.ant_glob(['tests/**/*.cpp']),
-            use = 'nrd-objects',
-            includes = ['.', 'src'],
-            install_prefix = None,
+            features='cxx cxxprogram',
+            source=bld.path.ant_glob(['tests/**/*.cpp']),
+            use='nrd-objects',
+            includes=['.', 'src'],
+            install_prefix=None,
           )