ndn-cxx+build+docs: Attaching ndn-cxx as a submodule

Based on ndn-cxx:commit:6fa52970f35a58df85dae9c1cca7be6c58ab7d0a (version 0.3.4)

Change-Id: I1f3e5bfcd09c7dd517862ccaf6abe169cf71ecd4
Refs: #3124
diff --git a/.gitmodules b/.gitmodules
index d01dda7..eda145d 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
 [submodule "NFD"]
 	path = NFD
 	url = https://github.com/named-data-ndnSIM/NFD
+[submodule "ndn-cxx"]
+	path = ndn-cxx
+	url = https://github.com/named-data-ndnSIM/ndn-cxx
diff --git a/.jenkins.d/02-deps-ndn-cxx.sh b/.jenkins.d/02-deps-ndn-cxx.sh
deleted file mode 100755
index bcd5364..0000000
--- a/.jenkins.d/02-deps-ndn-cxx.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/usr/bin/env bash
-set -x
-set -e
-
-JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
-source "$JDIR"/util.sh
-
-pushd /tmp >/dev/null
-
-INSTALLED_VERSION=$((cd ndn-cxx && git rev-parse HEAD) 2>/dev/null || echo NONE)
-
-sudo rm -Rf ndn-cxx-latest
-git clone --depth 1 git://github.com/named-data/ndn-cxx ndn-cxx-latest
-LATEST_VERSION=$((cd ndn-cxx-latest && git rev-parse HEAD) 2>/dev/null || echo UNKNOWN)
-
-if [[ $INSTALLED_VERSION != $LATEST_VERSION ]]; then
-    sudo rm -Rf ndn-cxx
-    mv ndn-cxx-latest ndn-cxx
-else
-    sudo rm -Rf ndn-cxx-latest
-fi
-
-sudo rm -Rf /usr/local/include/ndn-cxx
-sudo rm -f /usr/local/lib/libndn-cxx*
-sudo rm -f /usr/local/lib/pkgconfig/libndn-cxx*
-
-pushd ndn-cxx >/dev/null
-
-if has Ubuntu-12.04 $NODE_LABELS; then
-    EXTRA_FLAGS=" --boost-libs=/usr/lib/x86_64-linux-gnu"
-fi
-
-./waf configure -j1 --color=yes --enable-shared --disable-static --without-osx-keychain $EXTRA_FLAGS
-./waf -j1 --color=yes
-sudo ./waf install -j1 --color=yes
-
-popd >/dev/null
-popd >/dev/null
-
-if has Linux $NODE_LABELS; then
-    sudo ldconfig
-elif has FreeBSD $NODE_LABELS; then
-    sudo ldconfig -a
-fi
diff --git a/docs/source/getting-started.rst b/docs/source/getting-started.rst
index cea91d2..3adbd21 100644
--- a/docs/source/getting-started.rst
+++ b/docs/source/getting-started.rst
@@ -23,27 +23,18 @@
         sudo apt-get update
         sudo apt-get install libboost1.55-all-dev
 
-        # add  --boost-libs=/usr/lib/x86_64-linux-gnu  to ./waf configure for ndn-cxx and ns3
+        # add  --boost-libs=/usr/lib/x86_64-linux-gnu  to ./waf configure
         # ./waf configure --boost-libs=/usr/lib/x86_64-linux-gnu
 
     Make sure that all other version of boost libraries (``-dev`` packages) are removed,
     otherwise compilation will fail.
 
-.. note::
-   For ndnSIM properly work, ndn-cxx library must be build as a shared library. For example::
-
-       # download ndn-cxx
-       ./waf configure --enable-shared --disable-static
-       ./waf build
-       sudo ./waf install
-
 .. _requirements:
 
 Prerequisites
 -------------
 
-1. `ndnSIM also required ndn-cxx library and all of its prerequisites
-   <http://named-data.net/doc/ndn-cxx/current/INSTALL.html>`_.
+1. `ndn-cxx library prerequisites <http://named-data.net/doc/ndn-cxx/current/INSTALL.html>`__.
 
 .. role:: red
 
@@ -109,7 +100,6 @@
 
 ndnSIM package consists of three pieces:
 
-- `ndn-cxx library <http://named-data.net/doc/ndn-cxx/>`_
 - a custom branch of NS-3 that contains a few useful patches
 - a customized python binding generation library (necessary if you want to use NS-3's python
   bindings and/or visualizer module)
@@ -121,7 +111,6 @@
 
     mkdir ndnSIM
     cd ndnSIM
-    git clone https://github.com/named-data/ndn-cxx.git ndn-cxx
     git clone https://github.com/named-data-ndnSIM/ns-3-dev.git ns-3
     git clone https://github.com/named-data-ndnSIM/pybindgen.git pybindgen
     git clone --recursive https://github.com/named-data-ndnSIM/ndnSIM.git ns-3/src/ndnSIM
@@ -135,27 +124,6 @@
 Compiling and running ndnSIM
 ----------------------------
 
-- Compile and install ndn-cxx library
-
-    .. code-block:: bash
-
-        cd ndnSIM/ndn-cxx
-        ./waf configure --enable-shared --disable-static
-        ./waf
-        sudo ./waf install
-
-    .. note::
-       On Ubuntu platform you can also install ndn-cxx library from `NDN
-       PPA repository <http://named-data.net/doc/NFD/current/INSTALL.html#installing-nfd-from-binaries>`_
-
-       .. code-block:: bash
-
-           sudo apt-get install ndn-cxx-dev
-
-       If you are using ndn-cxx from PPA, please make sure that you do not have the existing installation
-       of ndn-cxx library compiled from source (e.g., in /usr/local).  Otherwise, the version mistmach
-       may result in compilation errors.
-
 - Compile NS-3 with ndnSIM module
 
     ndnSIM uses standard NS-3 compilation procedure.  Normally the following commands should be
diff --git a/ndn-cxx b/ndn-cxx
new file mode 160000
index 0000000..55d61d2
--- /dev/null
+++ b/ndn-cxx
@@ -0,0 +1 @@
+Subproject commit 55d61d2b42eebd056237e8d27d40c788a27c7d44
diff --git a/wscript b/wscript
index 53fc23f..494cd43 100644
--- a/wscript
+++ b/wscript
@@ -6,19 +6,19 @@
 
 import wutils
 
-REQUIRED_BOOST_LIBS = ['graph', 'unit_test_framework']
+REQUIRED_BOOST_LIBS = ['graph', 'thread', 'unit_test_framework',
+                       'system', 'random', 'date_time', 'iostreams', 'regex', 'program_options', 'chrono', 'filesystem']
 
 def required_boost_libs(conf):
     conf.env.REQUIRED_BOOST_LIBS += REQUIRED_BOOST_LIBS
 
 def options(opt):
-    opt.load(['dependency-checker',
-              'doxygen', 'sphinx_build', 'type_traits', 'compiler-features', 'version'],
-             tooldir=['%s/.waf-tools' % opt.path.abspath()])
+    opt.load(['version'], tooldir=['%s/.waf-tools' % opt.path.abspath()])
+    opt.load(['doxygen', 'sphinx_build', 'type_traits', 'compiler-features', 'cryptopp', 'sqlite3'],
+             tooldir=['%s/ndn-cxx/.waf-tools' % opt.path.abspath()])
 
 def configure(conf):
-    conf.load(['dependency-checker',
-               'doxygen', 'sphinx_build', 'type_traits', 'compiler-features', 'version'])
+    conf.load(['doxygen', 'sphinx_build', 'type_traits', 'compiler-features', 'version', 'cryptopp', 'sqlite3'])
 
     conf.env['ENABLE_NDNSIM']=False
 
@@ -28,8 +28,10 @@
             '/usr/local/lib64/pkgconfig',
             '/usr/local/lib32/pkgconfig',
             '/opt/local/lib/pkgconfig'])
-    conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
-                   uselib_store='NDN_CXX', mandatory=True)
+
+    conf.check_cxx(lib='pthread', uselib_store='PTHREAD', define_name='HAVE_PTHREAD', mandatory=False)
+    conf.check_sqlite3(mandatory=True)
+    conf.check_cryptopp(mandatory=True, use='PTHREAD')
 
     if not conf.env['LIB_BOOST']:
         conf.report_optional_feature("ndnSIM", "ndnSIM", False,
@@ -72,12 +74,24 @@
 
     conf.report_optional_feature("ndnSIM", "ndnSIM", True, "")
 
-    conf.write_config_header('NFD/config.hpp', remove=False)
+    conf.write_config_header('../../ns3/ndnSIM/ndn-cxx/ndn-cxx-config.hpp', define_prefix='NDN_CXX_', remove=False)
+    conf.write_config_header('../../ns3/ndnSIM/NFD/config.hpp', remove=False)
 
 def build(bld):
     (base, build, split) = bld.getVersion('NFD')
     bld(features="subst",
-        source='NFD/version.hpp.in', target='NFD/version.hpp',
+        name="version-NFD",
+        source='NFD/version.hpp.in', target='../../ns3/ndnSIM/NFD/version.hpp',
+        install_path=None,
+        VERSION_STRING=base,
+        VERSION_BUILD="%s-ndnSIM" % build,
+        VERSION=int(split[0]) * 1000000 + int(split[1]) * 1000 + int(split[2]),
+        VERSION_MAJOR=split[0], VERSION_MINOR=split[1], VERSION_PATCH=split[2])
+
+    (base, build, split) = bld.getVersion('ndn-cxx')
+    bld(features="subst",
+        name="version-ndn-cxx",
+        source='ndn-cxx/src/version.hpp.in', target='../../ns3/ndnSIM/ndn-cxx/version.hpp',
         install_path=None,
         VERSION_STRING=base,
         VERSION_BUILD="%s-ndnSIM" % build,
@@ -91,14 +105,29 @@
     if bld.env.ENABLE_EXAMPLES:
         deps += ['point-to-point-layout', 'csma', 'applications', 'wifi']
 
-    module = bld.create_ns3_module ('ndnSIM', deps)
-    module.module = 'ndnSIM'
-    module.features += ' ns3fullmoduleheaders'
-    module.use += ['NDN_CXX', 'BOOST']
-    module.includes = [".", "./NFD", "./NFD/daemon", "./NFD/core"]
-    module.export_includes = [".", "./NFD", "./NFD/daemon", "./NFD/core"]
+    ndnCxxSrc = bld.path.ant_glob('ndn-cxx/src/**/*.cpp',
+                                  excl=['ndn-cxx/src/**/*-osx.cpp',
+                                        'ndn-cxx/src/util/dummy-client-face.cpp'])
 
-    headers = bld (features='ns3header')
+    nfdSrc = bld.path.ant_glob(['%s/**/*.cpp' % dir for dir in ['NFD/core', 'NFD/daemon']],
+                               excl=['NFD/core/network-interface.cpp',
+                                     'NFD/daemon/main.cpp',
+                                     'NFD/daemon/nfd.cpp',
+                                     'NFD/daemon/face/ethernet*',
+                                     'NFD/daemon/face/multicast-udp*',
+                                     'NFD/daemon/face/tcp*',
+                                     'NFD/daemon/face/udp*',
+                                     'NFD/daemon/face/unix-stream*',
+                                     'NFD/daemon/face/websocket*'])
+
+    module = bld.create_ns3_module('ndnSIM', deps)
+    module.module = 'ndnSIM'
+    module.features += ' ns3fullmoduleheaders ndncxxheaders'
+    module.use += ['version-ndn-cxx', 'version-NFD', 'BOOST', 'CRYPTOPP', 'SQLITE3', 'RT', 'PTHREAD']
+    module.includes = ['../..', '../../ns3/ndnSIM/NFD', './NFD/core', './NFD/daemon', '../../ns3/ndnSIM', '../../ns3/ndnSIM/ndn-cxx']
+    module.export_includes = ['../../ns3/ndnSIM/NFD', './NFD/core', './NFD/daemon', '../../ns3/ndnSIM']
+
+    headers = bld(features='ns3header')
     headers.module = 'ndnSIM'
     headers.source = ["ndn-all.hpp"]
 
@@ -106,23 +135,16 @@
         bld.env['MODULES_NOT_BUILT'].append('ndnSIM')
         return
 
-    module_dirs = ['NFD/core', 'NFD/daemon', 'apps', 'helper', 'model', 'utils']
-
+    module_dirs = ['apps', 'helper', 'model', 'utils']
     module.source = bld.path.ant_glob(['%s/**/*.cpp' % dir for dir in module_dirs],
-                                      excl=['model/ip-faces/*',
-                                            'NFD/core/network-interface.cpp',
-                                            'NFD/daemon/main.cpp',
-                                            'NFD/daemon/nfd.*',
-                                            'NFD/daemon/face/ethernet*',
-                                            'NFD/daemon/face/multicast-udp*',
-                                            'NFD/daemon/face/tcp*',
-                                            'NFD/daemon/face/udp*',
-                                            'NFD/daemon/face/unix-stream*',
-                                            'NFD/daemon/face/websocket*'])
+                                      excl=['model/ip-faces/*']) + ndnCxxSrc + nfdSrc
 
-    module.full_headers = [p.path_from(bld.path) for p in bld.path.ant_glob(
-        ['%s/**/*.hpp' % dir for dir in module_dirs])]
+    module_dirs = ['NFD/core', 'NFD/daemon', 'apps', 'helper', 'model', 'utils']
+    module.full_headers = bld.path.ant_glob(['%s/**/*.hpp' % dir for dir in module_dirs])
+    module.full_headers += bld.path.ant_glob('NFD/common.hpp')
 
+    module.ndncxx_headers = bld.path.ant_glob(['ndn-cxx/src/**/*.hpp'],
+                                              excl=['src/**/*-osx.hpp', 'src/detail/**/*'])
     if bld.env.ENABLE_EXAMPLES:
         bld.recurse('examples')
 
@@ -139,10 +161,7 @@
 
     mode = getattr(self, "mode", "install")
 
-    for filename in set(self.to_list(self.full_headers)):
-        src_node = self.path.find_resource(filename)
-        if src_node is None:
-            raise WafError("source ns3 header file %s not found" % (filename,))
+    for src_node in set(self.full_headers):
         dst_node = ns3_dir_node.find_or_declare(src_node.path_from(self.bld.path.find_dir('src')))
         assert dst_node is not None
 
@@ -157,3 +176,27 @@
             task.set_outputs([dst_node])
         else:
             task.header_to_remove = dst_node
+
+@TaskGen.feature('ndncxxheaders')
+@TaskGen.after_method('process_rule')
+def apply_ndnsim_moduleheaders(self):
+    # ## get all of the ns3 headers
+    ndncxx_dir_node = self.bld.path.find_or_declare("ns3/ndnSIM/ndn-cxx")
+
+    mode = getattr(self, "mode", "install")
+
+    for src_node in set(self.ndncxx_headers):
+        dst_node = ndncxx_dir_node.find_or_declare(src_node.path_from(self.bld.path.find_dir('src/ndnSIM/ndn-cxx/src')))
+        assert dst_node is not None
+
+        relpath = src_node.parent.path_from(self.bld.path.find_dir('src/ndnSIM/ndn-cxx/src'))
+
+        task = self.create_task('ns3header')
+        task.mode = getattr(self, 'mode', 'install')
+        if task.mode == 'install':
+            self.bld.install_files('${INCLUDEDIR}/%s%s/ns3/ndnSIM/ndn-cxx/%s' % (wutils.APPNAME, wutils.VERSION, relpath),
+                                   [src_node])
+            task.set_inputs([src_node])
+            task.set_outputs([dst_node])
+        else:
+            task.header_to_remove = dst_node