blob: 8591b35603aca9a5b918d475c1c9e3f3de39c4b9 [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):
8 opt.load('compiler_cxx')
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''')
14 nfdopt.add_option('--with-ndn-cpp',action='store',type='string',default=None,dest='ndn_cpp_dir',
15 help='''Use NDN-CPP library from the specified path''')
16
17def configure(conf):
18 conf.load("compiler_cxx boost")
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -080019 try:
20 conf.load("doxygen")
21 except:
22 pass
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080023
24 if conf.options.debug:
25 conf.define ('_DEBUG', 1)
26 conf.add_supported_cxxflags (cxxflags = ['-O0',
27 '-Wall',
28 '-Wno-unused-variable',
29 '-g3',
30 '-Wno-unused-private-field', # only clang supports
31 '-fcolor-diagnostics', # only clang supports
32 '-Qunused-arguments', # only clang supports
33 '-Wno-tautological-compare', # suppress warnings from CryptoPP
34 '-Wno-unused-function', # suppress warnings from CryptoPP
35 ])
36 else:
37 conf.add_supported_cxxflags (cxxflags = ['-O3', '-g', '-Wno-tautological-compare', '-Wno-unused-function'])
38
39 if not conf.options.ndn_cpp_dir:
40 conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'], uselib_store='NDN_CPP', mandatory=True)
41 else:
42 conf.check_cxx(lib='ndn-cpp-dev', uselib_store='NDN_CPP',
43 cxxflags="-I%s/include" % conf.options.ndn_cpp_dir,
44 linkflags="-L%s/lib" % conf.options.ndn_cpp_dir,
45 mandatory=True)
46
47 boost_libs='system'
48 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)
54
55 boost_version = conf.env.BOOST_VERSION.split('_')
56 if int(boost_version[0]) < 1 or int(boost_version[1]) < 42:
57 Logs.error ("Minumum required boost version is 1.42")
58 return
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080059
60 conf.load('unix-socket')
Junxiao Shi61c5ef32014-01-24 20:59:30 -070061
62 conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False)
63
Alexander Afanasyev689569b2014-02-16 20:20:07 -080064 conf.load('coverage')
65
Junxiao Shi61c5ef32014-01-24 20:59:30 -070066 conf.write_config_header('daemon/config.hpp')
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080067
Junxiao Shi09bf7c42014-01-31 11:10:25 -070068def build(bld):
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080069 nfd_objects = bld(
70 target = "nfd-objects",
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070071 features = "cxx",
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080072 source = bld.path.ant_glob(['daemon/**/*.cpp'],
73 excl=['daemon/**/unix-*.cpp', 'daemon/main.cpp']),
Junxiao Shi61c5ef32014-01-24 20:59:30 -070074 use = 'BOOST NDN_CPP RT',
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080075 includes = [".", "daemon"],
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070076 )
77
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080078 if bld.env['HAVE_UNIX_SOCKETS']:
79 nfd_objects.source += bld.path.ant_glob(['daemon/**/unix-*.cpp'],
80 excl=['daemon/main.cpp'])
81
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080082 bld(target = "nfd",
83 features = "cxx cxxprogram",
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070084 source = 'daemon/main.cpp',
85 use = 'nfd-objects',
Junxiao Shi09bf7c42014-01-31 11:10:25 -070086 includes = [".", "daemon"],
hilata198cadb2014-02-15 23:46:19 -060087 )
88
89 for app in bld.path.ant_glob('tools/*.cpp'):
90 bld(features=['cxx', 'cxxprogram'],
91 target = 'bin/%s' % (str(app.change_ext(''))),
92 source = ['tools/%s' % (str(app))],
93 use = 'BOOST NDN_CPP RT',
94 )
95
Alexander Afanasyev2aa39622014-01-22 11:51:11 -080096 # Unit tests
97 if bld.env['WITH_TESTS']:
Alexander Afanasyevc78b1412014-02-19 14:08:26 -080098 unit_tests = unittests = bld.program (
99 target="unit-tests",
100 features = "cxx cxxprogram",
101 source = bld.path.ant_glob(['tests/**/*.cpp'],
102 excl=['tests/**/unix-*.cpp']),
103 use = 'nfd-objects',
104 includes = [".", "daemon"],
105 install_prefix = None,
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800106 )
107
Alexander Afanasyevc78b1412014-02-19 14:08:26 -0800108 if bld.env['HAVE_UNIX_SOCKETS']:
109 unit_tests.source += bld.path.ant_glob(['tests/**/unix-*.cpp'])
110
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800111@Configure.conf
112def add_supported_cxxflags(self, cxxflags):
113 """
114 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
115 """
116 self.start_msg('Checking allowed flags for c++ compiler')
117
118 supportedFlags = []
119 for flag in cxxflags:
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800120 if self.check_cxx(cxxflags=[flag], mandatory=False):
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800121 supportedFlags += [flag]
122
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800123 self.end_msg(' '.join (supportedFlags))
Alexander Afanasyev2aa39622014-01-22 11:51:11 -0800124 self.env.CXXFLAGS += supportedFlags
Alexander Afanasyev35fc2b72014-02-13 16:56:21 -0800125
126# doxygen docs
127from waflib.Build import BuildContext
128class doxy(BuildContext):
129 cmd = "doxygen"
130 fun = "doxygen"
131
132def doxygen(bld):
133 if not bld.env.DOXYGEN:
134 bld.fatal("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
135 bld(features="doxygen",
136 doxyfile='docs/doxygen.conf')
hilata198cadb2014-02-15 23:46:19 -0600137