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''') |
Steve DiBenedetto | 84da5bf | 2014-03-11 14:51:29 -0600 | [diff] [blame] | 14 | |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 15 | def configure(conf): |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 16 | conf.load("compiler_cxx boost gnu_dirs") |
Alexander Afanasyev | 35fc2b7 | 2014-02-13 16:56:21 -0800 | [diff] [blame] | 17 | try: |
| 18 | conf.load("doxygen") |
| 19 | except: |
| 20 | pass |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 21 | |
Alexander Afanasyev | efea8fe | 2014-03-23 00:00:35 -0700 | [diff] [blame^] | 22 | areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0) |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 23 | if conf.options.debug: |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 24 | conf.define('_DEBUG', 1) |
Alexander Afanasyev | efea8fe | 2014-03-23 00:00:35 -0700 | [diff] [blame^] | 25 | defaultFlags = ['-O0', '-g3', |
| 26 | '-Werror', |
| 27 | '-Wall', |
| 28 | '-fcolor-diagnostics', # only clang supports |
| 29 | ] |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | efea8fe | 2014-03-23 00:00:35 -0700 | [diff] [blame^] | 31 | if areCustomCxxflagsPresent: |
| 32 | missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS] |
| 33 | if len(missingFlags) > 0: |
| 34 | Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'" |
| 35 | % " ".join(conf.env.CXXFLAGS)) |
| 36 | Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags)) |
| 37 | else: |
| 38 | conf.add_supported_cxxflags(cxxflags = defaultFlags) |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 39 | else: |
Alexander Afanasyev | efea8fe | 2014-03-23 00:00:35 -0700 | [diff] [blame^] | 40 | defaultFlags = ['-O2', '-g', '-Wall'] |
| 41 | if not areCustomCxxflagsPresent: |
| 42 | conf.add_supported_cxxflags(cxxflags = defaultFlags) |
| 43 | |
| 44 | conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'], |
| 45 | uselib_store='NDN_CPP', mandatory=True) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 46 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 47 | boost_libs = 'system chrono program_options' |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 48 | if conf.options.with_tests: |
| 49 | conf.env['WITH_TESTS'] = 1 |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 50 | conf.define('WITH_TESTS', 1); |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 51 | boost_libs+=' unit_test_framework' |
| 52 | |
| 53 | conf.check_boost(lib=boost_libs) |
Steve DiBenedetto | 84da5bf | 2014-03-11 14:51:29 -0600 | [diff] [blame] | 54 | |
Alexander Afanasyev | e1724c4 | 2014-02-26 22:00:54 -0800 | [diff] [blame] | 55 | if conf.env.BOOST_VERSION_NUMBER < 104800: |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 56 | Logs.error("Minimum required boost version is 1.48.0") |
| 57 | Logs.error("Please upgrade your distribution or install custom boost libraries" + |
| 58 | " (http://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)") |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 59 | return |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 60 | |
| 61 | conf.load('unix-socket') |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 62 | |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 63 | 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] | 64 | if conf.check_cxx(lib='pcap', uselib_store='PCAP', define_name='HAVE_PCAP', mandatory=False): |
| 65 | conf.env['HAVE_PCAP'] = True |
Alexander Afanasyev | efea8fe | 2014-03-23 00:00:35 -0700 | [diff] [blame^] | 66 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 67 | conf.check_cxx(lib='resolv', uselib_store='RESOLV', mandatory=True) |
Alexander Afanasyev | efea8fe | 2014-03-23 00:00:35 -0700 | [diff] [blame^] | 68 | |
Alexander Afanasyev | 689569b | 2014-02-16 20:20:07 -0800 | [diff] [blame] | 69 | conf.load('coverage') |
| 70 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 71 | conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nfd.conf' % conf.env['SYSCONFDIR']) |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 72 | |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 73 | conf.write_config_header('daemon/config.hpp') |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 74 | |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 75 | def build(bld): |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 76 | nfd_objects = bld( |
| 77 | target = "nfd-objects", |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 78 | features = "cxx", |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 79 | source = bld.path.ant_glob(['daemon/**/*.cpp'], |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 80 | excl=['daemon/face/ethernet-*.cpp', |
| 81 | 'daemon/face/unix-*.cpp', |
| 82 | 'daemon/main.cpp']), |
Junxiao Shi | 61c5ef3 | 2014-01-24 20:59:30 -0700 | [diff] [blame] | 83 | use = 'BOOST NDN_CPP RT', |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 84 | includes = [".", "daemon"], |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 85 | ) |
| 86 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 87 | if bld.env['HAVE_PCAP']: |
| 88 | nfd_objects.source += bld.path.ant_glob('daemon/face/ethernet-*.cpp') |
| 89 | nfd_objects.use += ' PCAP' |
| 90 | |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 91 | if bld.env['HAVE_UNIX_SOCKETS']: |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 92 | nfd_objects.source += bld.path.ant_glob('daemon/face/unix-*.cpp') |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 93 | |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 94 | bld(target = "nfd", |
| 95 | features = "cxx cxxprogram", |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 96 | source = 'daemon/main.cpp', |
| 97 | use = 'nfd-objects', |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 98 | includes = [".", "daemon"], |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 99 | ) |
Steve DiBenedetto | 84da5bf | 2014-03-11 14:51:29 -0600 | [diff] [blame] | 100 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 101 | for app in bld.path.ant_glob('tools/*.cpp'): |
| 102 | bld(features=['cxx', 'cxxprogram'], |
| 103 | target = 'bin/%s' % (str(app.change_ext(''))), |
| 104 | source = ['tools/%s' % (str(app))], |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 105 | includes = [".", "daemon"], |
| 106 | use = 'nfd-objects RESOLV', |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 107 | ) |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 108 | |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 109 | # Unit tests |
| 110 | if bld.env['WITH_TESTS']: |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 111 | unit_tests = bld.program( |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 112 | target="unit-tests", |
| 113 | features = "cxx cxxprogram", |
| 114 | source = bld.path.ant_glob(['tests/**/*.cpp'], |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 115 | excl=['tests/face/ethernet.cpp', |
| 116 | 'tests/face/unix-*.cpp']), |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 117 | use = 'nfd-objects', |
| 118 | includes = [".", "daemon"], |
| 119 | install_prefix = None, |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 120 | ) |
| 121 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 122 | if bld.env['HAVE_PCAP']: |
| 123 | unit_tests.source += bld.path.ant_glob('tests/face/ethernet.cpp') |
| 124 | |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 125 | if bld.env['HAVE_UNIX_SOCKETS']: |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 126 | unit_tests.source += bld.path.ant_glob('tests/face/unix-*.cpp') |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 127 | |
Steve DiBenedetto | 84da5bf | 2014-03-11 14:51:29 -0600 | [diff] [blame] | 128 | bld(features = "subst", |
| 129 | source = 'nfd.conf.sample.in', |
| 130 | target = 'nfd.conf.sample', |
| 131 | install_path = "${SYSCONFDIR}/ndn") |
| 132 | |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 133 | @Configure.conf |
| 134 | def add_supported_cxxflags(self, cxxflags): |
| 135 | """ |
| 136 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 137 | """ |
| 138 | self.start_msg('Checking allowed flags for c++ compiler') |
| 139 | |
| 140 | supportedFlags = [] |
| 141 | for flag in cxxflags: |
Alexander Afanasyev | 35fc2b7 | 2014-02-13 16:56:21 -0800 | [diff] [blame] | 142 | if self.check_cxx(cxxflags=[flag], mandatory=False): |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 143 | supportedFlags += [flag] |
| 144 | |
Alexander Afanasyev | 35fc2b7 | 2014-02-13 16:56:21 -0800 | [diff] [blame] | 145 | self.end_msg(' '.join (supportedFlags)) |
Alexander Afanasyev | efea8fe | 2014-03-23 00:00:35 -0700 | [diff] [blame^] | 146 | self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS |
Alexander Afanasyev | 35fc2b7 | 2014-02-13 16:56:21 -0800 | [diff] [blame] | 147 | |
| 148 | # doxygen docs |
| 149 | from waflib.Build import BuildContext |
| 150 | class doxy(BuildContext): |
| 151 | cmd = "doxygen" |
| 152 | fun = "doxygen" |
| 153 | |
| 154 | def doxygen(bld): |
| 155 | if not bld.env.DOXYGEN: |
| 156 | bld.fatal("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
| 157 | bld(features="doxygen", |
| 158 | doxyfile='docs/doxygen.conf') |