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') |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 8 | opt.load('boost doxygen coverage unix-socket', tooldir=['.waf-tools']) |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 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") |
Alexander Afanasyev | 35fc2b7 | 2014-02-13 16:56:21 -0800 | [diff] [blame] | 18 | try: |
| 19 | conf.load("doxygen") |
| 20 | except: |
| 21 | pass |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 22 | |
| 23 | if conf.options.debug: |
| 24 | conf.define ('_DEBUG', 1) |
| 25 | conf.add_supported_cxxflags (cxxflags = ['-O0', |
| 26 | '-Wall', |
| 27 | '-Wno-unused-variable', |
| 28 | '-g3', |
| 29 | '-Wno-unused-private-field', # only clang supports |
| 30 | '-fcolor-diagnostics', # only clang supports |
| 31 | '-Qunused-arguments', # only clang supports |
| 32 | '-Wno-tautological-compare', # suppress warnings from CryptoPP |
| 33 | '-Wno-unused-function', # suppress warnings from CryptoPP |
| 34 | ]) |
| 35 | else: |
| 36 | conf.add_supported_cxxflags (cxxflags = ['-O3', '-g', '-Wno-tautological-compare', '-Wno-unused-function']) |
| 37 | |
| 38 | if not conf.options.ndn_cpp_dir: |
| 39 | conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'], uselib_store='NDN_CPP', mandatory=True) |
| 40 | else: |
| 41 | conf.check_cxx(lib='ndn-cpp-dev', uselib_store='NDN_CPP', |
| 42 | cxxflags="-I%s/include" % conf.options.ndn_cpp_dir, |
| 43 | linkflags="-L%s/lib" % conf.options.ndn_cpp_dir, |
| 44 | mandatory=True) |
| 45 | |
| 46 | boost_libs='system' |
| 47 | if conf.options.with_tests: |
| 48 | conf.env['WITH_TESTS'] = 1 |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 49 | conf.define('WITH_TESTS', 1); |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 50 | boost_libs+=' unit_test_framework' |
| 51 | |
| 52 | conf.check_boost(lib=boost_libs) |
| 53 | |
| 54 | boost_version = conf.env.BOOST_VERSION.split('_') |
| 55 | if int(boost_version[0]) < 1 or int(boost_version[1]) < 42: |
| 56 | Logs.error ("Minumum required boost version is 1.42") |
| 57 | return |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 58 | |
| 59 | conf.load('unix-socket') |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 60 | |
| 61 | conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False) |
| 62 | |
Alexander Afanasyev | 689569b | 2014-02-16 20:20:07 -0800 | [diff] [blame] | 63 | conf.load('coverage') |
| 64 | |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 65 | conf.write_config_header('daemon/config.hpp') |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 66 | |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 67 | def build(bld): |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 68 | nfd_objects = bld( |
| 69 | target = "nfd-objects", |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 70 | features = "cxx", |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 71 | source = bld.path.ant_glob(['daemon/**/*.cpp'], |
| 72 | excl=['daemon/**/unix-*.cpp', 'daemon/main.cpp']), |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 73 | use = 'BOOST NDN_CPP RT', |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 74 | includes = [".", "daemon"], |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 75 | ) |
| 76 | |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 77 | if bld.env['HAVE_UNIX_SOCKETS']: |
| 78 | nfd_objects.source += bld.path.ant_glob(['daemon/**/unix-*.cpp'], |
| 79 | excl=['daemon/main.cpp']) |
| 80 | |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 81 | bld(target = "nfd", |
| 82 | features = "cxx cxxprogram", |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 83 | source = 'daemon/main.cpp', |
| 84 | use = 'nfd-objects', |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 85 | includes = [".", "daemon"], |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 86 | ) |
| 87 | |
| 88 | # Unit tests |
| 89 | if bld.env['WITH_TESTS']: |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 90 | unit_tests = unittests = bld.program ( |
| 91 | target="unit-tests", |
| 92 | features = "cxx cxxprogram", |
| 93 | source = bld.path.ant_glob(['tests/**/*.cpp'], |
| 94 | excl=['tests/**/unix-*.cpp']), |
| 95 | use = 'nfd-objects', |
| 96 | includes = [".", "daemon"], |
| 97 | install_prefix = None, |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 98 | ) |
| 99 | |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 100 | if bld.env['HAVE_UNIX_SOCKETS']: |
| 101 | unit_tests.source += bld.path.ant_glob(['tests/**/unix-*.cpp']) |
| 102 | |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 103 | @Configure.conf |
| 104 | def add_supported_cxxflags(self, cxxflags): |
| 105 | """ |
| 106 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 107 | """ |
| 108 | self.start_msg('Checking allowed flags for c++ compiler') |
| 109 | |
| 110 | supportedFlags = [] |
| 111 | for flag in cxxflags: |
Alexander Afanasyev | 35fc2b7 | 2014-02-13 16:56:21 -0800 | [diff] [blame] | 112 | if self.check_cxx(cxxflags=[flag], mandatory=False): |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 113 | supportedFlags += [flag] |
| 114 | |
Alexander Afanasyev | 35fc2b7 | 2014-02-13 16:56:21 -0800 | [diff] [blame] | 115 | self.end_msg(' '.join (supportedFlags)) |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 116 | self.env.CXXFLAGS += supportedFlags |
Alexander Afanasyev | 35fc2b7 | 2014-02-13 16:56:21 -0800 | [diff] [blame] | 117 | |
| 118 | # doxygen docs |
| 119 | from waflib.Build import BuildContext |
| 120 | class doxy(BuildContext): |
| 121 | cmd = "doxygen" |
| 122 | fun = "doxygen" |
| 123 | |
| 124 | def doxygen(bld): |
| 125 | if not bld.env.DOXYGEN: |
| 126 | bld.fatal("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
| 127 | bld(features="doxygen", |
| 128 | doxyfile='docs/doxygen.conf') |