blob: 0e35b2cc8091c5f120110d1416e0fbff04d884f0 [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
Davide Pesavento550d8c92023-11-05 01:30:01 -04003import os
4import subprocess
Alexander Afanasyev5560fd42018-03-07 17:03:03 -05005from waflib import Context, Logs, Utils
Alexander Afanasyeva06fdda2014-04-29 19:15:00 -07006
Davide Pesavento81de5d92022-12-30 01:08:05 -05007VERSION = '0.8.1'
Alexander Afanasyev5560fd42018-03-07 17:03:03 -05008APPNAME = 'ndn-cxx'
Alexander Afanasyev5560fd42018-03-07 17:03:03 -05009GIT_TAG_PREFIX = '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'])
Davide Pesavento869d1a32023-03-14 23:55:02 -040013 opt.load(['cross', 'default-compiler-flags', 'pch',
14 'coverage', 'sanitizers', 'osx-frameworks',
Alexander Afanasyevadc71842017-01-26 22:17:58 -050015 'boost', 'openssl', 'sqlite3',
Davide Pesavento1349d2d2016-08-09 06:43:57 +020016 'doxygen', 'sphinx_build'],
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070017 tooldir=['.waf-tools'])
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080018
Davide Pesavento77f1c762019-02-19 03:20:49 -050019 opt = opt.add_option_group('ndn-cxx Options')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080020
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -070021 opt.add_option('--enable-static', action='store_true', default=False,
Davide Pesavento4b8eab72018-09-01 20:10:36 -040022 dest='enable_static', help='Build static library (disabled by default)')
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -070023 opt.add_option('--disable-static', action='store_false', default=False,
Davide Pesavento4b8eab72018-09-01 20:10:36 -040024 dest='enable_static', help='Do not build static library (disabled by default)')
Alexander Afanasyev5519cc72015-03-01 14:25:03 -080025
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -070026 opt.add_option('--enable-shared', action='store_true', default=True,
Davide Pesavento4b8eab72018-09-01 20:10:36 -040027 dest='enable_shared', help='Build shared library (enabled by default)')
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -070028 opt.add_option('--disable-shared', action='store_false', default=True,
Davide Pesavento4b8eab72018-09-01 20:10:36 -040029 dest='enable_shared', help='Do not build shared library (enabled by default)')
Alexander Afanasyev5519cc72015-03-01 14:25:03 -080030
Davide Pesavento77f1c762019-02-19 03:20:49 -050031 opt.add_option('--without-osx-keychain', action='store_false', default=True,
32 dest='with_osx_keychain', help='Do not use macOS Keychain as default TPM (macOS only)')
33
34 opt.add_option('--without-sqlite-locking', action='store_false', default=True, dest='with_sqlite_locking',
35 help='Disable filesystem locking in sqlite3 database '
36 '(use unix-dot locking mechanism instead). '
37 'This option may be necessary if the home directory is hosted on NFS.')
38
39 stacktrace_choices = ['backtrace', 'addr2line', 'basic', 'noop']
40 opt.add_option('--with-stacktrace', action='store', default=None, choices=stacktrace_choices,
41 help='Select the stacktrace backend implementation: '
42 '%s [default=auto-detect]' % ', '.join(stacktrace_choices))
43 opt.add_option('--without-stacktrace', action='store_const', const='', dest='with_stacktrace',
44 help='Disable stacktrace support')
45
46 opt.add_option('--with-examples', action='store_true', default=False,
47 help='Build examples')
48
49 opt.add_option('--with-tests', action='store_true', default=False,
Davide Pesavento906dde52024-02-24 20:52:23 -050050 help='Build all tests (benchmarks, integration tests, unit tests)')
51 opt.add_option('--with-benchmarks', action='store_true', default=False,
52 help='Build benchmarks')
53 opt.add_option('--with-integration-tests', action='store_true', default=False,
54 help='Build integration tests')
55 opt.add_option('--with-unit-tests', action='store_true', default=False,
56 help='Build unit tests')
Davide Pesavento77f1c762019-02-19 03:20:49 -050057
58 opt.add_option('--without-tools', action='store_false', default=True, dest='with_tools',
59 help='Do not build tools')
60
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080061def configure(conf):
Alexander Afanasyev5519cc72015-03-01 14:25:03 -080062 conf.start_msg('Building static library')
63 if conf.options.enable_static:
64 conf.end_msg('yes')
65 else:
66 conf.end_msg('no', color='YELLOW')
67 conf.env.enable_static = conf.options.enable_static
68
69 conf.start_msg('Building shared library')
70 if conf.options.enable_shared:
71 conf.end_msg('yes')
72 else:
73 conf.end_msg('no', color='YELLOW')
74 conf.env.enable_shared = conf.options.enable_shared
75
76 if not conf.options.enable_shared and not conf.options.enable_static:
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050077 conf.fatal('Either static library or shared library must be enabled')
Alexander Afanasyev5519cc72015-03-01 14:25:03 -080078
Davide Pesavento869d1a32023-03-14 23:55:02 -040079 conf.load(['compiler_cxx', 'gnu_dirs', 'c_osx',
80 'cross', 'default-compiler-flags', 'pch',
81 'osx-frameworks', 'boost', 'openssl', 'sqlite3',
Davide Pesavento1349d2d2016-08-09 06:43:57 +020082 'doxygen', 'sphinx_build'])
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080083
Davide Pesavento550d8c92023-11-05 01:30:01 -040084 conf.env.WITH_EXAMPLES = conf.options.with_examples
Davide Pesavento906dde52024-02-24 20:52:23 -050085 conf.env.WITH_BENCHMARKS = conf.options.with_benchmarks or conf.options.with_tests
86 conf.env.WITH_INTEGRATION_TESTS = conf.options.with_integration_tests or conf.options.with_tests
87 conf.env.WITH_UNIT_TESTS = conf.options.with_unit_tests or conf.options.with_tests
Davide Pesaventofd674012019-02-06 02:00:12 -050088 conf.env.WITH_TOOLS = conf.options.with_tools
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080089
Davide Pesavento2d7c5852022-07-18 16:02:52 -040090 conf.find_program('dot', mandatory=False)
Alexander Afanasyev95de62e2014-04-11 18:26:33 -070091
Eric Newberry96033252020-04-10 13:08:27 -070092 conf.check_cxx(lib='atomic', uselib_store='ATOMIC', define_name='HAVE_ATOMIC', mandatory=False)
Davide Pesavento2bf35a62017-04-02 00:41:06 -040093 conf.check_cxx(lib='pthread', uselib_store='PTHREAD', define_name='HAVE_PTHREAD', mandatory=False)
Alexander Afanasyevfff47d62014-05-11 19:24:46 -070094 conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False)
Davide Pesavento78338c52020-04-20 23:00:02 -040095
Davide Pesavento50b92262018-07-11 12:28:31 -040096 conf.check_cxx(msg='Checking for function getpass', define_name='HAVE_GETPASS', mandatory=False,
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050097 fragment='''#include <unistd.h>
98 int main() { getpass("Enter password"); }''')
Alexander Afanasyevfff47d62014-05-11 19:24:46 -070099
Davide Pesavento474c3b22018-08-25 16:24:43 -0400100 if conf.check_cxx(msg='Checking for netlink', define_name='HAVE_NETLINK', mandatory=False,
Davide Pesavento2bf35a62017-04-02 00:41:06 -0400101 header_name=['linux/if_addr.h', 'linux/if_link.h',
Davide Pesavento474c3b22018-08-25 16:24:43 -0400102 'linux/netlink.h', 'linux/rtnetlink.h', 'linux/genetlink.h']):
Davide Pesaventofd674012019-02-06 02:00:12 -0500103 conf.env.HAVE_NETLINK = True
Davide Pesavento50b92262018-07-11 12:28:31 -0400104 conf.check_cxx(msg='Checking for NETLINK_EXT_ACK', define_name='HAVE_NETLINK_EXT_ACK', mandatory=False,
105 fragment='''#include <linux/netlink.h>
106 int main() { return NETLINK_EXT_ACK; }''')
Davide Pesavento2bf35a62017-04-02 00:41:06 -0400107 conf.check_cxx(msg='Checking for IFA_FLAGS', define_name='HAVE_IFA_FLAGS', mandatory=False,
Davide Pesavento844b0932018-05-07 01:00:16 -0400108 fragment='''#include <linux/if_addr.h>
109 int main() { return IFA_FLAGS; }''')
Alexander Afanasyev7b3080f2015-01-28 21:21:01 -0800110
Alexander Afanasyev0cf887d2017-03-26 16:58:59 -0500111 conf.check_osx_frameworks()
Davide Pesavento77f1c762019-02-19 03:20:49 -0500112 conf.check_sqlite3()
Davide Pesavento273ea012022-02-20 17:50:02 -0500113 conf.check_openssl(lib='crypto', atleast_version='1.1.1')
Yingdi Yue6bfab22014-02-06 16:01:19 -0800114
Davide Pesavento550d8c92023-11-05 01:30:01 -0400115 conf.check_boost()
116 if conf.env.BOOST_VERSION_NUMBER < 107100:
117 conf.fatal('The minimum supported version of Boost is 1.71.0.\n'
118 'Please upgrade your distribution or manually install a newer version of Boost.\n'
119 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
120
121 # Boost.Log requires Boost.Thread
122 boost_libs = ['chrono', 'filesystem', 'log', 'thread']
123
124 # Boost.Date_Time is header-only since 1.73
125 if conf.env.BOOST_VERSION_NUMBER < 107300:
126 boost_libs.append('date_time')
Junxiao Shi7d054272016-08-04 17:00:41 +0000127
Davide Pesaventofd674012019-02-06 02:00:12 -0500128 stacktrace_backend = conf.options.with_stacktrace
129 if stacktrace_backend is None:
130 # auto-detect
Davide Pesaventof3089c32021-05-25 21:28:21 -0400131 for candidate in ('backtrace', 'basic'):
Davide Pesaventofd674012019-02-06 02:00:12 -0500132 try:
Davide Pesaventoc9967422023-09-07 22:04:34 -0400133 conf.check_boost(lib=f'stacktrace_{candidate}', mt=True)
Davide Pesaventofd674012019-02-06 02:00:12 -0500134 except conf.errors.ConfigurationError:
135 continue
136 stacktrace_backend = candidate
137 break
138 if stacktrace_backend:
139 conf.env.HAVE_STACKTRACE = True
140 conf.env.append_unique('DEFINES_BOOST', ['BOOST_STACKTRACE_DYN_LINK'])
Davide Pesaventoc9967422023-09-07 22:04:34 -0400141 boost_libs.append(f'stacktrace_{stacktrace_backend}')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800142
Davide Pesaventofd674012019-02-06 02:00:12 -0500143 conf.check_boost(lib=boost_libs, mt=True)
Davide Pesaventod8e0cad2021-05-26 21:43:47 -0400144
Davide Pesavento31bca202024-02-25 23:10:26 -0500145 if conf.env.WITH_BENCHMARKS or conf.env.WITH_INTEGRATION_TESTS or conf.env.WITH_UNIT_TESTS:
Davide Pesavento5686c512023-09-07 22:08:46 -0400146 conf.check_boost(lib='unit_test_framework', mt=True, uselib_store='BOOST_TESTS')
147
148 if conf.env.WITH_TOOLS:
149 conf.check_boost(lib='program_options', mt=True, uselib_store='BOOST_TOOLS')
150
Alexander Afanasyevb82d8c32017-09-21 11:35:07 -0400151 conf.check_compiler_flags()
152
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500153 # Loading "late" to prevent tests from being compiled with profiling flags
Alexander Afanasyev1160baa2014-04-10 18:50:29 -0700154 conf.load('coverage')
Eric Newberrya3973e02016-11-01 17:58:12 -0700155 conf.load('sanitizers')
156
Alexander Afanasyev224044f2016-07-18 10:45:08 +0200157 if not conf.env.enable_static:
158 # If there happens to be a static library, waf will put the corresponding -L flags
159 # before dynamic library flags. This can result in compilation failure when the
160 # system has a different version of the ndn-cxx library installed.
Davide Pesaventofd674012019-02-06 02:00:12 -0500161 conf.env.prepend_value('STLIBPATH', ['.'])
Alexander Afanasyev224044f2016-07-18 10:45:08 +0200162
Davide Pesaventofd674012019-02-06 02:00:12 -0500163 conf.define_cond('HAVE_STACKTRACE', conf.env.HAVE_STACKTRACE)
Davide Pesavento31bca202024-02-25 23:10:26 -0500164 conf.define_cond('WITH_TESTS', conf.env.WITH_INTEGRATION_TESTS or conf.env.WITH_UNIT_TESTS)
Davide Pesaventofd674012019-02-06 02:00:12 -0500165 conf.define_cond('WITH_OSX_KEYCHAIN', conf.env.HAVE_OSX_FRAMEWORKS and conf.options.with_osx_keychain)
166 conf.define_cond('DISABLE_SQLITE3_FS_LOCKING', not conf.options.with_sqlite_locking)
167 conf.define('SYSCONFDIR', conf.env.SYSCONFDIR)
168 # The config header will contain all defines that were added using conf.define()
169 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
170 # will not appear in the config header, but will instead be passed directly to the
171 # compiler on the command line.
Junxiao Shid1fc9a72018-12-12 16:35:34 +0000172 conf.write_config_header('ndn-cxx/detail/config.hpp', define_prefix='NDN_CXX_')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800173
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700174def build(bld):
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700175 version(bld)
176
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500177 bld(features='subst',
178 name='version.hpp',
Davide Pesavento19442812018-11-23 14:00:04 -0500179 source='ndn-cxx/version.hpp.in',
180 target='ndn-cxx/version.hpp',
Davide Pesavento550d8c92023-11-05 01:30:01 -0400181 install_path='${INCLUDEDIR}/ndn-cxx',
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700182 VERSION_STRING=VERSION_BASE,
183 VERSION_BUILD=VERSION,
184 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
185 int(VERSION_SPLIT[1]) * 1000 +
186 int(VERSION_SPLIT[2]),
187 VERSION_MAJOR=VERSION_SPLIT[0],
188 VERSION_MINOR=VERSION_SPLIT[1],
Davide Pesavento1349d2d2016-08-09 06:43:57 +0200189 VERSION_PATCH=VERSION_SPLIT[2])
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700190
Davide Pesaventofd674012019-02-06 02:00:12 -0500191 if bld.env.HAVE_OSX_FRAMEWORKS:
Alexander Afanasyev7cd43ab2017-03-27 21:33:10 -0500192 # Need to disable precompiled headers for Objective-C++ code
Davide Pesavento25d4f1c2020-04-29 23:31:04 -0400193 bld(features='cxx',
Davide Pesavento19442812018-11-23 14:00:04 -0500194 target='ndn-cxx-mm-objects',
195 source=bld.path.ant_glob('ndn-cxx/**/*-osx.mm'),
196 use='BOOST PTHREAD OSX_COREFOUNDATION OSX_SECURITY OSX_SYSTEMCONFIGURATION OSX_FOUNDATION OSX_COREWLAN',
Davide Pesavento7e780642018-11-24 15:51:34 -0500197 includes='.')
Alexander Afanasyev7cd43ab2017-03-27 21:33:10 -0500198
Alexander Afanasyev5519cc72015-03-01 14:25:03 -0800199 libndn_cxx = dict(
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500200 target='ndn-cxx',
Davide Pesavento19442812018-11-23 14:00:04 -0500201 source=bld.path.ant_glob('ndn-cxx/**/*.cpp',
Alexander Afanasyev39535f42019-07-05 22:07:52 -0400202 excl=['ndn-cxx/**/*-android.cpp',
203 'ndn-cxx/**/*-osx.cpp',
204 'ndn-cxx/**/*-sqlite3.cpp',
205 'ndn-cxx/**/*netlink*.cpp']),
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500206 features='pch',
Junxiao Shid1fc9a72018-12-12 16:35:34 +0000207 headers='ndn-cxx/impl/common-pch.hpp',
Eric Newberry96033252020-04-10 13:08:27 -0700208 use='ndn-cxx-mm-objects version BOOST OPENSSL SQLITE3 ATOMIC RT PTHREAD',
Davide Pesavento7e780642018-11-24 15:51:34 -0500209 includes='.',
210 export_includes='.',
Davide Pesavento1349d2d2016-08-09 06:43:57 +0200211 install_path='${LIBDIR}')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800212
Alexander Afanasyev39535f42019-07-05 22:07:52 -0400213 if bld.env.HOST == 'android':
214 libndn_cxx['source'] += bld.path.ant_glob('ndn-cxx/**/*-android.cpp')
215
Davide Pesaventofd674012019-02-06 02:00:12 -0500216 if bld.env.HAVE_OSX_FRAMEWORKS:
Davide Pesavento19442812018-11-23 14:00:04 -0500217 libndn_cxx['source'] += bld.path.ant_glob('ndn-cxx/**/*-osx.cpp')
Davide Pesavento4b8eab72018-09-01 20:10:36 -0400218 libndn_cxx['use'] += ' OSX_COREFOUNDATION OSX_SECURITY OSX_SYSTEMCONFIGURATION OSX_FOUNDATION OSX_COREWLAN'
Alexander Afanasyev0cf887d2017-03-26 16:58:59 -0500219
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -0800220 # In case we want to make it optional later
Davide Pesavento19442812018-11-23 14:00:04 -0500221 libndn_cxx['source'] += bld.path.ant_glob('ndn-cxx/**/*-sqlite3.cpp')
Alexander Afanasyev5519cc72015-03-01 14:25:03 -0800222
Alexander Afanasyev39535f42019-07-05 22:07:52 -0400223 if bld.env.HAVE_NETLINK:
224 libndn_cxx['source'] += bld.path.ant_glob('ndn-cxx/**/*netlink*.cpp')
225
Alexander Afanasyev5519cc72015-03-01 14:25:03 -0800226 if bld.env.enable_shared:
Davide Pesavento550d8c92023-11-05 01:30:01 -0400227 bld.shlib(
228 name='ndn-cxx',
229 vnum=VERSION_BASE,
230 cnum=VERSION_BASE,
231 **libndn_cxx)
Alexander Afanasyev5519cc72015-03-01 14:25:03 -0800232
233 if bld.env.enable_static:
Davide Pesavento550d8c92023-11-05 01:30:01 -0400234 bld.stlib(
235 name='ndn-cxx-static' if bld.env.enable_shared else 'ndn-cxx',
236 **libndn_cxx)
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800237
Davide Pesavento906dde52024-02-24 20:52:23 -0500238 bld.recurse('tests')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800239
Davide Pesaventofd674012019-02-06 02:00:12 -0500240 if bld.env.WITH_TOOLS:
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500241 bld.recurse('tools')
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700242
Davide Pesaventofd674012019-02-06 02:00:12 -0500243 if bld.env.WITH_EXAMPLES:
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500244 bld.recurse('examples')
Alexander Afanasyevf5df8e62014-02-16 19:56:21 -0800245
Davide Pesavento550d8c92023-11-05 01:30:01 -0400246 # Install header files
Davide Pesavento19442812018-11-23 14:00:04 -0500247 headers = bld.path.ant_glob('ndn-cxx/**/*.hpp',
Alexander Afanasyev39535f42019-07-05 22:07:52 -0400248 excl=['ndn-cxx/**/*-android.hpp',
249 'ndn-cxx/**/*-osx.hpp',
Davide Pesavento19442812018-11-23 14:00:04 -0500250 'ndn-cxx/**/*-sqlite3.hpp',
Alexander Afanasyev39535f42019-07-05 22:07:52 -0400251 'ndn-cxx/**/*netlink*.hpp',
Junxiao Shi24c5a002018-12-12 04:47:15 +0000252 'ndn-cxx/**/impl/**/*'])
Davide Pesavento50b92262018-07-11 12:28:31 -0400253
Alexander Afanasyev39535f42019-07-05 22:07:52 -0400254 if bld.env.HOST == 'android':
255 headers += bld.path.ant_glob('ndn-cxx/**/*-android.hpp', excl='ndn-cxx/**/impl/**/*')
256
Davide Pesaventofd674012019-02-06 02:00:12 -0500257 if bld.env.HAVE_OSX_FRAMEWORKS:
Junxiao Shi24c5a002018-12-12 04:47:15 +0000258 headers += bld.path.ant_glob('ndn-cxx/**/*-osx.hpp', excl='ndn-cxx/**/impl/**/*')
Alexander Afanasyev0cf887d2017-03-26 16:58:59 -0500259
Alexander Afanasyev0cf887d2017-03-26 16:58:59 -0500260 # In case we want to make it optional later
Junxiao Shi24c5a002018-12-12 04:47:15 +0000261 headers += bld.path.ant_glob('ndn-cxx/**/*-sqlite3.hpp', excl='ndn-cxx/**/impl/**/*')
Junxiao Shie30aaea2014-12-03 20:48:34 -0700262
Alexander Afanasyev39535f42019-07-05 22:07:52 -0400263 if bld.env.HAVE_NETLINK:
264 headers += bld.path.ant_glob('ndn-cxx/**/*netlink*.hpp', excl='ndn-cxx/**/impl/**/*')
265
Davide Pesaventof3089c32021-05-25 21:28:21 -0400266 bld.install_files('${INCLUDEDIR}', headers, relative_trick=True)
Davide Pesavento550d8c92023-11-05 01:30:01 -0400267 bld.install_files('${INCLUDEDIR}/ndn-cxx/detail', 'ndn-cxx/detail/config.hpp')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800268
Davide Pesavento550d8c92023-11-05 01:30:01 -0400269 # Prepare flags that should go into pkgconfig file
270 pkgconfig_libs = []
271 pkgconfig_ldflags = []
272 pkgconfig_linkflags = []
273 pkgconfig_includes = []
274 pkgconfig_cxxflags = []
275 pkgconfig_defines = []
276 for lib in Utils.to_list(libndn_cxx['use']):
277 if bld.env[f'LIB_{lib}']:
278 pkgconfig_libs += Utils.to_list(bld.env[f'LIB_{lib}'])
279 if bld.env[f'LIBPATH_{lib}']:
280 pkgconfig_ldflags += Utils.to_list(bld.env[f'LIBPATH_{lib}'])
281 if bld.env[f'LINKFLAGS_{lib}']:
282 pkgconfig_linkflags += Utils.to_list(bld.env[f'LINKFLAGS_{lib}'])
283 if bld.env[f'INCLUDES_{lib}']:
284 pkgconfig_includes += Utils.to_list(bld.env[f'INCLUDES_{lib}'])
285 if bld.env[f'CXXFLAGS_{lib}']:
286 pkgconfig_cxxflags += Utils.to_list(bld.env[f'CXXFLAGS_{lib}'])
287 if bld.env[f'DEFINES_{lib}']:
288 pkgconfig_defines += Utils.to_list(bld.env[f'DEFINES_{lib}'])
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700289
Davide Pesavento550d8c92023-11-05 01:30:01 -0400290 EXTRA_FRAMEWORKS = '-framework CoreFoundation -framework Security -framework SystemConfiguration -framework Foundation -framework CoreWLAN'
291
292 def uniq(alist):
293 return list(dict.fromkeys(alist))
294
295 bld(features='subst',
296 source='libndn-cxx.pc.in',
297 target='libndn-cxx.pc',
298 install_path='${LIBDIR}/pkgconfig',
299 VERSION=VERSION_BASE,
300 # This probably not the right thing to do, but to simplify life of apps
301 # that use the library
302 EXTRA_LIBS=' '.join([f'-l{i}' for i in uniq(pkgconfig_libs)]),
303 EXTRA_LDFLAGS=' '.join([f'-L{i}' for i in uniq(pkgconfig_ldflags)]),
304 EXTRA_LINKFLAGS=' '.join(uniq(pkgconfig_linkflags)),
305 EXTRA_INCLUDES=' '.join([f'-I{i}' for i in uniq(pkgconfig_includes)]),
306 EXTRA_CXXFLAGS=' '.join(uniq(pkgconfig_cxxflags) + [f'-D{i}' for i in uniq(pkgconfig_defines)]),
307 EXTRA_FRAMEWORKS=EXTRA_FRAMEWORKS if bld.env.HAVE_OSX_FRAMEWORKS else '')
308
309 # Install sample config
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500310 bld.install_files('${SYSCONFDIR}/ndn', 'client.conf.sample')
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -0600311
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500312 if bld.env.SPHINX_BUILD:
313 bld(features='sphinx',
314 name='manpages',
315 builder='man',
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500316 config='docs/conf.py',
Davide Pesavento4b8eab72018-09-01 20:10:36 -0400317 outdir='docs/manpages',
Davide Pesaventob310efb2019-04-11 22:10:24 -0400318 source=bld.path.ant_glob('docs/manpages/*.rst'),
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500319 install_path='${MANDIR}',
Davide Pesaventob310efb2019-04-11 22:10:24 -0400320 version=VERSION_BASE,
321 release=VERSION)
Alexander Afanasyev7c6aeb02014-04-10 19:59:19 -0700322
323def docs(bld):
324 from waflib import Options
325 Options.commands = ['doxygen', 'sphinx'] + Options.commands
326
Alexander Afanasyev401a2362014-03-02 00:03:11 +0000327def doxygen(bld):
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700328 version(bld)
329
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800330 if not bld.env.DOXYGEN:
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500331 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Alexander Afanasyeva06fdda2014-04-29 19:15:00 -0700332
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500333 bld(features='subst',
334 name='doxygen.conf',
335 source=['docs/doxygen.conf.in',
336 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
337 target=['docs/doxygen.conf',
338 'docs/named_data_theme/named_data_footer-with-analytics.html'],
339 VERSION=VERSION,
Davide Pesaventodbe645f2021-04-16 00:42:52 -0400340 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500341 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
342 if os.getenv('GOOGLE_ANALYTICS', None) \
343 else '../docs/named_data_theme/named_data_footer.html',
344 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
345
346 bld(features='doxygen',
347 doxyfile='docs/doxygen.conf',
348 use='doxygen.conf')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800349
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -0700350def sphinx(bld):
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700351 version(bld)
352
Alexander Afanasyev1160baa2014-04-10 18:50:29 -0700353 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500354 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
355
356 bld(features='sphinx',
357 config='docs/conf.py',
358 outdir='docs',
359 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventob310efb2019-04-11 22:10:24 -0400360 version=VERSION_BASE,
361 release=VERSION)
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700362
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700363def version(ctx):
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500364 # don't execute more than once
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700365 if getattr(Context.g_module, 'VERSION_BASE', None):
366 return
367
368 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500369 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700370
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500371 # first, try to get a version string from git
372 gotVersionFromGit = False
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700373 try:
Davide Pesaventoc9967422023-09-07 22:04:34 -0400374 cmd = ['git', 'describe', '--always', '--match', f'{GIT_TAG_PREFIX}*']
375 out = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500376 if out:
377 gotVersionFromGit = True
Alexander Afanasyev6c632302014-10-31 12:34:11 -0700378 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500379 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyev6c632302014-10-31 12:34:11 -0700380 else:
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500381 # no tags matched
Davide Pesaventoc9967422023-09-07 22:04:34 -0400382 Context.g_module.VERSION = f'{VERSION_BASE}-commit-{out}'
383 except (OSError, subprocess.SubprocessError):
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700384 pass
385
Alexander Afanasyev3de8aac2020-05-28 20:51:43 -0400386 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500387 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyev6c632302014-10-31 12:34:11 -0700388 try:
389 Context.g_module.VERSION = versionFile.read()
390 return
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500391 except EnvironmentError:
Alexander Afanasyev6c632302014-10-31 12:34:11 -0700392 pass
393
394 # version was obtained from git, update VERSION file if necessary
395 if versionFile is not None:
396 try:
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500397 if versionFile.read() == Context.g_module.VERSION:
398 # already up-to-date
399 return
400 except EnvironmentError as e:
Davide Pesaventoc9967422023-09-07 22:04:34 -0400401 Logs.warn(f'{versionFile} exists but is not readable ({e.strerror})')
Alexander Afanasyev6c632302014-10-31 12:34:11 -0700402 else:
Alexander Afanasyev3de8aac2020-05-28 20:51:43 -0400403 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyev6c632302014-10-31 12:34:11 -0700404
Alexander Afanasyev6c632302014-10-31 12:34:11 -0700405 try:
406 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev5560fd42018-03-07 17:03:03 -0500407 except EnvironmentError as e:
Davide Pesaventoc9967422023-09-07 22:04:34 -0400408 Logs.warn(f'{versionFile} is not writable ({e.strerror})')
Alexander Afanasyev6c632302014-10-31 12:34:11 -0700409
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700410def dist(ctx):
Davide Pesaventoae39daf2023-02-14 23:46:46 -0500411 ctx.algo = 'tar.xz'
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700412 version(ctx)
413
414def distcheck(ctx):
Davide Pesaventoae39daf2023-02-14 23:46:46 -0500415 ctx.algo = 'tar.xz'
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -0700416 version(ctx)