blob: e2c946bcdf040fdc1232a8d64a5f27d9f7a23738 [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
5
6def options(opt):
7 opt.load('compiler_cxx')
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -08008 opt.load('boost doxygen', tooldir=['.waf-tools'])
Alexander Afanasyev2aa39622014-01-22 11:51:11 -08009
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
16def configure(conf):
17 conf.load("compiler_cxx boost")
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -080018 try:
19 conf.load("doxygen")
20 except:
21 pass
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080022
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
49 boost_libs+=' unit_test_framework'
50
51 conf.check_boost(lib=boost_libs)
52
53 boost_version = conf.env.BOOST_VERSION.split('_')
54 if int(boost_version[0]) < 1 or int(boost_version[1]) < 42:
55 Logs.error ("Minumum required boost version is 1.42")
56 return
Junxiao Shi61c5ef32014-01-24 20:59:30 -070057
58 conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False)
59
60 conf.write_config_header('daemon/config.hpp')
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080061
Junxiao Shi09bf7c42014-01-31 11:10:25 -070062def build(bld):
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070063 bld(target = "nfd-objects",
64 features = "cxx",
65 source = bld.path.ant_glob(['daemon/**/*.cpp'], excl=['daemon/main.cpp']),
Junxiao Shi61c5ef32014-01-24 20:59:30 -070066 use = 'BOOST NDN_CPP RT',
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080067 includes = [".", "daemon"],
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070068 )
69
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080070 bld(target = "nfd",
71 features = "cxx cxxprogram",
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070072 source = 'daemon/main.cpp',
73 use = 'nfd-objects',
Junxiao Shi09bf7c42014-01-31 11:10:25 -070074 includes = [".", "daemon"],
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080075 )
76
77 # Unit tests
78 if bld.env['WITH_TESTS']:
79 unittests = bld.program (
80 target="unit-tests",
81 features = "cxx cxxprogram",
Junxiao Shi1a2a8562014-01-23 10:07:59 -070082 source = bld.path.ant_glob(['tests/**/*.cpp']),
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070083 use = 'nfd-objects',
Junxiao Shi1a2a8562014-01-23 10:07:59 -070084 includes = [".", "daemon"],
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080085 install_prefix = None,
86 )
87
88@Configure.conf
89def add_supported_cxxflags(self, cxxflags):
90 """
91 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
92 """
93 self.start_msg('Checking allowed flags for c++ compiler')
94
95 supportedFlags = []
96 for flag in cxxflags:
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -080097 if self.check_cxx(cxxflags=[flag], mandatory=False):
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080098 supportedFlags += [flag]
99
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800100 self.end_msg(' '.join (supportedFlags))
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800101 self.env.CXXFLAGS += supportedFlags
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800102
103# doxygen docs
104from waflib.Build import BuildContext
105class doxy(BuildContext):
106 cmd = "doxygen"
107 fun = "doxygen"
108
109def doxygen(bld):
110 if not bld.env.DOXYGEN:
111 bld.fatal("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
112 bld(features="doxygen",
113 doxyfile='docs/doxygen.conf')