blob: 30101747132c336e2ba37d3aa71e811c54034b48 [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''')
Steve DiBenedetto84da5bf2014-03-11 14:51:29 -060014
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080015def configure(conf):
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070016 conf.load("compiler_cxx boost gnu_dirs")
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -080017 try:
18 conf.load("doxygen")
19 except:
20 pass
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080021
Alexander Afanasyevefea8fe2014-03-23 00:00:35 -070022 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080023 if conf.options.debug:
Junxiao Shiea48d8b2014-03-16 13:53:47 -070024 conf.define('_DEBUG', 1)
Alexander Afanasyevefea8fe2014-03-23 00:00:35 -070025 defaultFlags = ['-O0', '-g3',
26 '-Werror',
27 '-Wall',
28 '-fcolor-diagnostics', # only clang supports
29 ]
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080030
Alexander Afanasyevefea8fe2014-03-23 00:00:35 -070031 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 Afanasyev2aa39622014-01-22 11:51:11 -080039 else:
Alexander Afanasyevefea8fe2014-03-23 00:00:35 -070040 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 Pesavento44deacc2014-02-19 10:48:07 +010046
Alexander Afanasyev82afa1a2014-03-20 16:56:56 -070047 boost_libs = 'system chrono program_options'
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080048 if conf.options.with_tests:
49 conf.env['WITH_TESTS'] = 1
Junxiao Shi88884492014-02-15 15:57:43 -070050 conf.define('WITH_TESTS', 1);
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080051 boost_libs+=' unit_test_framework'
52
53 conf.check_boost(lib=boost_libs)
Steve DiBenedetto84da5bf2014-03-11 14:51:29 -060054
Alexander Afanasyeve1724c42014-02-26 22:00:54 -080055 if conf.env.BOOST_VERSION_NUMBER < 104800:
Junxiao Shiea48d8b2014-03-16 13:53:47 -070056 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 Afanasyev2aa39622014-01-22 11:51:11 -080059 return
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080060
61 conf.load('unix-socket')
Davide Pesavento44deacc2014-02-19 10:48:07 +010062
Junxiao Shi61c5ef32014-01-24 20:59:30 -070063 conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False)
Davide Pesavento44deacc2014-02-19 10:48:07 +010064 if conf.check_cxx(lib='pcap', uselib_store='PCAP', define_name='HAVE_PCAP', mandatory=False):
65 conf.env['HAVE_PCAP'] = True
Alexander Afanasyevefea8fe2014-03-23 00:00:35 -070066
hilatadd50ada2014-03-13 12:48:47 -050067 conf.check_cxx(lib='resolv', uselib_store='RESOLV', mandatory=True)
Alexander Afanasyevefea8fe2014-03-23 00:00:35 -070068
Alexander Afanasyev689569b2014-02-16 20:20:07 -080069 conf.load('coverage')
70
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060071 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nfd.conf' % conf.env['SYSCONFDIR'])
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070072
Junxiao Shi61c5ef32014-01-24 20:59:30 -070073 conf.write_config_header('daemon/config.hpp')
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080074
Junxiao Shi09bf7c42014-01-31 11:10:25 -070075def build(bld):
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080076 nfd_objects = bld(
77 target = "nfd-objects",
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070078 features = "cxx",
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080079 source = bld.path.ant_glob(['daemon/**/*.cpp'],
Davide Pesavento44deacc2014-02-19 10:48:07 +010080 excl=['daemon/face/ethernet-*.cpp',
81 'daemon/face/unix-*.cpp',
82 'daemon/main.cpp']),
Junxiao Shi61c5ef32014-01-24 20:59:30 -070083 use = 'BOOST NDN_CPP RT',
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080084 includes = [".", "daemon"],
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070085 )
86
Davide Pesavento44deacc2014-02-19 10:48:07 +010087 if bld.env['HAVE_PCAP']:
88 nfd_objects.source += bld.path.ant_glob('daemon/face/ethernet-*.cpp')
89 nfd_objects.use += ' PCAP'
90
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080091 if bld.env['HAVE_UNIX_SOCKETS']:
Davide Pesavento44deacc2014-02-19 10:48:07 +010092 nfd_objects.source += bld.path.ant_glob('daemon/face/unix-*.cpp')
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080093
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080094 bld(target = "nfd",
95 features = "cxx cxxprogram",
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070096 source = 'daemon/main.cpp',
97 use = 'nfd-objects',
Junxiao Shi09bf7c42014-01-31 11:10:25 -070098 includes = [".", "daemon"],
hilata198cadb2014-02-15 23:46:19 -060099 )
Steve DiBenedetto84da5bf2014-03-11 14:51:29 -0600100
hilata198cadb2014-02-15 23:46:19 -0600101 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 Afanasyev82afa1a2014-03-20 16:56:56 -0700105 includes = [".", "daemon"],
106 use = 'nfd-objects RESOLV',
hilata198cadb2014-02-15 23:46:19 -0600107 )
Davide Pesavento44deacc2014-02-19 10:48:07 +0100108
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800109 # Unit tests
110 if bld.env['WITH_TESTS']:
Junxiao Shiea48d8b2014-03-16 13:53:47 -0700111 unit_tests = bld.program(
Alexander Afanasyevc78b1412014-02-19 14:08:26 -0800112 target="unit-tests",
113 features = "cxx cxxprogram",
114 source = bld.path.ant_glob(['tests/**/*.cpp'],
Davide Pesavento44deacc2014-02-19 10:48:07 +0100115 excl=['tests/face/ethernet.cpp',
116 'tests/face/unix-*.cpp']),
Alexander Afanasyevc78b1412014-02-19 14:08:26 -0800117 use = 'nfd-objects',
118 includes = [".", "daemon"],
119 install_prefix = None,
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800120 )
121
Davide Pesavento44deacc2014-02-19 10:48:07 +0100122 if bld.env['HAVE_PCAP']:
123 unit_tests.source += bld.path.ant_glob('tests/face/ethernet.cpp')
124
Alexander Afanasyevc78b1412014-02-19 14:08:26 -0800125 if bld.env['HAVE_UNIX_SOCKETS']:
Davide Pesavento44deacc2014-02-19 10:48:07 +0100126 unit_tests.source += bld.path.ant_glob('tests/face/unix-*.cpp')
Alexander Afanasyevc78b1412014-02-19 14:08:26 -0800127
Steve DiBenedetto84da5bf2014-03-11 14:51:29 -0600128 bld(features = "subst",
129 source = 'nfd.conf.sample.in',
130 target = 'nfd.conf.sample',
131 install_path = "${SYSCONFDIR}/ndn")
132
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800133@Configure.conf
134def 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 Afanasyev35fc2b72014-02-13 16:56:21 -0800142 if self.check_cxx(cxxflags=[flag], mandatory=False):
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800143 supportedFlags += [flag]
144
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800145 self.end_msg(' '.join (supportedFlags))
Alexander Afanasyevefea8fe2014-03-23 00:00:35 -0700146 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800147
148# doxygen docs
149from waflib.Build import BuildContext
150class doxy(BuildContext):
151 cmd = "doxygen"
152 fun = "doxygen"
153
154def 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')