blob: 4198fa3ea1eea03832949e99976c09aad896069a [file] [log] [blame]
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -07002#
3# Copyright (c) 2014, Regents of the University of California
4#
5# GPL 3.0 license, see the COPYING.md file for more information
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08006
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -07007VERSION = '0.4.0'
8APPNAME = "ndn-cpp-dev"
9PACKAGE_BUGREPORT = "http://redmine.named-data.net/projects/ndn-cpp-dev"
10PACKAGE_URL = "https://github.com/named-data/ndn-cpp-dev"
11
12from waflib import Logs, Utils, Task, TaskGen
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080013from waflib.Tools import c_preproc
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080014
15def options(opt):
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070016 opt.load('compiler_cxx gnu_dirs c_osx')
17 opt.load('boost doxygen openssl cryptopp coverage default-compiler-flags',
18 tooldir=['.waf-tools'])
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080019
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070020 opt = opt.add_option_group('Library Options')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080021
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070022 opt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080023 help='''build unit tests''')
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070024 opt.add_option('--with-log4cxx', action='store_true', default=False, dest='log4cxx',
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080025 help='''Compile with log4cxx logging support''')
26
27 opt.add_option('--with-c++11', action='store_true', default=False, dest='use_cxx11',
28 help='''Use C++11 features, even if available in the compiler''')
Yingdi Yue6bfab22014-02-06 16:01:19 -080029 opt.add_option('--without-tools', action='store_false', default=True, dest='with_tools',
30 help='''Do not build tools''')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080031
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070032 opt.add_option('--without-sqlite-locking', action='store_false', default=True,
33 dest='with_sqlite_locking',
34 help='''Disable filesystem locking in sqlite3 database '''
35 '''(use unix-dot locking mechanism instead). '''
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -080036 '''This option may be necessary if home directory is hosted on NFS.''')
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080037 opt.add_option('--with-pch', action='store_true', default=False, dest='with_pch',
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070038 help='''Try to use precompiled header to speed up compilation '''
39 '''(only gcc and clang)''')
40 opt.add_option('--without-osx-keychain', action='store_false', default=True,
41 dest='with_osx_keychain',
Alexander Afanasyev3e08d5d2014-02-12 19:24:28 -080042 help='''On Darwin, do not use OSX keychain as a default TPM''')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080043
44def configure(conf):
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070045 conf.load("compiler_cxx boost gnu_dirs c_osx openssl cryptopp")
46 try: conf.load("doxygen")
47 except: pass
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080048
49 if conf.options.with_tests:
50 conf.env['WITH_TESTS'] = True
51
Yingdi Yue6bfab22014-02-06 16:01:19 -080052 if conf.options.with_tools:
53 conf.env['WITH_TOOLS'] = True
54
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080055 conf.check_openssl()
56
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070057 conf.load('default-compiler-flags')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080058
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070059 if Utils.unversioned_sys_platform() == "darwin":
Alexander Afanasyev59d67a52014-04-03 16:09:31 -070060 try:
61 codeFragment='''
62#include <CoreFoundation/CoreFoundation.h>
63#include <Security/Security.h>
64#include <Security/SecRandom.h>
65#include <CoreServices/CoreServices.h>
66#include <Security/SecDigestTransform.h>
67
68int main(int argc, char **argv) {
69 (void)argc; (void)argv;
70 return 0;
71}
72'''
73 conf.check_cxx(framework_name='CoreFoundation', uselib_store='OSX_COREFOUNDATION',
74 mandatory=True)
75 conf.check_cxx(framework_name='CoreServices', uselib_store='OSX_CORESERVICES',
76 mandatory=True)
77 conf.check_cxx(framework_name='Security', uselib_store='OSX_SECURITY',
78 define_name='HAVE_SECURITY', use="OSX_COREFOUNDATION",
79 fragment=codeFragment, mandatory=True)
80 conf.define('HAVE_OSX_SECURITY', 1)
81 conf.env['HAVE_OSX_SECURITY'] = True
82 except:
83 Logs.warn("Compiling on OSX, but CoreFoundation, CoreServices, or Security framework is not functional.")
84 Logs.warn("The frameworks are known to work only with Apple-specific compilers: llvm-gcc-4.2 or clang")
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080085
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070086 conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3',
87 mandatory=True)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080088
89 if conf.options.log4cxx:
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070090 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX',
91 mandatory=True)
92 conf.define("HAVE_LOG4CXX", 1)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080093
94 conf.check_cryptopp(path=conf.options.cryptopp_dir, mandatory=True)
95
96 if conf.options.use_cxx11:
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070097 conf.add_supported_cxxflags(cxxflags=['-std=c++11', '-std=c++0x'])
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080098
99 conf.check(msg='Checking for type std::shared_ptr',
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700100 type_name="std::shared_ptr<int>", header_name="memory",
101 define_name='HAVE_STD_SHARED_PTR')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800102 conf.check(msg='Checking for type std::function',
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700103 type_name="std::function<void()>", header_name="functional",
104 define_name='HAVE_STD_FUNCTION')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800105 conf.define('HAVE_CXX11', 1)
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700106
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700107 USED_BOOST_LIBS = ['system', 'filesystem', 'date_time', 'iostreams',
108 'regex', 'program_options', 'chrono']
Alexander Afanasyevdafdc372014-03-03 15:58:44 +0000109 if conf.env['WITH_TESTS']:
110 USED_BOOST_LIBS += ['unit_test_framework']
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800111
Alexander Afanasyevdafdc372014-03-03 15:58:44 +0000112 conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True)
113 if conf.env.BOOST_VERSION_NUMBER < 104800:
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700114 Logs.error("Minimum required boost version is 1.48.0")
115 Logs.error("Please upgrade your distribution or install custom boost libraries" +
Alexander Afanasyevdafdc372014-03-03 15:58:44 +0000116 " (http://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)")
117 return
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800118
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700119 conf.check_cxx(lib='pthread', uselib_store='PTHREAD', define_name='HAVE_PTHREAD',
120 mandatory=False)
Alexander Afanasyev19508852014-01-29 01:01:51 -0800121 conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False)
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800122 conf.check_cxx(cxxflags=['-fPIC'], uselib_store='cxxstlib', mandatory=False)
Alexander Afanasyev19508852014-01-29 01:01:51 -0800123
Alexander Afanasyev5b60f702014-02-07 12:55:24 -0800124 if not conf.options.with_sqlite_locking:
125 conf.define('DISABLE_SQLITE3_FS_LOCKING', 1)
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800126
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -0800127 conf.env['WITH_PCH'] = conf.options.with_pch
Alexander Afanasyev3e08d5d2014-02-12 19:24:28 -0800128
Alexander Afanasyev59d67a52014-04-03 16:09:31 -0700129 if conf.env['HAVE_OSX_SECURITY']:
Alexander Afanasyev3e08d5d2014-02-12 19:24:28 -0800130 conf.env['WITH_OSX_KEYCHAIN'] = conf.options.with_osx_keychain
131 if conf.options.with_osx_keychain:
132 conf.define('WITH_OSX_KEYCHAIN', 1)
133 else:
134 conf.env['WITH_OSX_KEYCHAIN'] = False
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800135
136 conf.load("coverage")
137
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600138 conf.define('SYSCONFDIR', conf.env['SYSCONFDIR'])
139
Alexander Afanasyev09c613f2014-01-29 00:23:58 -0800140 conf.write_config_header('src/ndn-cpp-config.h', define_prefix='NDN_CPP_')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800141
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700142def build(bld):
143 libndn_cpp = bld(
Alexander Afanasyev59efe102014-01-29 15:56:30 -0800144 features=['cxx', 'cxxstlib'], # 'cxxshlib',
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700145 # vnum="0.3.0",
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -0800146 target="ndn-cpp-dev",
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700147 name="ndn-cpp-dev",
148 source=bld.path.ant_glob('src/**/*.cpp',
149 excl=['src/**/*-osx.cpp', 'src/**/*-sqlite3.cpp']),
150 use='BOOST OPENSSL LOG4CXX CRYPTOPP SQLITE3 RT PIC PTHREAD',
151 includes=". src",
152 export_includes="src",
153 install_path='${LIBDIR}',
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800154 )
155
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -0800156 if bld.env['WITH_PCH']:
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700157 libndn_cpp.pch="src/common.hpp"
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800158
Alexander Afanasyev59d67a52014-04-03 16:09:31 -0700159 if bld.env['HAVE_OSX_SECURITY']:
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -0800160 libndn_cpp.source += bld.path.ant_glob('src/**/*-osx.cpp')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800161 libndn_cpp.mac_app = True
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800162 libndn_cpp.use += " OSX_COREFOUNDATION OSX_SECURITY"
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800163
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -0800164 # In case we want to make it optional later
165 libndn_cpp.source += bld.path.ant_glob('src/**/*-sqlite3.cpp')
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800166
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700167 # Prepare flags that should go to pkgconfig file
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800168 pkgconfig_libs = []
169 pkgconfig_ldflags = []
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800170 pkgconfig_linkflags = []
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800171 pkgconfig_includes = []
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800172 pkgconfig_cxxflags = []
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800173 for lib in Utils.to_list(libndn_cpp.use):
174 if bld.env['LIB_%s' % lib]:
175 pkgconfig_libs += Utils.to_list(bld.env['LIB_%s' % lib])
176 if bld.env['LIBPATH_%s' % lib]:
177 pkgconfig_ldflags += Utils.to_list(bld.env['LIBPATH_%s' % lib])
178 if bld.env['INCLUDES_%s' % lib]:
179 pkgconfig_includes += Utils.to_list(bld.env['INCLUDES_%s' % lib])
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800180 if bld.env['LINKFLAGS_%s' % lib]:
181 pkgconfig_linkflags += Utils.to_list(bld.env['LINKFLAGS_%s' % lib])
182 if bld.env['CXXFLAGS_%s' % lib]:
183 pkgconfig_cxxflags += Utils.to_list(bld.env['CXXFLAGS_%s' % lib])
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800184
Alexander Afanasyev84cf4292014-01-29 22:16:27 -0800185 EXTRA_FRAMEWORKS = "";
Alexander Afanasyev59d67a52014-04-03 16:09:31 -0700186 if bld.env['HAVE_OSX_SECURITY']:
Alexander Afanasyev84cf4292014-01-29 22:16:27 -0800187 EXTRA_FRAMEWORKS = "-framework CoreFoundation -framework Security"
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800188
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800189 def uniq(alist):
190 set = {}
191 return [set.setdefault(e,e) for e in alist if e not in set]
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800192
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700193 pkconfig = bld(features="subst",
194 source="libndn-cpp-dev.pc.in",
195 target="libndn-cpp-dev.pc",
196 install_path="${LIBDIR}/pkgconfig",
197 VERSION=VERSION,
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800198
199 # This probably not the right thing to do, but to simplify life of apps
200 # that use the library
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700201 EXTRA_LIBS=" ".join([('-l%s' % i) for i in uniq(pkgconfig_libs)]),
202 EXTRA_LDFLAGS=" ".join([('-L%s' % i) for i in uniq(pkgconfig_ldflags)]),
203 EXTRA_LINKFLAGS=" ".join(uniq(pkgconfig_linkflags)),
204 EXTRA_INCLUDES=" ".join([('-I%s' % i) for i in uniq(pkgconfig_includes)]),
205 EXTRA_CXXFLAGS=" ".join(uniq(pkgconfig_cxxflags)),
206 EXTRA_FRAMEWORKS=EXTRA_FRAMEWORKS,
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800207 )
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800208
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800209 # Unit tests
210 if bld.env['WITH_TESTS']:
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800211 bld.recurse('tests')
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700212 bld.recurse('tests-integrated')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800213
Yingdi Yue6bfab22014-02-06 16:01:19 -0800214 if bld.env['WITH_TOOLS']:
215 bld.recurse("tools examples")
216 else:
217 bld.recurse("examples")
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800218
Alexander Afanasyev19508852014-01-29 01:01:51 -0800219 headers = bld.path.ant_glob(['src/**/*.hpp'])
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700220 bld.install_files("%s/ndn-cpp-dev" % bld.env['INCLUDEDIR'], headers,
221 relative_trick=True, cwd=bld.path.find_node('src'))
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800222
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700223 bld.install_files("%s/ndn-cpp-dev" % bld.env['INCLUDEDIR'],
224 bld.path.find_resource('src/ndn-cpp-config.h'))
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800225
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600226 bld.install_files("${SYSCONFDIR}/ndn", "client.conf.sample")
227
Alexander Afanasyev401a2362014-03-02 00:03:11 +0000228def doxygen(bld):
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800229 if not bld.env.DOXYGEN:
Alexander Afanasyev401a2362014-03-02 00:03:11 +0000230 bld.fatal("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
231 bld(features="doxygen",
232 doxyfile='docs/doxygen.conf')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800233
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700234def sphinx(bld):
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800235 bld.load('sphinx_build', tooldir=['waf-tools'])
236
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700237 bld(features="sphinx",
238 outdir="doc/html",
239 source="doc/source/conf.py")
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -0800240
241
242@TaskGen.feature('cxx')
243@TaskGen.before('process_source')
244def process_pch(self):
245 if getattr(self, 'pch', ''):
246 # for now support only gcc-compatible things
247 if self.env['COMPILER_CXX'] == 'g++':
248 nodes = self.to_nodes(self.pch, path=self.path)
249 for x in nodes:
250 z = self.create_task('gchx', x, x.change_ext('.hpp.gch'))
251 z.orig_self = self
252
253class gchx(Task.Task):
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700254 run_str = '${CXX} -x c++-header ${CXXFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ' + \
255 '${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ' + \
256 '${CXX_SRC_F}${SRC} ${CXX_TGT_F}${TGT}'
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -0800257 scan = c_preproc.scan
258 ext_out = ['.hpp']
259 color = 'BLUE'
260
261 def post_run(self):
262 super(gchx, self).post_run()
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700263 self.orig_self.env['CXXFLAGS'] = ['-include', self.inputs[0].relpath()] + \
264 self.env['CXXFLAGS']