blob: ef26082e5ed4d11ba6be1a79fccabbc8a1e4c6f6 [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2VERSION='0.6.0'
3
4from waflib import Build, Logs, Utils, Task, TaskGen, Configure
5
6def options(opt):
7 opt.add_option('--debug',action='store_true',default=False,dest='debug',help='''debugging mode''')
8 opt.add_option('--test', action='store_true',default=False,dest='_test',help='''build unit tests''')
9 opt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx logging support''')
10
11 opt.load('compiler_c compiler_cxx boost ccnx doxygen gnu_dirs c_osx')
12 opt.load('tinyxml', tooldir=['waf-tools'])
13
14def configure(conf):
15 conf.load("compiler_c compiler_cxx boost ccnx gnu_dirs tinyxml doxygen c_osx")
16
17 if conf.options.debug:
18 conf.define ('_DEBUG', 1)
19 conf.add_supported_cxxflags (cxxflags = ['-O0',
20 '-Wall',
21 '-Wno-unused-variable',
22 '-g3',
23 '-Wno-unused-private-field', # only clang supports
24 '-fcolor-diagnostics', # only clang supports
25 '-Qunused-arguments' # only clang supports
26 ])
27 else:
28 conf.add_supported_cxxflags (cxxflags = ['-O3', '-g'])
29
30 # if Utils.unversioned_sys_platform () == "darwin":
31 # conf.check_cxx(framework_name='Foundation', uselib_store='OSX_FOUNDATION', mandatory=True, compile_filename='test.mm')
32 # # conf.check_cxx(framework_name='AppKit', uselib_store='OSX_APPKIT', mandatory=True, compile_filename='test.mm')
33 # conf.check_cxx(framework_name='Security', uselib_store='OSX_SECURITY', define_name='HAVE_SECURITY',
34 # use="OSX_FOUNDATION", mandatory=True, compile_filename='test.mm')
35
36 conf.define ("NDN_CXX_VERSION", VERSION)
37
38 conf.check_cfg(package='libevent', args=['--cflags', '--libs'], uselib_store='LIBEVENT', mandatory=True)
39 conf.check_cfg(package='libevent_pthreads', args=['--cflags', '--libs'], uselib_store='LIBEVENT_PTHREADS', mandatory=True)
40
41 if not conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='SSL', mandatory=False):
42 libcrypto = conf.check_cc(lib='crypto',
43 header_name='openssl/crypto.h',
44 define_name='HAVE_SSL',
45 uselib_store='SSL')
46 else:
47 conf.define ("HAVE_SSL", 1)
48 if not conf.get_define ("HAVE_SSL"):
49 conf.fatal ("Cannot find SSL libraries")
50
51 conf.check_cfg(package="libcrypto", args=['--cflags', '--libs'], uselib_store='CRYPTO', mandatory=True)
52
53 if conf.options.log4cxx:
54 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
55 conf.define ("HAVE_LOG4CXX", 1)
56
57 conf.check_tinyxml(path=conf.options.tinyxml_dir)
58 conf.check_doxygen(mandatory=False)
59
60 conf.check_boost(lib='system test iostreams filesystem thread date_time')
61
62 boost_version = conf.env.BOOST_VERSION.split('_')
63 if int(boost_version[0]) < 1 or int(boost_version[1]) < 46:
64 Logs.error ("Minumum required boost version is 1.46")
65 return
66
67 conf.check_ccnx (path=conf.options.ccnx_dir)
68
69 if conf.options._test:
70 conf.define ('_TESTS', 1)
71 conf.env.TEST = 1
72
73 conf.write_config_header('config.h')
74
75def build (bld):
76 executor = bld.objects (
77 target = "executor",
78 features = ["cxx"],
79 cxxflags = "-fPIC",
80 source = bld.path.ant_glob(['executor/**/*.cc']),
81 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX',
82 includes = ".",
83 )
84
85 scheduler = bld.objects (
86 target = "scheduler",
87 features = ["cxx"],
88 cxxflags = "-fPIC",
89 source = bld.path.ant_glob(['scheduler/**/*.cc']),
90 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX executor',
91 includes = ".",
92 )
93
94 libndn_cxx = bld (
95 target="ndn.cxx",
96 features=['cxx', 'cxxshlib'],
97 source = bld.path.ant_glob(['ndn.cxx/**/*.cpp', 'ndn.cxx/**/*.cc',
98 'logging.cc',
99 'libndn.cxx.pc.in']),
100 use = 'CRYPTO TINYXML BOOST BOOST_THREAD SSL CCNX LOG4CXX scheduler executor',
101 includes = ".",
102 )
103
104 # if Utils.unversioned_sys_platform () == "darwin":
105 # libndn_cxx.mac_app = True
106 # libndn_cxx.source += bld.path.ant_glob (['platforms/osx/**/*.mm'])
107 # libndn_cxx.use += " OSX_FOUNDATION OSX_SECURITY"
108
109 # Unit tests
110 if bld.env['TEST']:
111 unittests = bld.program (
112 target="unit-tests",
113 features = "cxx cxxprogram",
114 defines = "WAF",
115 source = bld.path.ant_glob(['test/*.cc']),
116 use = 'BOOST_TEST BOOST_FILESYSTEM BOOST_DATE_TIME LOG4CXX ndn.cxx',
117 includes = ".",
118 install_prefix = None,
119 )
120
121 headers = bld.path.ant_glob(['ndn.cxx.h', 'ndn.cxx/**/*.h'])
122 bld.install_files("%s" % bld.env['INCLUDEDIR'], headers, relative_trick=True)
123
124@Configure.conf
125def add_supported_cxxflags(self, cxxflags):
126 """
127 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
128 """
129 self.start_msg('Checking allowed flags for c++ compiler')
130
131 supportedFlags = []
132 for flag in cxxflags:
133 if self.check_cxx (cxxflags=[flag], mandatory=False):
134 supportedFlags += [flag]
135
136 self.end_msg (' '.join (supportedFlags))
137 self.env.CXXFLAGS += supportedFlags
138
139
140# doxygen docs
141from waflib.Build import BuildContext
142class doxy (BuildContext):
143 cmd = "doxygen"
144 fun = "doxygen"
145
146def doxygen (bld):
147 if not bld.env.DOXYGEN:
148 bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
149 bld (features="doxygen",
150 doxyfile='doc/doxygen.conf')
151
152# doxygen docs
153from waflib.Build import BuildContext
154class sphinx (BuildContext):
155 cmd = "sphinx"
156 fun = "sphinx"
157
158def sphinx (bld):
159 bld.load('sphinx_build', tooldir=['waf-tools'])
160
161 bld (features="sphinx",
162 outdir = "doc/html",
163 source = "doc/source/conf.py")
164
165
166@TaskGen.extension('.mm')
167def mm_hook(self, node):
168 """Alias .mm files to be compiled the same as .cc files, gcc will do the right thing."""
169 return self.create_compiled_task('cxx', node)