build: Making build system consistent with other NDN projects and adding unit-test framework

This commit aims only at correcting building system and adding unit-test framework.
Existing test cases (ChronoSync) are disabled temporarily and will be fixed later.
Minimum changes are made, so that the code can be built successfully.
Compiling warnings will be resolved in a later commit.

Refs: #1495

Change-Id: Ibf7119bbd77b6307cb58bbee47b61d7a7312df98
diff --git a/wscript b/wscript
index 200ccbf..f3061db 100644
--- a/wscript
+++ b/wscript
@@ -1,4 +1,24 @@
 # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+"""
+Copyright (c) 2014  University of Memphis,
+                    Regents of the University of California
+
+This file is part of NLSR (Named-data Link State Routing).
+See AUTHORS.md for complete list of NLSR authors and contributors.
+
+NLSR is free software: you can redistribute it and/or modify it under the terms
+of the GNU General Public License as published by the Free Software Foundation,
+either version 3 of the License, or (at your option) any later version.
+
+NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+PURPOSE.  See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+"""
+
 VERSION='1.0'
 NAME="NLSR"
 
@@ -6,75 +26,77 @@
 from waflib.Tools import c_preproc
 
 def options(opt):
-    opt.load('compiler_c compiler_cxx gnu_dirs c_osx')
-    opt.load('boost openssl cryptopp', tooldir=['waf-tools'])
+    opt.load(['compiler_cxx', 'gnu_dirs'])
+    opt.load(['default-compiler-flags', 'coverage',
+              'boost', 'protoc', 'openssl',
+              'doxygen', 'sphinx_build'],
+            tooldir=['.waf-tools'])
 
-    opt = opt.add_option_group('NLSR Options')
+    nlsropt = opt.add_option_group('NLSR Options')
 
-    opt.add_option('--debug',action='store_true',default=False,dest='debug',help='''debugging mode''')
+    nlsropt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
+                       help='''build unit tests''')
 
 
 def configure(conf):
-    conf.load("compiler_c compiler_cxx boost gnu_dirs c_osx openssl cryptopp")
+    conf.load("compiler_cxx gnu_dirs boost openssl")
 
-    conf.check_openssl()
+    conf.load('default-compiler-flags')
 
-    if conf.options.debug:
-        conf.define ('_DEBUG', 1)
-        flags = ['-O0',
-                 '-Wall',
-                 # '-Werror',
-                 '-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.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'],
+                   uselib_store='NDN_CPP', mandatory=True)
 
-                 '-Wno-deprecated-declarations',
-                 ]
+    boost_libs = 'system chrono program_options log iostreams thread'
+    if conf.options.with_tests:
+        conf.env['WITH_TESTS'] = 1
+        conf.define('WITH_TESTS', 1);
+        boost_libs += ' unit_test_framework'
 
-        conf.add_supported_cxxflags (cxxflags = flags)
-    else:
-        flags = ['-O3', '-g', '-Wno-tautological-compare', '-Wno-unused-function', '-Wno-deprecated-declarations']
-        conf.add_supported_cxxflags (cxxflags = flags)
+    conf.check_boost(lib=boost_libs)
 
-
-    conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'], uselib_store='NDN_CPP', mandatory=True)
-    conf.check_cfg(package='nsync', args=['--cflags', '--libs'], uselib_store='nsync', mandatory=True)
-    conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3', mandatory=True)
-    conf.check_cryptopp(path=conf.options.cryptopp_dir, mandatory=True)
-    conf.check_boost(lib='system iostreams thread unit_test_framework log', uselib_store='BOOST', mandatory=True)
     if conf.env.BOOST_VERSION_NUMBER < 105400:
-        Logs.error ("Minimum required boost version is 1.54.0")
-        Logs.error ("Please upgrade your distribution or install custom boost libraries")
+        Logs.error("Minimum required boost version is 1.54.0")
+        Logs.error("Please upgrade your distribution or install custom boost libraries")
         return
 
+    conf.load('protoc')
 
+    conf.load('coverage')
+
+    conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR'])
+
+    conf.write_config_header('config.hpp')
 
 
 def build (bld):
-    bld (
-        features=['cxx', 'cxxprogram'],
-        target="nlsr",
-        source = bld.path.ant_glob('src/**/*.cpp'),
-        use = 'NDN_CPP BOOST CRYPTOPP SQLITE3 nsync',
-        includes = ". src"
+    nsync_objects = bld(
+        target='nsync-objects',
+        name='nsync-objects',
+        features='cxx',
+        source=bld.path.ant_glob(['nsync/**/*.cc', 'nsync/**/*.proto']),
+        use='BOOST NDN_CPP OPENSSL',
+        includes='nsync',
+        export_includes='nsync',
         )
-    bld.recurse("CertTool")
 
-@Configure.conf
-def add_supported_cxxflags(self, cxxflags):
-    """
-    Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
-    """
-    self.start_msg('Checking allowed flags for c++ compiler')
+    nlsr_objects = bld(
+        target='nlsr-objects',
+        name='nlsr-objects',
+        features='cxx',
+        source=bld.path.ant_glob(['src/**/*.cpp'],
+                                 excl=['src/main.cpp']),
+        use='nsync-objects NDN_CPP BOOST',
+        includes='. src',
+        export_includes='. src',
+        )
 
-    supportedFlags = []
-    for flag in cxxflags:
-        if self.check_cxx (cxxflags=[flag], mandatory=False):
-            supportedFlags += [flag]
+    nlsr = bld(
+        target='bin/nlsr',
+        features='cxx cxxprogram',
+        source='src/main.cpp',
+        use='nlsr-objects',
+        )
 
-    self.end_msg (' '.join (supportedFlags))
-    self.env.CXXFLAGS += supportedFlags
+    if bld.env['WITH_TESTS']:
+        bld.recurse('tests')
+        bld.recurse('tests-integrated')