blob: faa9112529bb802a99a254c64a18b7fb99f9df6b [file] [log] [blame]
Alexander Afanasyev219fcb52013-11-18 19:49:16 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2VERSION='0.3~dev0'
3NAME="ndn-cpp-dev"
4
5from waflib import Build, Logs, Utils, Task, TaskGen, Configure
6
7def options(opt):
8 opt.load('compiler_c compiler_cxx gnu_dirs c_osx')
9 opt.load('boost doxygen openssl cryptopp', tooldir=['waf-tools'])
10
11 opt = opt.add_option_group('NDN-CPP Options')
12
13 opt.add_option('--debug',action='store_true',default=False,dest='debug',help='''debugging mode''')
14 opt.add_option('--test', action='store_true',default=False,dest='_test',help='''build unit tests''')
15 opt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx logging support''')
16 opt.add_option('--private_storage', dest='private_storage', default='opt', help='''simple for SimplePrivatekeyStorage; osx for OSXPrivatekeyStorage; opt for optimal one based on system (default)''')
17 opt.add_option('--public_storage', dest='public_storage', default='opt', help='''basic for BasicIdentityStorage; opt for optimal one based on system (default)''')
18 opt.add_option('--policy_manager', dest='policy_manager', default='opt', help='''none for NoVerifyPolicyManager; opt for optimal one based on system (default)''')
19 opt.add_option('--encrypt_manager', dest='encrypt_manager', default='opt', help='''basic for BasicEncryptionManager; opt for optimal one based on system (default)''')
20
21 opt.add_option('--no-c++11', action='store_false', default=True, dest='use_cxx11',
22 help='''Do not use C++11 features, even if available in the compiler''')
23 opt.add_option('--use-system-boost', action='store_true', default=False, dest='use_system_boost',
24 help='''Use system's boost libraries''')
25
26
27def configure(conf):
28 conf.load("compiler_c compiler_cxx boost gnu_dirs c_osx openssl cryptopp")
29 try:
30 conf.load("doxygen")
31 except:
32 pass
33
34 if conf.options._test:
35 conf.define ('_TESTS', 1)
36 conf.env['TEST'] = True
37
38 # Optional functions
39 for func in ['memcmp', 'memcpy', 'memset']:
40 conf.check(function_name=func, header_name='string.h', mandatory=False)
41
42 # Mandatory functions
43 for func in ['strchr', 'sscanf']:
44 conf.check(function_name=func, header_name=['string.h', 'stdio.h'])
45
46 # Mandatory headers
47 for header in ['time.h', 'sys/time.h']:
48 conf.check(header_name=header)
49
50 conf.check(function_name='gettimeofday', header_name=['time.h', 'sys/time.h'])
51
52 conf.check_openssl()
53
54 if conf.options.debug:
55 conf.define ('_DEBUG', 1)
56 flags = ['-O0',
57 '-Wall',
58 '-Werror',
59 '-Wno-unused-variable',
60 '-g3',
61 '-Wno-unused-private-field', # only clang supports
62 '-fcolor-diagnostics', # only clang supports
63 '-Qunused-arguments', # only clang supports
64 '-Wno-tautological-compare', # suppress warnings from CryptoPP
65 '-Wno-unused-function', # another annoying warning from CryptoPP
66
67 '-Wno-deprecated-declarations',
68 ]
69
70 conf.add_supported_cxxflags (cxxflags = flags)
71 conf.add_supported_cflags (cflags = flags)
72 else:
73 flags = ['-O3', '-g', '-Wno-tautological-compare', '-Wno-unused-function', '-Wno-deprecated-declarations']
74 conf.add_supported_cxxflags (cxxflags = flags)
75 conf.add_supported_cflags (cxxflags = flags)
76
77 if Utils.unversioned_sys_platform () == "darwin":
78 # if 'clang++' not in conf.env['CXX']:
79 # conf.fatal('Use clang++ compiler (CXX=clang++ ./waf configure) on OSX platform')
80 # return
81
82 conf.check_cxx(framework_name='CoreFoundation', uselib_store='OSX_COREFOUNDATION', mandatory=True)
83 # conf.check_cxx(framework_name='CoreServices', uselib_store='OSX_CORESERVICES', mandatory=True, compile_filename='test.mm')
84 # conf.check_cxx(framework_name='Security', uselib_store='OSX_SECURITY', define_name='HAVE_SECURITY',
85 # use="OSX_COREFOUNDATION", mandatory=True, compile_filename='test.mm')
86
87 conf.check_security_parameter()
88
89 conf.define ("PACKAGE_BUGREPORT", "ndn-lib@lists.cs.ucla.edu")
90 conf.define ("PACKAGE_NAME", NAME)
91 conf.define ("PACKAGE_VERSION", VERSION)
92 conf.define ("PACKAGE_URL", "https://github.com/named-data/ndn-cpp")
93
94 conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3', mandatory=True)
95 # conf.check_cfg(package='libevent', args=['--cflags', '--libs'], uselib_store='LIBEVENT', mandatory=True)
96 # conf.check_cfg(package='libevent_pthreads', args=['--cflags', '--libs'], uselib_store='LIBEVENT_PTHREADS', mandatory=True)
97
98 if conf.options.log4cxx:
99 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
100 conf.define ("HAVE_LOG4CXX", 1)
101
102 # conf.check_cryptopp(path=conf.options.cryptopp_dir)
103
104 if conf.options.use_cxx11:
105 conf.add_supported_cxxflags(cxxflags = ['-std=c++11', '-std=c++0x'])
106
107 conf.check(msg='Checking for type std::shared_ptr',
108 type_name="std::shared_ptr<int>", header_name="memory", define_name='HAVE_STD_SHARED_PTR')
109 conf.check(msg='Checking for type std::function',
110 type_name="std::function<void()>", header_name="functional", define_name='HAVE_STD_FUNCTION')
111 conf.define('HAVE_CXX11', 1)
112 else:
113 if conf.options.use_system_boost:
114 USED_BOOST_LIBS = 'system iostreams'
115 if conf.env['TEST']:
116 USED_BOOST_LIBS += " test"
117
118 conf.check_boost(lib=USED_BOOST_LIBS)
119
120 boost_version = conf.env.BOOST_VERSION.split('_')
121 if int(boost_version[0]) > 1 or (int(boost_version[0]) == 1 and int(boost_version[1]) >= 46):
122 conf.env['USE_SYSTEM_BOOST'] = True
123 conf.define('USE_SYSTEM_BOOST', 1)
124
125 conf.write_config_header('include/ndn-cpp/ndn-cpp-config.h', define_prefix='NDN_CPP_')
126
127def build (bld):
128 libndn_cpp = bld (
129 target="ndn-cpp-dev",
130 vnum = "0.3.0",
131 features=['c', 'cxx', 'cxxshlib'],
132 source = bld.path.ant_glob(['src/**/*.cpp',
133 'src/**/*.c']),
134 use = 'BOOST OPENSSL LOG4CXX CRYPTOPP SQLITE3',
135 includes = ". include",
136 )
137
138 if Utils.unversioned_sys_platform () == "darwin":
139 libndn_cpp.mac_app = True
140 libndn_cpp.use += " OSX_COREFOUNDATION OSX_SECURITY"
141
142 # Unit tests
143 if bld.env['TEST']:
144 unittests = bld.program (
145 target="unit-tests",
146 features = "cxx cxxprogram",
147 defines = "WAF",
148 source = bld.path.ant_glob(['test/*.cc']),
149 use = 'BOOST BOOST_TEST OPENSSL LOG4CXX ndn.cxx CRYPTOPP',
150 includes = ".",
151 install_prefix = None,
152 )
153
154 headers = bld.path.ant_glob(['src/**/*.h'])
155 bld.install_files("%s/ndn-cpp" % bld.env['INCLUDEDIR'], headers, relative_trick=True, cwd=bld.path.find_node('src'))
156
157@Configure.conf
158def add_supported_cxxflags(self, cxxflags):
159 """
160 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
161 """
162 self.start_msg('Checking allowed flags for c++ compiler')
163
164 supportedFlags = []
165 for flag in cxxflags:
166 if self.check_cxx (cxxflags=[flag], mandatory=False):
167 supportedFlags += [flag]
168
169 self.end_msg (' '.join (supportedFlags))
170 self.env.CXXFLAGS += supportedFlags
171
172@Configure.conf
173def add_supported_cflags(self, cflags):
174 """
175 Check which cflags are supported by compiler and add them to env.CFLAGS variable
176 """
177 self.start_msg('Checking allowed flags for c compiler')
178
179 supportedFlags = []
180 for flag in cflags:
181 if self.check_cc (cflags=[flag], mandatory=False):
182 supportedFlags += [flag]
183
184 self.end_msg (' '.join (supportedFlags))
185 self.env.CFLAGS += supportedFlags
186
187@Configure.conf
188def check_security_parameter(self):
189 """
190 Check the security parameters
191 """
192 if self.options.private_storage == 'simple':
193 self.define ('USE_SIMPLE_PRIVATEKEY_STORAGE', 1)
194 elif self.options.private_storage == 'osx':
195 self.define ('USE_OSX_PRIVATEKEY_STORAGE', 1)
196 else:
197 if Utils.unversioned_sys_platform () == "darwin":
198 self.define ('USE_OSX_PRIVATEKEY_STORAGE', 1)
199 else:
200 self.define ('USE_SIMPLE_PRIVATEKEY_STORAGE', 1)
201
202 if self.options.public_storage == 'basic':
203 self.define ('USE_BASIC_IDENTITY_STORAGE', 1)
204 else:
205 self.define ('USE_BASIC_IDENTITY_STORAGE', 1)
206
207 if self.options.policy_manager == 'none':
208 self.define ('USE_NO_VERIFY_POLICY_MANAGER', 1)
209 else:
210 self.define ('USE_SIMPLE_POLICY_MANAGER', 1)
211
212 if self.options.encrypt_manager == 'basic':
213 self.define ('USE_BASIC_ENCRYPTION_MANAGER', 1)
214 else:
215 self.define ('USE_BASIC_ENCRYPTION_MANAGER', 1)
216
217
218# doxygen docs
219from waflib.Build import BuildContext
220class doxy (BuildContext):
221 cmd = "doxygen"
222 fun = "doxygen"
223
224def doxygen (bld):
225 if not bld.env.DOXYGEN:
226 bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
227 bld (features="doxygen",
228 doxyfile='doc/doxygen.conf')
229
230# doxygen docs
231from waflib.Build import BuildContext
232class sphinx (BuildContext):
233 cmd = "sphinx"
234 fun = "sphinx"
235
236def sphinx (bld):
237 bld.load('sphinx_build', tooldir=['waf-tools'])
238
239 bld (features="sphinx",
240 outdir = "doc/html",
241 source = "doc/source/conf.py")
242
243@TaskGen.extension('.mm')
244def mm_hook(self, node):
245 """Alias .mm files to be compiled the same as .cc files, gcc will do the right thing."""
246 return self.create_compiled_task('cxx', node)