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 |
| 5 | |
| 6 | def options(opt): |
| 7 | opt.load('compiler_cxx') |
| 8 | opt.load('boost', tooldir=['.waf-tools']) |
| 9 | |
| 10 | nfdopt = opt.add_option_group('NFD Options') |
| 11 | nfdopt.add_option('--debug',action='store_true',default=False,dest='debug',help='''Compile library debugging mode without all optimizations (-O0)''') |
| 12 | nfdopt.add_option('--with-tests', action='store_true',default=False,dest='with_tests',help='''Build unit tests''') |
| 13 | nfdopt.add_option('--with-ndn-cpp',action='store',type='string',default=None,dest='ndn_cpp_dir', |
| 14 | help='''Use NDN-CPP library from the specified path''') |
| 15 | |
| 16 | def configure(conf): |
| 17 | conf.load("compiler_cxx boost") |
| 18 | |
| 19 | if conf.options.debug: |
| 20 | conf.define ('_DEBUG', 1) |
| 21 | conf.add_supported_cxxflags (cxxflags = ['-O0', |
| 22 | '-Wall', |
| 23 | '-Wno-unused-variable', |
| 24 | '-g3', |
| 25 | '-Wno-unused-private-field', # only clang supports |
| 26 | '-fcolor-diagnostics', # only clang supports |
| 27 | '-Qunused-arguments', # only clang supports |
| 28 | '-Wno-tautological-compare', # suppress warnings from CryptoPP |
| 29 | '-Wno-unused-function', # suppress warnings from CryptoPP |
| 30 | ]) |
| 31 | else: |
| 32 | conf.add_supported_cxxflags (cxxflags = ['-O3', '-g', '-Wno-tautological-compare', '-Wno-unused-function']) |
| 33 | |
| 34 | if not conf.options.ndn_cpp_dir: |
| 35 | conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'], uselib_store='NDN_CPP', mandatory=True) |
| 36 | else: |
| 37 | conf.check_cxx(lib='ndn-cpp-dev', uselib_store='NDN_CPP', |
| 38 | cxxflags="-I%s/include" % conf.options.ndn_cpp_dir, |
| 39 | linkflags="-L%s/lib" % conf.options.ndn_cpp_dir, |
| 40 | mandatory=True) |
| 41 | |
| 42 | boost_libs='system' |
| 43 | if conf.options.with_tests: |
| 44 | conf.env['WITH_TESTS'] = 1 |
| 45 | boost_libs+=' unit_test_framework' |
| 46 | |
| 47 | conf.check_boost(lib=boost_libs) |
| 48 | |
| 49 | boost_version = conf.env.BOOST_VERSION.split('_') |
| 50 | if int(boost_version[0]) < 1 or int(boost_version[1]) < 42: |
| 51 | Logs.error ("Minumum required boost version is 1.42") |
| 52 | return |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 53 | |
| 54 | conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False) |
| 55 | |
| 56 | conf.write_config_header('daemon/config.hpp') |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 57 | |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 58 | def build(bld): |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 59 | bld(target = "nfd-objects", |
| 60 | features = "cxx", |
| 61 | source = bld.path.ant_glob(['daemon/**/*.cpp'], excl=['daemon/main.cpp']), |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 62 | use = 'BOOST NDN_CPP RT', |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 63 | includes = [".", "daemon"], |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 64 | ) |
| 65 | |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 66 | bld(target = "nfd", |
| 67 | features = "cxx cxxprogram", |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 68 | source = 'daemon/main.cpp', |
| 69 | use = 'nfd-objects', |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 70 | includes = [".", "daemon"], |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 71 | ) |
| 72 | |
| 73 | # Unit tests |
| 74 | if bld.env['WITH_TESTS']: |
| 75 | unittests = bld.program ( |
| 76 | target="unit-tests", |
| 77 | features = "cxx cxxprogram", |
Junxiao Shi | 1a2a856 | 2014-01-23 10:07:59 -0700 | [diff] [blame] | 78 | source = bld.path.ant_glob(['tests/**/*.cpp']), |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 79 | use = 'nfd-objects', |
Junxiao Shi | 1a2a856 | 2014-01-23 10:07:59 -0700 | [diff] [blame] | 80 | includes = [".", "daemon"], |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 81 | install_prefix = None, |
| 82 | ) |
| 83 | |
| 84 | @Configure.conf |
| 85 | def add_supported_cxxflags(self, cxxflags): |
| 86 | """ |
| 87 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 88 | """ |
| 89 | self.start_msg('Checking allowed flags for c++ compiler') |
| 90 | |
| 91 | supportedFlags = [] |
| 92 | for flag in cxxflags: |
| 93 | if self.check_cxx (cxxflags=[flag], mandatory=False): |
| 94 | supportedFlags += [flag] |
| 95 | |
| 96 | self.end_msg (' '.join (supportedFlags)) |
| 97 | self.env.CXXFLAGS += supportedFlags |