Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | VERSION='0.1' |
| 3 | |
| 4 | from waflib import Build, Logs, Utils, Task, TaskGen, Configure |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 5 | import os |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 6 | |
| 7 | def options(opt): |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame^] | 8 | opt.load('compiler_cxx gnu_dirs') |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 9 | opt.load('boost doxygen coverage unix-socket', tooldir=['.waf-tools']) |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 10 | |
| 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''') |
| 16 | |
| 17 | def configure(conf): |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame^] | 18 | conf.load("compiler_cxx boost gnu_dirs") |
Alexander Afanasyev | 35fc2b7 | 2014-02-13 16:56:21 -0800 | [diff] [blame] | 19 | try: |
| 20 | conf.load("doxygen") |
| 21 | except: |
| 22 | pass |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 23 | |
| 24 | if conf.options.debug: |
| 25 | 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 |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 35 | '-fno-inline', |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 36 | ]) |
| 37 | else: |
| 38 | conf.add_supported_cxxflags (cxxflags = ['-O3', '-g', '-Wno-tautological-compare', '-Wno-unused-function']) |
| 39 | |
| 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: |
| 43 | conf.check_cxx(lib='ndn-cpp-dev', uselib_store='NDN_CPP', |
| 44 | cxxflags="-I%s/include" % conf.options.ndn_cpp_dir, |
| 45 | linkflags="-L%s/lib" % conf.options.ndn_cpp_dir, |
| 46 | mandatory=True) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 47 | |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 48 | boost_libs='system' |
| 49 | if conf.options.with_tests: |
| 50 | conf.env['WITH_TESTS'] = 1 |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 51 | conf.define('WITH_TESTS', 1); |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 52 | boost_libs+=' unit_test_framework' |
| 53 | |
| 54 | conf.check_boost(lib=boost_libs) |
| 55 | |
Alexander Afanasyev | e1724c4 | 2014-02-26 22:00:54 -0800 | [diff] [blame] | 56 | if conf.env.BOOST_VERSION_NUMBER < 104800: |
| 57 | Logs.error ("Minimum required boost version is 1.48.0") |
Alexander Afanasyev | bfd31de | 2014-02-26 13:20:08 -0800 | [diff] [blame] | 58 | Logs.error ("Please upgrade your distribution or install custom boost libraries" + |
| 59 | " (http://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)") |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 60 | return |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 61 | |
| 62 | conf.load('unix-socket') |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 63 | |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 64 | conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 65 | if conf.check_cxx(lib='pcap', uselib_store='PCAP', define_name='HAVE_PCAP', mandatory=False): |
| 66 | conf.env['HAVE_PCAP'] = True |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 67 | |
Alexander Afanasyev | 689569b | 2014-02-16 20:20:07 -0800 | [diff] [blame] | 68 | conf.load('coverage') |
| 69 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame^] | 70 | conf.define('DEFAULT_CONFIG_FILE', '%s/nfd/nfd.conf' % conf.env['SYSCONFDIR']) |
| 71 | |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 72 | conf.write_config_header('daemon/config.hpp') |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 73 | |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 74 | def build(bld): |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 75 | nfd_objects = bld( |
| 76 | target = "nfd-objects", |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 77 | features = "cxx", |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 78 | source = bld.path.ant_glob(['daemon/**/*.cpp'], |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 79 | excl=['daemon/face/ethernet-*.cpp', |
| 80 | 'daemon/face/unix-*.cpp', |
| 81 | 'daemon/main.cpp']), |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 82 | use = 'BOOST NDN_CPP RT', |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 83 | includes = [".", "daemon"], |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 84 | ) |
| 85 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 86 | if bld.env['HAVE_PCAP']: |
| 87 | nfd_objects.source += bld.path.ant_glob('daemon/face/ethernet-*.cpp') |
| 88 | nfd_objects.use += ' PCAP' |
| 89 | |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 90 | if bld.env['HAVE_UNIX_SOCKETS']: |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 91 | nfd_objects.source += bld.path.ant_glob('daemon/face/unix-*.cpp') |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 92 | |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 93 | bld(target = "nfd", |
| 94 | features = "cxx cxxprogram", |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 95 | source = 'daemon/main.cpp', |
| 96 | use = 'nfd-objects', |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 97 | includes = [".", "daemon"], |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 98 | ) |
| 99 | |
| 100 | for app in bld.path.ant_glob('tools/*.cpp'): |
| 101 | bld(features=['cxx', 'cxxprogram'], |
| 102 | target = 'bin/%s' % (str(app.change_ext(''))), |
| 103 | source = ['tools/%s' % (str(app))], |
| 104 | use = 'BOOST NDN_CPP RT', |
| 105 | ) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 106 | |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 107 | # Unit tests |
| 108 | if bld.env['WITH_TESTS']: |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 109 | unit_tests = unittests = bld.program( |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 110 | target="unit-tests", |
| 111 | features = "cxx cxxprogram", |
| 112 | source = bld.path.ant_glob(['tests/**/*.cpp'], |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 113 | excl=['tests/face/ethernet.cpp', |
| 114 | 'tests/face/unix-*.cpp']), |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 115 | use = 'nfd-objects', |
| 116 | includes = [".", "daemon"], |
| 117 | install_prefix = None, |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 118 | ) |
| 119 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 120 | if bld.env['HAVE_PCAP']: |
| 121 | unit_tests.source += bld.path.ant_glob('tests/face/ethernet.cpp') |
| 122 | |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 123 | if bld.env['HAVE_UNIX_SOCKETS']: |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 124 | unit_tests.source += bld.path.ant_glob('tests/face/unix-*.cpp') |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 125 | |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 126 | @Configure.conf |
| 127 | def add_supported_cxxflags(self, cxxflags): |
| 128 | """ |
| 129 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 130 | """ |
| 131 | self.start_msg('Checking allowed flags for c++ compiler') |
| 132 | |
| 133 | supportedFlags = [] |
| 134 | for flag in cxxflags: |
Alexander Afanasyev | 35fc2b7 | 2014-02-13 16:56:21 -0800 | [diff] [blame] | 135 | if self.check_cxx(cxxflags=[flag], mandatory=False): |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 136 | supportedFlags += [flag] |
| 137 | |
Alexander Afanasyev | 35fc2b7 | 2014-02-13 16:56:21 -0800 | [diff] [blame] | 138 | self.end_msg(' '.join (supportedFlags)) |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 139 | self.env.CXXFLAGS += supportedFlags |
Alexander Afanasyev | 35fc2b7 | 2014-02-13 16:56:21 -0800 | [diff] [blame] | 140 | |
| 141 | # doxygen docs |
| 142 | from waflib.Build import BuildContext |
| 143 | class doxy(BuildContext): |
| 144 | cmd = "doxygen" |
| 145 | fun = "doxygen" |
| 146 | |
| 147 | def doxygen(bld): |
| 148 | if not bld.env.DOXYGEN: |
| 149 | bld.fatal("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
| 150 | bld(features="doxygen", |
| 151 | doxyfile='docs/doxygen.conf') |