blob: 270ac19b65bfe23c6b0673a83e4c4eabd3169989 [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 Pesavento17b266c2019-04-06 21:37:43 -04003from waflib import Context, Logs, Utils
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05004import os, subprocess
5
Saurab Dulal32b97d72020-12-12 23:57:36 -06006VERSION = '0.3.0'
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05007APPNAME = 'PSync'
8GIT_TAG_PREFIX = ''
9
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060010BOOST_COMPRESSION_CODE = '''
11#include <boost/iostreams/filter/{0}.hpp>
12int main() {{ boost::iostreams::{0}_compressor test; }}
13'''
14
15COMPRESSION_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:
31 optgrp.add_option('--without-{}'.format(scheme), action='store_true', default=False,
32 help='Build without {}'.format(scheme))
33
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 Pesavento75496282021-04-25 16:38:22 -040042 conf.find_program('dot', var='DOT', mandatory=False)
43
Davide Pesavento85a73d22022-03-06 16:00:01 -050044 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
45 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.0', '--cflags', '--libs'],
46 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050047
Davide Pesavento17b266c2019-04-06 21:37:43 -040048 boost_libs = ['system', 'iostreams']
49 if conf.env.WITH_TESTS:
50 boost_libs.append('unit_test_framework')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050051
52 conf.check_boost(lib=boost_libs, mt=True)
53
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060054 for scheme in COMPRESSION_SCHEMES:
55 if getattr(conf.options, 'without_{}'.format(scheme)):
56 continue
57 conf.check_cxx(fragment=BOOST_COMPRESSION_CODE.format(scheme),
58 use='BOOST', execute=False, mandatory=False,
59 msg='Checking for {} support in boost iostreams'.format(scheme),
60 define_name='HAVE_{}'.format(scheme.upper()))
61
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050062 conf.check_compiler_flags()
63
Davide Pesavento17b266c2019-04-06 21:37:43 -040064 # Loading "late" to prevent tests from being compiled with profiling flags
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050065 conf.load('coverage')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050066 conf.load('sanitizers')
67
68 # If there happens to be a static library, waf will put the corresponding -L flags
69 # before dynamic library flags. This can result in compilation failure when the
70 # system has a different version of the PSync library installed.
Davide Pesavento17b266c2019-04-06 21:37:43 -040071 conf.env.prepend_value('STLIBPATH', ['.'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050072
Davide Pesavento17b266c2019-04-06 21:37:43 -040073 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
74 # The config header will contain all defines that were added using conf.define()
75 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
76 # will not appear in the config header, but will instead be passed directly to the
77 # compiler on the command line.
78 conf.write_config_header('PSync/detail/config.hpp', define_prefix='PSYNC_')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050079
80def build(bld):
Davide Pesavento34f7eea2019-11-09 17:33:45 -050081 bld.shlib(target='PSync',
82 vnum=VERSION,
83 cnum=VERSION,
84 source=bld.path.ant_glob('PSync/**/*.cpp'),
85 use='NDN_CXX BOOST',
86 includes='.',
87 export_includes='.')
Davide Pesavento17b266c2019-04-06 21:37:43 -040088
89 if bld.env.WITH_TESTS:
90 bld.recurse('tests')
91
92 if bld.env.WITH_EXAMPLES:
93 bld.recurse('examples')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050094
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060095 headers = bld.path.ant_glob('PSync/**/*.hpp')
Davide Pesavento34f7eea2019-11-09 17:33:45 -050096 bld.install_files(bld.env.INCLUDEDIR, headers,
97 relative_trick=True)
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060098
99 bld.install_files('${INCLUDEDIR}/PSync/detail',
100 bld.path.find_resource('PSync/detail/config.hpp'))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500101
Davide Pesavento17b266c2019-04-06 21:37:43 -0400102 bld(features='subst',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500103 source='PSync.pc.in',
104 target='PSync.pc',
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500105 install_path='${LIBDIR}/pkgconfig',
106 VERSION=VERSION)
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -0500107
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500108def docs(bld):
109 from waflib import Options
110 Options.commands = ['doxygen', 'sphinx'] + Options.commands
111
112def doxygen(bld):
113 version(bld)
114
115 if not bld.env.DOXYGEN:
116 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
117
118 bld(features='subst',
119 name='doxygen.conf',
120 source=['docs/doxygen.conf.in',
121 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
122 target=['docs/doxygen.conf',
123 'docs/named_data_theme/named_data_footer-with-analytics.html'],
124 VERSION=VERSION,
Davide Pesavento75496282021-04-25 16:38:22 -0400125 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500126 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
127 if os.getenv('GOOGLE_ANALYTICS', None) \
128 else '../docs/named_data_theme/named_data_footer.html',
129 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
130
131 bld(features='doxygen',
132 doxyfile='docs/doxygen.conf',
133 use='doxygen.conf')
134
135def sphinx(bld):
136 version(bld)
137
138 if not bld.env.SPHINX_BUILD:
139 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
140
141 bld(features='sphinx',
142 config='docs/conf.py',
143 outdir='docs',
144 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500145 version=VERSION_BASE,
146 release=VERSION)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500147
148def version(ctx):
149 # don't execute more than once
150 if getattr(Context.g_module, 'VERSION_BASE', None):
151 return
152
153 Context.g_module.VERSION_BASE = Context.g_module.VERSION
154 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
155
156 # first, try to get a version string from git
157 gotVersionFromGit = False
158 try:
159 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
160 out = subprocess.check_output(cmd, universal_newlines=True).strip()
161 if out:
162 gotVersionFromGit = True
163 if out.startswith(GIT_TAG_PREFIX):
164 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
165 else:
166 # no tags matched
167 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
168 except (OSError, subprocess.CalledProcessError):
169 pass
170
Alexander Afanasyev89edd8f2020-06-01 18:58:54 -0400171 versionFile = ctx.path.find_node('VERSION.info')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500172 if not gotVersionFromGit and versionFile is not None:
173 try:
174 Context.g_module.VERSION = versionFile.read()
175 return
176 except EnvironmentError:
177 pass
178
179 # version was obtained from git, update VERSION file if necessary
180 if versionFile is not None:
181 try:
182 if versionFile.read() == Context.g_module.VERSION:
183 # already up-to-date
184 return
185 except EnvironmentError as e:
186 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
187 else:
Alexander Afanasyev89edd8f2020-06-01 18:58:54 -0400188 versionFile = ctx.path.make_node('VERSION.info')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500189
190 try:
191 versionFile.write(Context.g_module.VERSION)
192 except EnvironmentError as e:
193 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
194
195def dist(ctx):
196 version(ctx)
197
198def distcheck(ctx):
199 version(ctx)