blob: a9d75f7edb9693f7fd045a68b7455bb585956aba [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 Afanasyeva1ae0a12014-01-28 15:21:02 -08002
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -07003from waflib import Logs, Utils, Context
4import os
Alexander Afanasyeva06fdda2014-04-29 19:15:00 -07005
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -07006VERSION = "0.1.0"
Alexander Afanasyev766cea72014-04-24 19:16:42 -07007APPNAME = "ndn-cxx"
8PACKAGE_BUGREPORT = "http://redmine.named-data.net/projects/ndn-cxx"
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -07009PACKAGE_URL = "http://named-data.net/doc/ndn-cxx/"
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070010
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080011def options(opt):
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070012 opt.load(['compiler_cxx', 'gnu_dirs', 'c_osx'])
13 opt.load(['default-compiler-flags', 'coverage', 'osx-security', 'pch',
14 'boost', 'openssl', 'cryptopp', 'sqlite3',
15 'doxygen', 'sphinx_build'],
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070016 tooldir=['.waf-tools'])
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080017
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070018 opt = opt.add_option_group('Library Options')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080019
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070020 opt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080021 help='''build unit tests''')
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070022 opt.add_option('--with-log4cxx', action='store_true', default=False, dest='log4cxx',
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080023 help='''Compile with log4cxx logging support''')
24
Yingdi Yue6bfab22014-02-06 16:01:19 -080025 opt.add_option('--without-tools', action='store_false', default=True, dest='with_tools',
26 help='''Do not build tools''')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080027
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -070028 opt.add_option('--with-examples', action='store_true', default=False, dest='with_examples',
29 help='''Build examples''')
30
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070031 opt.add_option('--without-sqlite-locking', action='store_false', default=True,
32 dest='with_sqlite_locking',
33 help='''Disable filesystem locking in sqlite3 database '''
34 '''(use unix-dot locking mechanism instead). '''
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -080035 '''This option may be necessary if home directory is hosted on NFS.''')
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070036 opt.add_option('--without-osx-keychain', action='store_false', default=True,
37 dest='with_osx_keychain',
Alexander Afanasyev3e08d5d2014-02-12 19:24:28 -080038 help='''On Darwin, do not use OSX keychain as a default TPM''')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080039
40def configure(conf):
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070041 conf.load(['compiler_cxx', 'gnu_dirs', 'c_osx',
42 'default-compiler-flags', 'osx-security', 'pch',
43 'boost', 'openssl', 'cryptopp', 'sqlite3',
44 'doxygen', 'sphinx_build'])
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080045
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070046 conf.env['WITH_TESTS'] = conf.options.with_tests
47 conf.env['WITH_TOOLS'] = conf.options.with_tools
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -070048 conf.env['WITH_EXAMPLES'] = conf.options.with_examples
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080049
Alexander Afanasyev95de62e2014-04-11 18:26:33 -070050 conf.find_program('sh', var='SH', mandatory=True)
51
Alexander Afanasyevfff47d62014-05-11 19:24:46 -070052 conf.check_cxx(lib='pthread', uselib_store='PTHREAD', define_name='HAVE_PTHREAD',
53 mandatory=False)
54 conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False)
55 conf.check_cxx(cxxflags=['-fPIC'], uselib_store='cxxstlib', mandatory=False)
56
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070057 conf.check_osx_security(mandatory=False)
Yingdi Yue6bfab22014-02-06 16:01:19 -080058
Alexander Afanasyev1160baa2014-04-10 18:50:29 -070059 conf.check_openssl(mandatory=True)
60 conf.check_sqlite3(mandatory=True)
Alexander Afanasyevfff47d62014-05-11 19:24:46 -070061 conf.check_cryptopp(mandatory=True, use='PTHREAD')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080062
63 if conf.options.log4cxx:
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070064 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX',
65 mandatory=True)
66 conf.define("HAVE_LOG4CXX", 1)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080067
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080068 if conf.options.use_cxx11:
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080069 conf.check(msg='Checking for type std::shared_ptr',
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070070 type_name="std::shared_ptr<int>", header_name="memory",
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070071 define_name='HAVE_STD_SHARED_PTR', mandatory=True)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080072 conf.check(msg='Checking for type std::function',
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070073 type_name="std::function<void()>", header_name="functional",
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070074 define_name='HAVE_STD_FUNCTION', mandatory=True)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080075 conf.define('HAVE_CXX11', 1)
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070076
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070077 USED_BOOST_LIBS = ['system', 'filesystem', 'date_time', 'iostreams',
78 'regex', 'program_options', 'chrono']
Alexander Afanasyevdafdc372014-03-03 15:58:44 +000079 if conf.env['WITH_TESTS']:
80 USED_BOOST_LIBS += ['unit_test_framework']
Yingdi Yuf56c68f2014-04-24 21:50:13 -070081 conf.define('HAVE_TESTS', 1)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080082
Alexander Afanasyevdafdc372014-03-03 15:58:44 +000083 conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True)
84 if conf.env.BOOST_VERSION_NUMBER < 104800:
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070085 Logs.error("Minimum required boost version is 1.48.0")
86 Logs.error("Please upgrade your distribution or install custom boost libraries" +
Alexander Afanasyevdafdc372014-03-03 15:58:44 +000087 " (http://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)")
88 return
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080089
Alexander Afanasyev5b60f702014-02-07 12:55:24 -080090 if not conf.options.with_sqlite_locking:
91 conf.define('DISABLE_SQLITE3_FS_LOCKING', 1)
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -080092
Alexander Afanasyev59d67a52014-04-03 16:09:31 -070093 if conf.env['HAVE_OSX_SECURITY']:
Alexander Afanasyev3e08d5d2014-02-12 19:24:28 -080094 conf.env['WITH_OSX_KEYCHAIN'] = conf.options.with_osx_keychain
95 if conf.options.with_osx_keychain:
96 conf.define('WITH_OSX_KEYCHAIN', 1)
97 else:
98 conf.env['WITH_OSX_KEYCHAIN'] = False
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -080099
Alexander Afanasyev1160baa2014-04-10 18:50:29 -0700100 # Loading "late" to prevent tests to be compiled with profiling flags
101 conf.load('coverage')
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800102
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600103 conf.define('SYSCONFDIR', conf.env['SYSCONFDIR'])
104
Alexander Afanasyev766cea72014-04-24 19:16:42 -0700105 conf.write_config_header('src/ndn-cxx-config.hpp', define_prefix='NDN_CXX_')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800106
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700107def build(bld):
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700108 version(bld)
109
110 bld(features="subst",
111 name='version',
112 source='src/version.hpp.in',
113 target='src/version.hpp',
114 install_path=None,
115 VERSION_STRING=VERSION_BASE,
116 VERSION_BUILD=VERSION,
117 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
118 int(VERSION_SPLIT[1]) * 1000 +
119 int(VERSION_SPLIT[2]),
120 VERSION_MAJOR=VERSION_SPLIT[0],
121 VERSION_MINOR=VERSION_SPLIT[1],
122 VERSION_PATCH=VERSION_SPLIT[2],
123 )
124
Alexander Afanasyev766cea72014-04-24 19:16:42 -0700125 libndn_cxx = bld(
Alexander Afanasyev59efe102014-01-29 15:56:30 -0800126 features=['cxx', 'cxxstlib'], # 'cxxshlib',
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700127 # vnum=VERSION,
Alexander Afanasyev766cea72014-04-24 19:16:42 -0700128 target="ndn-cxx",
129 name="ndn-cxx",
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700130 source=bld.path.ant_glob('src/**/*.cpp',
131 excl=['src/**/*-osx.cpp', 'src/**/*-sqlite3.cpp']),
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700132 use='version BOOST OPENSSL LOG4CXX CRYPTOPP SQLITE3 RT PIC PTHREAD',
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700133 includes=". src",
134 export_includes="src",
135 install_path='${LIBDIR}',
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800136 )
137
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -0800138 if bld.env['WITH_PCH']:
Alexander Afanasyev766cea72014-04-24 19:16:42 -0700139 libndn_cxx.pch="src/common.hpp"
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800140
Alexander Afanasyev59d67a52014-04-03 16:09:31 -0700141 if bld.env['HAVE_OSX_SECURITY']:
Alexander Afanasyev766cea72014-04-24 19:16:42 -0700142 libndn_cxx.source += bld.path.ant_glob('src/**/*-osx.cpp')
143 libndn_cxx.mac_app = True
144 libndn_cxx.use += " OSX_COREFOUNDATION OSX_SECURITY"
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800145
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -0800146 # In case we want to make it optional later
Alexander Afanasyev766cea72014-04-24 19:16:42 -0700147 libndn_cxx.source += bld.path.ant_glob('src/**/*-sqlite3.cpp')
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800148
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700149 # Prepare flags that should go to pkgconfig file
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800150 pkgconfig_libs = []
151 pkgconfig_ldflags = []
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800152 pkgconfig_linkflags = []
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800153 pkgconfig_includes = []
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800154 pkgconfig_cxxflags = []
Alexander Afanasyev766cea72014-04-24 19:16:42 -0700155 for lib in Utils.to_list(libndn_cxx.use):
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800156 if bld.env['LIB_%s' % lib]:
157 pkgconfig_libs += Utils.to_list(bld.env['LIB_%s' % lib])
158 if bld.env['LIBPATH_%s' % lib]:
159 pkgconfig_ldflags += Utils.to_list(bld.env['LIBPATH_%s' % lib])
160 if bld.env['INCLUDES_%s' % lib]:
161 pkgconfig_includes += Utils.to_list(bld.env['INCLUDES_%s' % lib])
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800162 if bld.env['LINKFLAGS_%s' % lib]:
163 pkgconfig_linkflags += Utils.to_list(bld.env['LINKFLAGS_%s' % lib])
164 if bld.env['CXXFLAGS_%s' % lib]:
165 pkgconfig_cxxflags += Utils.to_list(bld.env['CXXFLAGS_%s' % lib])
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800166
Alexander Afanasyev84cf4292014-01-29 22:16:27 -0800167 EXTRA_FRAMEWORKS = "";
Alexander Afanasyev59d67a52014-04-03 16:09:31 -0700168 if bld.env['HAVE_OSX_SECURITY']:
Alexander Afanasyev84cf4292014-01-29 22:16:27 -0800169 EXTRA_FRAMEWORKS = "-framework CoreFoundation -framework Security"
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800170
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800171 def uniq(alist):
172 set = {}
173 return [set.setdefault(e,e) for e in alist if e not in set]
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800174
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700175 pkconfig = bld(features="subst",
Alexander Afanasyev766cea72014-04-24 19:16:42 -0700176 source="libndn-cxx.pc.in",
177 target="libndn-cxx.pc",
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700178 install_path="${LIBDIR}/pkgconfig",
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700179 VERSION=VERSION_BASE,
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800180
181 # This probably not the right thing to do, but to simplify life of apps
182 # that use the library
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700183 EXTRA_LIBS=" ".join([('-l%s' % i) for i in uniq(pkgconfig_libs)]),
184 EXTRA_LDFLAGS=" ".join([('-L%s' % i) for i in uniq(pkgconfig_ldflags)]),
185 EXTRA_LINKFLAGS=" ".join(uniq(pkgconfig_linkflags)),
186 EXTRA_INCLUDES=" ".join([('-I%s' % i) for i in uniq(pkgconfig_includes)]),
187 EXTRA_CXXFLAGS=" ".join(uniq(pkgconfig_cxxflags)),
188 EXTRA_FRAMEWORKS=EXTRA_FRAMEWORKS,
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800189 )
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800190
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800191 # Unit tests
192 if bld.env['WITH_TESTS']:
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800193 bld.recurse('tests')
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700194 bld.recurse('tests-integrated')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800195
Yingdi Yue6bfab22014-02-06 16:01:19 -0800196 if bld.env['WITH_TOOLS']:
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700197 bld.recurse("tools")
198
199 if bld.env['WITH_EXAMPLES']:
Yingdi Yue6bfab22014-02-06 16:01:19 -0800200 bld.recurse("examples")
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800201
Alexander Afanasyev19508852014-01-29 01:01:51 -0800202 headers = bld.path.ant_glob(['src/**/*.hpp'])
Alexander Afanasyev766cea72014-04-24 19:16:42 -0700203 bld.install_files("%s/ndn-cxx" % bld.env['INCLUDEDIR'], headers,
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700204 relative_trick=True, cwd=bld.path.find_node('src'))
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800205
Alexander Afanasyev766cea72014-04-24 19:16:42 -0700206 bld.install_files("%s/ndn-cxx" % bld.env['INCLUDEDIR'],
207 bld.path.find_resource('src/ndn-cxx-config.hpp'))
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800208
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700209 bld.install_files("%s/ndn-cxx" % bld.env['INCLUDEDIR'],
210 bld.path.find_resource('src/version.hpp'))
211
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600212 bld.install_files("${SYSCONFDIR}/ndn", "client.conf.sample")
213
Alexander Afanasyev7c6aeb02014-04-10 19:59:19 -0700214 if bld.env['SPHINX_BUILD']:
215 bld(features="sphinx",
216 builder="man",
217 outdir="docs/manpages",
218 config="docs/conf.py",
219 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
Alexander Afanasyeva06fdda2014-04-29 19:15:00 -0700220 install_path="${MANDIR}/",
221 VERSION=VERSION)
Alexander Afanasyev7c6aeb02014-04-10 19:59:19 -0700222
223def docs(bld):
224 from waflib import Options
225 Options.commands = ['doxygen', 'sphinx'] + Options.commands
226
Alexander Afanasyev401a2362014-03-02 00:03:11 +0000227def doxygen(bld):
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700228 version(bld)
229
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800230 if not bld.env.DOXYGEN:
Alexander Afanasyev7c6aeb02014-04-10 19:59:19 -0700231 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
232 else:
Alexander Afanasyeva06fdda2014-04-29 19:15:00 -0700233 bld(features="subst",
234 name="doxygen-conf",
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700235 source=["docs/doxygen.conf.in",
236 "docs/named_data_theme/named_data_footer-with-analytics.html.in"],
237 target=["docs/doxygen.conf",
238 "docs/named_data_theme/named_data_footer-with-analytics.html"],
Alexander Afanasyeva06fdda2014-04-29 19:15:00 -0700239 VERSION=VERSION,
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700240 HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \
241 if os.getenv('GOOGLE_ANALYTICS', None) \
242 else "../docs/named_data_theme/named_data_footer.html",
243 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""),
Alexander Afanasyeva06fdda2014-04-29 19:15:00 -0700244 )
245
Alexander Afanasyev7c6aeb02014-04-10 19:59:19 -0700246 bld(features="doxygen",
Alexander Afanasyeva06fdda2014-04-29 19:15:00 -0700247 doxyfile='docs/doxygen.conf',
248 use="doxygen-conf")
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800249
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700250def sphinx(bld):
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700251 version(bld)
252
Alexander Afanasyev1160baa2014-04-10 18:50:29 -0700253 if not bld.env.SPHINX_BUILD:
254 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
Alexander Afanasyev7c6aeb02014-04-10 19:59:19 -0700255 else:
256 bld(features="sphinx",
257 outdir="docs",
258 source=bld.path.ant_glob("docs/**/*.rst"),
Alexander Afanasyeva06fdda2014-04-29 19:15:00 -0700259 config="docs/conf.py",
260 VERSION=VERSION)
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700261
262
263def version(ctx):
264 if getattr(Context.g_module, 'VERSION_BASE', None):
265 return
266
267 Context.g_module.VERSION_BASE = Context.g_module.VERSION
268 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
269
270 try:
271 cmd = ['git', 'describe', '--match', 'ndn-cxx-*']
272 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
273 stderr=None, stdin=None)
274 out = p.communicate()[0].strip()
275 if p.returncode == 0 and out != "":
276 Context.g_module.VERSION = out[8:]
277 except:
278 pass
279
280def dist(ctx):
281 version(ctx)
282
283def distcheck(ctx):
284 version(ctx)