blob: 77b8e8044d946f870b0a811a7a6713bbbd5155bc [file] [log] [blame]
Alexander Afanasyev2aa39622014-01-22 11:51:11 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2VERSION='0.1'
3
4from waflib import Build, Logs, Utils, Task, TaskGen, Configure
hilata198cadb2014-02-15 23:46:19 -06005import os
Alexander Afanasyev2aa39622014-01-22 11:51:11 -08006
7def options(opt):
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07008 opt.load('compiler_cxx gnu_dirs')
Alexander Afanasyevc78b1412014-02-19 14:08:26 -08009 opt.load('boost doxygen coverage unix-socket', tooldir=['.waf-tools'])
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080010
11 nfdopt = opt.add_option_group('NFD Options')
12 nfdopt.add_option('--debug',action='store_true',default=False,dest='debug',help='''Compile library debugging mode without all optimizations (-O0)''')
13 nfdopt.add_option('--with-tests', action='store_true',default=False,dest='with_tests',help='''Build unit tests''')
14 nfdopt.add_option('--with-ndn-cpp',action='store',type='string',default=None,dest='ndn_cpp_dir',
15 help='''Use NDN-CPP library from the specified path''')
Steve DiBenedetto84da5bf2014-03-11 14:51:29 -060016
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080017def configure(conf):
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070018 conf.load("compiler_cxx boost gnu_dirs")
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -080019 try:
20 conf.load("doxygen")
21 except:
22 pass
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080023
24 if conf.options.debug:
Junxiao Shiea48d8b2014-03-16 13:53:47 -070025 conf.define('_DEBUG', 1)
26 conf.add_supported_cxxflags(cxxflags = ['-O0',
27 '-Wall',
28 '-Wno-unused-variable',
29 '-g3',
30 '-Wno-unused-private-field', # only clang supports
31 '-fcolor-diagnostics', # only clang supports
32 '-Qunused-arguments', # only clang supports
33 '-Wno-tautological-compare', # suppress warnings from CryptoPP
34 '-Wno-unused-function', # suppress warnings from CryptoPP
35 '-fno-inline',
36 ])
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080037 else:
Junxiao Shiea48d8b2014-03-16 13:53:47 -070038 conf.add_supported_cxxflags(cxxflags = ['-O3', '-g', '-Wno-tautological-compare', '-Wno-unused-function'])
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080039
40 if not conf.options.ndn_cpp_dir:
41 conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'], uselib_store='NDN_CPP', mandatory=True)
42 else:
Steve DiBenedetto84da5bf2014-03-11 14:51:29 -060043 conf.check_cxx(lib='ndn-cpp-dev', uselib_store='NDN_CPP',
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080044 cxxflags="-I%s/include" % conf.options.ndn_cpp_dir,
45 linkflags="-L%s/lib" % conf.options.ndn_cpp_dir,
46 mandatory=True)
Davide Pesavento44deacc2014-02-19 10:48:07 +010047
Alexander Afanasyev82afa1a2014-03-20 16:56:56 -070048 boost_libs = 'system chrono program_options'
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080049 if conf.options.with_tests:
50 conf.env['WITH_TESTS'] = 1
Junxiao Shi88884492014-02-15 15:57:43 -070051 conf.define('WITH_TESTS', 1);
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080052 boost_libs+=' unit_test_framework'
53
54 conf.check_boost(lib=boost_libs)
Steve DiBenedetto84da5bf2014-03-11 14:51:29 -060055
Alexander Afanasyeve1724c42014-02-26 22:00:54 -080056 if conf.env.BOOST_VERSION_NUMBER < 104800:
Junxiao Shiea48d8b2014-03-16 13:53:47 -070057 Logs.error("Minimum required boost version is 1.48.0")
58 Logs.error("Please upgrade your distribution or install custom boost libraries" +
59 " (http://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)")
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080060 return
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080061
62 conf.load('unix-socket')
Davide Pesavento44deacc2014-02-19 10:48:07 +010063
Junxiao Shi61c5ef32014-01-24 20:59:30 -070064 conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False)
Davide Pesavento44deacc2014-02-19 10:48:07 +010065 if conf.check_cxx(lib='pcap', uselib_store='PCAP', define_name='HAVE_PCAP', mandatory=False):
66 conf.env['HAVE_PCAP'] = True
hilatadd50ada2014-03-13 12:48:47 -050067
68 conf.check_cxx(lib='resolv', uselib_store='RESOLV', mandatory=True)
69
Alexander Afanasyev689569b2014-02-16 20:20:07 -080070 conf.load('coverage')
71
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060072 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nfd.conf' % conf.env['SYSCONFDIR'])
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070073
Junxiao Shi61c5ef32014-01-24 20:59:30 -070074 conf.write_config_header('daemon/config.hpp')
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080075
Junxiao Shi09bf7c42014-01-31 11:10:25 -070076def build(bld):
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080077 nfd_objects = bld(
78 target = "nfd-objects",
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070079 features = "cxx",
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080080 source = bld.path.ant_glob(['daemon/**/*.cpp'],
Davide Pesavento44deacc2014-02-19 10:48:07 +010081 excl=['daemon/face/ethernet-*.cpp',
82 'daemon/face/unix-*.cpp',
83 'daemon/main.cpp']),
Junxiao Shi61c5ef32014-01-24 20:59:30 -070084 use = 'BOOST NDN_CPP RT',
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080085 includes = [".", "daemon"],
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070086 )
87
Davide Pesavento44deacc2014-02-19 10:48:07 +010088 if bld.env['HAVE_PCAP']:
89 nfd_objects.source += bld.path.ant_glob('daemon/face/ethernet-*.cpp')
90 nfd_objects.use += ' PCAP'
91
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080092 if bld.env['HAVE_UNIX_SOCKETS']:
Davide Pesavento44deacc2014-02-19 10:48:07 +010093 nfd_objects.source += bld.path.ant_glob('daemon/face/unix-*.cpp')
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080094
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080095 bld(target = "nfd",
96 features = "cxx cxxprogram",
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070097 source = 'daemon/main.cpp',
98 use = 'nfd-objects',
Junxiao Shi09bf7c42014-01-31 11:10:25 -070099 includes = [".", "daemon"],
hilata198cadb2014-02-15 23:46:19 -0600100 )
Steve DiBenedetto84da5bf2014-03-11 14:51:29 -0600101
hilata198cadb2014-02-15 23:46:19 -0600102 for app in bld.path.ant_glob('tools/*.cpp'):
103 bld(features=['cxx', 'cxxprogram'],
104 target = 'bin/%s' % (str(app.change_ext(''))),
105 source = ['tools/%s' % (str(app))],
Alexander Afanasyev82afa1a2014-03-20 16:56:56 -0700106 includes = [".", "daemon"],
107 use = 'nfd-objects RESOLV',
hilata198cadb2014-02-15 23:46:19 -0600108 )
Davide Pesavento44deacc2014-02-19 10:48:07 +0100109
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800110 # Unit tests
111 if bld.env['WITH_TESTS']:
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700112 unit_tests = bld.program(
Alexander Afanasyevc78b1412014-02-19 14:08:26 -0800113 target="unit-tests",
114 features = "cxx cxxprogram",
115 source = bld.path.ant_glob(['tests/**/*.cpp'],
Davide Pesavento44deacc2014-02-19 10:48:07 +0100116 excl=['tests/face/ethernet.cpp',
117 'tests/face/unix-*.cpp']),
Alexander Afanasyevc78b1412014-02-19 14:08:26 -0800118 use = 'nfd-objects',
119 includes = [".", "daemon"],
120 install_prefix = None,
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800121 )
122
Davide Pesavento44deacc2014-02-19 10:48:07 +0100123 if bld.env['HAVE_PCAP']:
124 unit_tests.source += bld.path.ant_glob('tests/face/ethernet.cpp')
125
Alexander Afanasyevc78b1412014-02-19 14:08:26 -0800126 if bld.env['HAVE_UNIX_SOCKETS']:
Davide Pesavento44deacc2014-02-19 10:48:07 +0100127 unit_tests.source += bld.path.ant_glob('tests/face/unix-*.cpp')
Alexander Afanasyevc78b1412014-02-19 14:08:26 -0800128
Steve DiBenedetto84da5bf2014-03-11 14:51:29 -0600129 bld(features = "subst",
130 source = 'nfd.conf.sample.in',
131 target = 'nfd.conf.sample',
132 install_path = "${SYSCONFDIR}/ndn")
133
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800134@Configure.conf
135def add_supported_cxxflags(self, cxxflags):
136 """
137 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
138 """
139 self.start_msg('Checking allowed flags for c++ compiler')
140
141 supportedFlags = []
142 for flag in cxxflags:
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800143 if self.check_cxx(cxxflags=[flag], mandatory=False):
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800144 supportedFlags += [flag]
145
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800146 self.end_msg(' '.join (supportedFlags))
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800147 self.env.CXXFLAGS += supportedFlags
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800148
149# doxygen docs
150from waflib.Build import BuildContext
151class doxy(BuildContext):
152 cmd = "doxygen"
153 fun = "doxygen"
154
155def doxygen(bld):
156 if not bld.env.DOXYGEN:
157 bld.fatal("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
158 bld(features="doxygen",
159 doxyfile='docs/doxygen.conf')