blob: c6595a2258970b3f11e860ece5288674cf7dd802 [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
Davide Pesavento0b272e02023-09-23 20:22:01 -04003import os
4import subprocess
5from waflib import Context, Logs
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05006
Davide Pesaventoec8f8542023-01-18 23:10:24 -05007VERSION = '0.4.0'
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05008APPNAME = 'PSync'
9GIT_TAG_PREFIX = ''
10
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060011BOOST_COMPRESSION_CODE = '''
12#include <boost/iostreams/filter/{0}.hpp>
13int main() {{ boost::iostreams::{0}_compressor test; }}
14'''
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060015COMPRESSION_SCHEMES = ['zlib', 'gzip', 'bzip2', 'lzma', 'zstd']
16
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050017def options(opt):
Davide Pesavento042dfb32020-07-23 21:07:16 -040018 opt.load(['compiler_cxx', 'gnu_dirs'])
19 opt.load(['default-compiler-flags',
20 'coverage', 'sanitizers', 'boost',
21 'doxygen', 'sphinx_build'],
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050022 tooldir=['.waf-tools'])
23
Davide Pesavento17b266c2019-04-06 21:37:43 -040024 optgrp = opt.add_option_group('PSync Options')
25 optgrp.add_option('--with-examples', action='store_true', default=False,
26 help='Build examples')
27 optgrp.add_option('--with-tests', action='store_true', default=False,
28 help='Build unit tests')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050029
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060030 for scheme in COMPRESSION_SCHEMES:
Davide Pesavento0b272e02023-09-23 20:22:01 -040031 optgrp.add_option(f'--without-{scheme}', action='store_true', default=False,
32 help=f'Disable support for {scheme} (de)compression')
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060033
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050034def configure(conf):
Davide Pesavento042dfb32020-07-23 21:07:16 -040035 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesaventoda278492019-01-29 15:00:49 -050036 'default-compiler-flags', 'boost',
37 'doxygen', 'sphinx_build'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050038
Davide Pesavento17b266c2019-04-06 21:37:43 -040039 conf.env.WITH_EXAMPLES = conf.options.with_examples
40 conf.env.WITH_TESTS = conf.options.with_tests
41
Davide Pesaventof2784382022-07-09 19:58:53 -040042 conf.find_program('dot', mandatory=False)
43
44 # Prefer pkgconf if it's installed, because it gives more correct results
45 # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348
46 # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg()
47 conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG')
Davide Pesavento75496282021-04-25 16:38:22 -040048
Davide Pesavento85a73d22022-03-06 16:00:01 -050049 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
Davide Pesaventoec8f8542023-01-18 23:10:24 -050050 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'],
Davide Pesavento85a73d22022-03-06 16:00:01 -050051 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050052
Davide Pesavento0b272e02023-09-23 20:22:01 -040053 conf.check_boost(lib='iostreams', mt=True)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050054
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060055 for scheme in COMPRESSION_SCHEMES:
Davide Pesavento0b272e02023-09-23 20:22:01 -040056 if getattr(conf.options, f'without_{scheme}'):
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060057 continue
58 conf.check_cxx(fragment=BOOST_COMPRESSION_CODE.format(scheme),
59 use='BOOST', execute=False, mandatory=False,
Davide Pesavento0b272e02023-09-23 20:22:01 -040060 msg=f'Checking for {scheme} support in boost iostreams',
61 define_name=f'HAVE_{scheme.upper()}')
62
63 if conf.env.WITH_TESTS:
64 conf.check_boost(lib='unit_test_framework', mt=True, uselib_store='BOOST_TESTS')
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060065
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050066 conf.check_compiler_flags()
67
Davide Pesavento17b266c2019-04-06 21:37:43 -040068 # Loading "late" to prevent tests from being compiled with profiling flags
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050069 conf.load('coverage')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050070 conf.load('sanitizers')
71
72 # If there happens to be a static library, waf will put the corresponding -L flags
73 # before dynamic library flags. This can result in compilation failure when the
74 # system has a different version of the PSync library installed.
Davide Pesavento17b266c2019-04-06 21:37:43 -040075 conf.env.prepend_value('STLIBPATH', ['.'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050076
Davide Pesavento17b266c2019-04-06 21:37:43 -040077 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
78 # The config header will contain all defines that were added using conf.define()
79 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
80 # will not appear in the config header, but will instead be passed directly to the
81 # compiler on the command line.
82 conf.write_config_header('PSync/detail/config.hpp', define_prefix='PSYNC_')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050083
84def build(bld):
Davide Pesavento0b272e02023-09-23 20:22:01 -040085 bld.shlib(
86 target='PSync',
87 vnum=VERSION,
88 cnum=VERSION,
89 source=bld.path.ant_glob('PSync/**/*.cpp'),
90 use='BOOST NDN_CXX',
91 includes='.',
92 export_includes='.')
Davide Pesavento17b266c2019-04-06 21:37:43 -040093
94 if bld.env.WITH_TESTS:
95 bld.recurse('tests')
96
97 if bld.env.WITH_EXAMPLES:
98 bld.recurse('examples')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050099
Davide Pesavento0b272e02023-09-23 20:22:01 -0400100 # Install header files
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -0600101 headers = bld.path.ant_glob('PSync/**/*.hpp')
Davide Pesaventoc407dee2022-07-21 23:56:05 -0400102 bld.install_files('${INCLUDEDIR}', headers, relative_trick=True)
Davide Pesavento0b272e02023-09-23 20:22:01 -0400103 bld.install_files('${INCLUDEDIR}/PSync/detail', 'PSync/detail/config.hpp')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500104
Davide Pesavento17b266c2019-04-06 21:37:43 -0400105 bld(features='subst',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500106 source='PSync.pc.in',
107 target='PSync.pc',
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500108 install_path='${LIBDIR}/pkgconfig',
109 VERSION=VERSION)
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -0500110
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500111def docs(bld):
112 from waflib import Options
113 Options.commands = ['doxygen', 'sphinx'] + Options.commands
114
115def doxygen(bld):
116 version(bld)
117
118 if not bld.env.DOXYGEN:
119 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
120
121 bld(features='subst',
122 name='doxygen.conf',
123 source=['docs/doxygen.conf.in',
124 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
125 target=['docs/doxygen.conf',
126 'docs/named_data_theme/named_data_footer-with-analytics.html'],
127 VERSION=VERSION,
Davide Pesavento75496282021-04-25 16:38:22 -0400128 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500129 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
130 if os.getenv('GOOGLE_ANALYTICS', None) \
131 else '../docs/named_data_theme/named_data_footer.html',
132 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
133
134 bld(features='doxygen',
135 doxyfile='docs/doxygen.conf',
136 use='doxygen.conf')
137
138def sphinx(bld):
139 version(bld)
140
141 if not bld.env.SPHINX_BUILD:
142 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
143
144 bld(features='sphinx',
145 config='docs/conf.py',
146 outdir='docs',
147 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500148 version=VERSION_BASE,
149 release=VERSION)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500150
151def version(ctx):
152 # don't execute more than once
153 if getattr(Context.g_module, 'VERSION_BASE', None):
154 return
155
156 Context.g_module.VERSION_BASE = Context.g_module.VERSION
157 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
158
159 # first, try to get a version string from git
160 gotVersionFromGit = False
161 try:
Davide Pesavento0b272e02023-09-23 20:22:01 -0400162 cmd = ['git', 'describe', '--always', '--match', f'{GIT_TAG_PREFIX}*']
163 out = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500164 if out:
165 gotVersionFromGit = True
166 if out.startswith(GIT_TAG_PREFIX):
167 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
168 else:
169 # no tags matched
Davide Pesavento0b272e02023-09-23 20:22:01 -0400170 Context.g_module.VERSION = f'{VERSION_BASE}-commit-{out}'
171 except (OSError, subprocess.SubprocessError):
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500172 pass
173
Alexander Afanasyev89edd8f2020-06-01 18:58:54 -0400174 versionFile = ctx.path.find_node('VERSION.info')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500175 if not gotVersionFromGit and versionFile is not None:
176 try:
177 Context.g_module.VERSION = versionFile.read()
178 return
179 except EnvironmentError:
180 pass
181
182 # version was obtained from git, update VERSION file if necessary
183 if versionFile is not None:
184 try:
185 if versionFile.read() == Context.g_module.VERSION:
186 # already up-to-date
187 return
188 except EnvironmentError as e:
Davide Pesavento0b272e02023-09-23 20:22:01 -0400189 Logs.warn(f'{versionFile} exists but is not readable ({e.strerror})')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500190 else:
Alexander Afanasyev89edd8f2020-06-01 18:58:54 -0400191 versionFile = ctx.path.make_node('VERSION.info')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500192
193 try:
194 versionFile.write(Context.g_module.VERSION)
195 except EnvironmentError as e:
Davide Pesavento0b272e02023-09-23 20:22:01 -0400196 Logs.warn(f'{versionFile} is not writable ({e.strerror})')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500197
198def dist(ctx):
Davide Pesavento46bac782023-02-19 20:32:24 -0500199 ctx.algo = 'tar.xz'
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500200 version(ctx)
201
202def distcheck(ctx):
Davide Pesavento46bac782023-02-19 20:32:24 -0500203 ctx.algo = 'tar.xz'
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500204 version(ctx)