blob: cc94ade74ba070128a6c7f36b2b74d446e1089cd [file] [log] [blame]
Ilya Moiseenko1762af72011-07-18 16:43:10 -07001## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
Alexander Afanasyev45b92d42011-08-14 23:11:38 -07003import os
Alexander Afanasyev152660b2013-01-08 09:33:05 -08004from waflib import Logs, Utils, Options, TaskGen, Task
Alexander Afanasyev9de011f2011-11-11 00:55:05 -08005from waflib.Errors import WafError
6
Alexander Afanasyeva65ab322012-10-23 21:43:39 -07007import wutils
8
Alexander Afanasyevb66a89b2013-05-05 00:20:12 -07009REQUIRED_BOOST_LIBS = ['graph']
Alexander Afanasyev3b936292011-09-20 08:45:36 -070010
Alexander Afanasyev152660b2013-01-08 09:33:05 -080011def required_boost_libs(conf):
12 conf.env.REQUIRED_BOOST_LIBS += REQUIRED_BOOST_LIBS
13
Alexander Afanasyev8e60bcd2015-01-15 20:55:40 +000014def options(opt):
15 opt.load(['dependency-checker',
16 'doxygen', 'sphinx_build', 'type_traits', 'compiler-features'],
17 tooldir=['%s/.waf-tools' % opt.path.abspath()])
18
Alexander Afanasyev152660b2013-01-08 09:33:05 -080019def configure(conf):
Alexander Afanasyev8e60bcd2015-01-15 20:55:40 +000020 conf.load(['dependency-checker',
21 'doxygen', 'sphinx_build', 'type_traits', 'compiler-features'])
22
23 conf.env['ENABLE_NDNSIM']=False
Alexander Afanasyev1bfce322012-11-23 21:38:02 -080024
Alexander Afanasyevce308b62015-01-20 18:17:28 -080025 if not os.environ.has_key('PKG_CONFIG_PATH'):
26 os.environ['PKG_CONFIG_PATH'] = ':'.join([
27 '/usr/local/lib/pkgconfig',
28 '/opt/local/lib/pkgconfig'])
Alexander Afanasyev60c04622014-12-29 20:43:22 -080029 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
30 uselib_store='NDN_CXX', mandatory=True)
31
Alexander Afanasyev3b936292011-09-20 08:45:36 -070032 if not conf.env['LIB_BOOST']:
Alexander Afanasyev1bfce322012-11-23 21:38:02 -080033 conf.report_optional_feature("ndnSIM", "ndnSIM", False,
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070034 "Required boost libraries not found")
Alexander Afanasyev9ab7d672013-08-11 11:02:52 -070035 Logs.error ("ndnSIM will not be build as it requires boost libraries of version at least 1.48")
Alexander Afanasyev57bcbc32012-06-01 01:46:24 -070036 conf.env['MODULES_NOT_BUILT'].append('ndnSIM')
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070037 return
Alexander Afanasyev1bfce322012-11-23 21:38:02 -080038 else:
Alexander Afanasyev152660b2013-01-08 09:33:05 -080039 present_boost_libs = []
40 for boost_lib_name in conf.env['LIB_BOOST']:
41 if boost_lib_name.startswith("boost_"):
42 boost_lib_name = boost_lib_name[6:]
43 if boost_lib_name.endswith("-mt"):
44 boost_lib_name = boost_lib_name[:-3]
Alexander Afanasyevcd38c842013-05-05 00:24:41 -070045 present_boost_libs.append(boost_lib_name)
Alexander Afanasyev152660b2013-01-08 09:33:05 -080046
47 missing_boost_libs = [lib for lib in REQUIRED_BOOST_LIBS if lib not in present_boost_libs]
Alexander Afanasyevb4921ec2013-08-07 17:45:01 -070048
Alexander Afanasyev152660b2013-01-08 09:33:05 -080049 if missing_boost_libs != []:
50 conf.report_optional_feature("ndnSIM", "ndnSIM", False,
51 "ndnSIM requires boost libraries: %s" % ' '.join(missing_boost_libs))
52 conf.env['MODULES_NOT_BUILT'].append('ndnSIM')
53
54 Logs.error ("ndnSIM will not be build as it requires boost libraries: %s" % ' '.join(missing_boost_libs))
55 Logs.error ("Please upgrade your distribution or install custom boost libraries (http://ndnsim.net/faq.html#boost-libraries)")
56 return
Alexander Afanasyevb4921ec2013-08-07 17:45:01 -070057
Alexander Afanasyev1bfce322012-11-23 21:38:02 -080058 boost_version = conf.env.BOOST_VERSION.split('_')
Alexander Afanasyev9ab7d672013-08-11 11:02:52 -070059 if int(boost_version[0]) < 1 or int(boost_version[1]) < 48:
Alexander Afanasyev1bfce322012-11-23 21:38:02 -080060 conf.report_optional_feature("ndnSIM", "ndnSIM", False,
Alexander Afanasyev9ab7d672013-08-11 11:02:52 -070061 "ndnSIM requires at least boost version 1.48")
Alexander Afanasyev1bfce322012-11-23 21:38:02 -080062 conf.env['MODULES_NOT_BUILT'].append('ndnSIM')
63
Alexander Afanasyev9ab7d672013-08-11 11:02:52 -070064 Logs.error ("ndnSIM will not be build as it requires boost libraries of version at least 1.48")
Alexander Afanasyev1bfce322012-11-23 21:38:02 -080065 Logs.error ("Please upgrade your distribution or install custom boost libraries (http://ndnsim.net/faq.html#boost-libraries)")
66 return
Alexander Afanasyevac46d452012-05-31 15:33:21 -070067
Alexander Afanasyev1bfce322012-11-23 21:38:02 -080068 conf.env['ENABLE_NDNSIM']=True;
69 conf.env['MODULES_BUILT'].append('ndnSIM')
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070070
Alexander Afanasyev1bfce322012-11-23 21:38:02 -080071 conf.report_optional_feature("ndnSIM", "ndnSIM", True, "")
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070072
Ilya Moiseenko1762af72011-07-18 16:43:10 -070073def build(bld):
Alexander Afanasyev60c04622014-12-29 20:43:22 -080074 deps = ['core', 'network', 'point-to-point', 'topology-read', 'mobility', 'internet']
Alexander Afanasyev0d584e32013-08-13 10:41:42 -070075 if 'ns3-visualizer' in bld.env['NS3_ENABLED_MODULES']:
Alexander Afanasyev60c04622014-12-29 20:43:22 -080076 deps.append('visualizer')
Alexander Afanasyev3bea3702011-11-16 10:27:18 -080077
Alexander Afanasyev60c04622014-12-29 20:43:22 -080078 if bld.env.ENABLE_EXAMPLES:
Alexander Afanasyev15db7722015-01-19 17:27:26 -080079 deps += ['point-to-point-layout', 'csma', 'applications', 'wifi']
Alexander Afanasyev4a3b2be2012-06-29 14:29:13 -070080
Alexander Afanasyev57bcbc32012-06-01 01:46:24 -070081 module = bld.create_ns3_module ('ndnSIM', deps)
Alexander Afanasyev59314802012-11-26 14:56:04 -080082 module.module = 'ndnSIM'
Alexander Afanasyev152660b2013-01-08 09:33:05 -080083 module.features += ' ns3fullmoduleheaders'
Alexander Afanasyev60c04622014-12-29 20:43:22 -080084 module.uselib = 'NDN_CXX BOOST'
85 module.includes = [".", "./NFD", "./NFD/daemon", "./NFD/core"]
86 module.export_includes = [".", "./NFD", "./NFD/daemon", "./NFD/core"]
Alexander Afanasyev404c0792011-08-09 17:09:59 -070087
Alexander Afanasyev152660b2013-01-08 09:33:05 -080088 headers = bld (features='ns3header')
Alexander Afanasyev57bcbc32012-06-01 01:46:24 -070089 headers.module = 'ndnSIM'
Alexander Afanasyev60c04622014-12-29 20:43:22 -080090 headers.source = ["ndn-all.hpp"]
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070091
Alexander Afanasyev1bfce322012-11-23 21:38:02 -080092 if not bld.env['ENABLE_NDNSIM']:
Alexander Afanasyev57bcbc32012-06-01 01:46:24 -070093 bld.env['MODULES_NOT_BUILT'].append('ndnSIM')
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070094 return
Alexander Afanasyev957a84a2013-01-23 10:21:06 -080095
Alexander Afanasyev60c04622014-12-29 20:43:22 -080096 module_dirs = ['NFD', 'apps', 'helper', 'model', 'utils']
Spyridon Mastorakisb4bd4b72015-01-05 17:41:12 -080097
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070098 module.source = bld.path.ant_glob(['%s/**/*.cpp' % dir for dir in module_dirs],
Alexander Afanasyevdca091a2015-01-01 20:51:27 -080099 excl=['model/ip-faces/*'])
Alexander Afanasyev2a5df202011-08-15 22:39:05 -0700100
Alexander Afanasyev60c04622014-12-29 20:43:22 -0800101 module.full_headers = [p.path_from(bld.path) for p in bld.path.ant_glob(
102 ['%s/**/*.hpp' % dir for dir in module_dirs])]
Alexander Afanasyev3b936292011-09-20 08:45:36 -0700103
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800104 if bld.env.ENABLE_EXAMPLES:
105 bld.recurse('examples')
Lucas64b85362012-01-30 16:28:37 -0800106
Spyridon Mastorakisb4bd4b72015-01-05 17:41:12 -0800107 if bld.env.ENABLE_TESTS:
108 bld.recurse('tests')
109
Alexander Afanasyev76b11572013-07-16 21:49:50 -0700110 bld.ns3_python_bindings()
Alexander Afanasyev59314802012-11-26 14:56:04 -0800111
Alexander Afanasyev59314802012-11-26 14:56:04 -0800112@TaskGen.feature('ns3fullmoduleheaders')
113@TaskGen.after_method('process_rule')
114def apply_ns3fullmoduleheaders(self):
115 # ## get all of the ns3 headers
Alexander Afanasyev1a62e612013-05-02 16:50:48 -0700116 ns3_dir_node = self.bld.path.find_or_declare("ns3")
Alexander Afanasyev59314802012-11-26 14:56:04 -0800117
118 mode = getattr(self, "mode", "install")
119
120 for filename in set(self.to_list(self.full_headers)):
121 src_node = self.path.find_resource(filename)
122 if src_node is None:
123 raise WafError("source ns3 header file %s not found" % (filename,))
124 dst_node = ns3_dir_node.find_or_declare(src_node.path_from(self.bld.path.find_dir('src')))
125 assert dst_node is not None
126
127 relpath = src_node.parent.path_from(self.bld.path.find_dir('src'))
128
129 task = self.create_task('ns3header')
130 task.mode = getattr(self, 'mode', 'install')
131 if task.mode == 'install':
Alexander Afanasyev957a84a2013-01-23 10:21:06 -0800132 self.bld.install_files('${INCLUDEDIR}/%s%s/ns3/%s' % (wutils.APPNAME, wutils.VERSION, relpath),
Alexander Afanasyev59314802012-11-26 14:56:04 -0800133 [src_node])
134 task.set_inputs([src_node])
135 task.set_outputs([dst_node])
136 else:
137 task.header_to_remove = dst_node