blob: c9565f4c3824d4e760d11f6207a99b318e745386 [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
Ashlesh Gawande5a895472020-01-25 18:07:32 -08006VERSION = '0.2.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 Pesavento34f7eea2019-11-09 17:33:45 -050042 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
43 pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050044
Davide Pesavento17b266c2019-04-06 21:37:43 -040045 boost_libs = ['system', 'iostreams']
46 if conf.env.WITH_TESTS:
47 boost_libs.append('unit_test_framework')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050048
49 conf.check_boost(lib=boost_libs, mt=True)
50
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060051 for scheme in COMPRESSION_SCHEMES:
52 if getattr(conf.options, 'without_{}'.format(scheme)):
53 continue
54 conf.check_cxx(fragment=BOOST_COMPRESSION_CODE.format(scheme),
55 use='BOOST', execute=False, mandatory=False,
56 msg='Checking for {} support in boost iostreams'.format(scheme),
57 define_name='HAVE_{}'.format(scheme.upper()))
58
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050059 conf.check_compiler_flags()
60
Davide Pesavento17b266c2019-04-06 21:37:43 -040061 # Loading "late" to prevent tests from being compiled with profiling flags
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050062 conf.load('coverage')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050063 conf.load('sanitizers')
64
65 # If there happens to be a static library, waf will put the corresponding -L flags
66 # before dynamic library flags. This can result in compilation failure when the
67 # system has a different version of the PSync library installed.
Davide Pesavento17b266c2019-04-06 21:37:43 -040068 conf.env.prepend_value('STLIBPATH', ['.'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050069
Davide Pesavento17b266c2019-04-06 21:37:43 -040070 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
71 # The config header will contain all defines that were added using conf.define()
72 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
73 # will not appear in the config header, but will instead be passed directly to the
74 # compiler on the command line.
75 conf.write_config_header('PSync/detail/config.hpp', define_prefix='PSYNC_')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050076
77def build(bld):
Davide Pesavento34f7eea2019-11-09 17:33:45 -050078 bld.shlib(target='PSync',
79 vnum=VERSION,
80 cnum=VERSION,
81 source=bld.path.ant_glob('PSync/**/*.cpp'),
82 use='NDN_CXX BOOST',
83 includes='.',
84 export_includes='.')
Davide Pesavento17b266c2019-04-06 21:37:43 -040085
86 if bld.env.WITH_TESTS:
87 bld.recurse('tests')
88
89 if bld.env.WITH_EXAMPLES:
90 bld.recurse('examples')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050091
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060092 headers = bld.path.ant_glob('PSync/**/*.hpp')
Davide Pesavento34f7eea2019-11-09 17:33:45 -050093 bld.install_files(bld.env.INCLUDEDIR, headers,
94 relative_trick=True)
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060095
96 bld.install_files('${INCLUDEDIR}/PSync/detail',
97 bld.path.find_resource('PSync/detail/config.hpp'))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050098
Davide Pesavento17b266c2019-04-06 21:37:43 -040099 bld(features='subst',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500100 source='PSync.pc.in',
101 target='PSync.pc',
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500102 install_path='${LIBDIR}/pkgconfig',
103 VERSION=VERSION)
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -0500104
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500105def docs(bld):
106 from waflib import Options
107 Options.commands = ['doxygen', 'sphinx'] + Options.commands
108
109def doxygen(bld):
110 version(bld)
111
112 if not bld.env.DOXYGEN:
113 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
114
115 bld(features='subst',
116 name='doxygen.conf',
117 source=['docs/doxygen.conf.in',
118 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
119 target=['docs/doxygen.conf',
120 'docs/named_data_theme/named_data_footer-with-analytics.html'],
121 VERSION=VERSION,
122 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
123 if os.getenv('GOOGLE_ANALYTICS', None) \
124 else '../docs/named_data_theme/named_data_footer.html',
125 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
126
127 bld(features='doxygen',
128 doxyfile='docs/doxygen.conf',
129 use='doxygen.conf')
130
131def sphinx(bld):
132 version(bld)
133
134 if not bld.env.SPHINX_BUILD:
135 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
136
137 bld(features='sphinx',
138 config='docs/conf.py',
139 outdir='docs',
140 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500141 version=VERSION_BASE,
142 release=VERSION)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500143
144def version(ctx):
145 # don't execute more than once
146 if getattr(Context.g_module, 'VERSION_BASE', None):
147 return
148
149 Context.g_module.VERSION_BASE = Context.g_module.VERSION
150 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
151
152 # first, try to get a version string from git
153 gotVersionFromGit = False
154 try:
155 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
156 out = subprocess.check_output(cmd, universal_newlines=True).strip()
157 if out:
158 gotVersionFromGit = True
159 if out.startswith(GIT_TAG_PREFIX):
160 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
161 else:
162 # no tags matched
163 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
164 except (OSError, subprocess.CalledProcessError):
165 pass
166
Alexander Afanasyev89edd8f2020-06-01 18:58:54 -0400167 versionFile = ctx.path.find_node('VERSION.info')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500168 if not gotVersionFromGit and versionFile is not None:
169 try:
170 Context.g_module.VERSION = versionFile.read()
171 return
172 except EnvironmentError:
173 pass
174
175 # version was obtained from git, update VERSION file if necessary
176 if versionFile is not None:
177 try:
178 if versionFile.read() == Context.g_module.VERSION:
179 # already up-to-date
180 return
181 except EnvironmentError as e:
182 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
183 else:
Alexander Afanasyev89edd8f2020-06-01 18:58:54 -0400184 versionFile = ctx.path.make_node('VERSION.info')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500185
186 try:
187 versionFile.write(Context.g_module.VERSION)
188 except EnvironmentError as e:
189 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
190
191def dist(ctx):
192 version(ctx)
193
194def distcheck(ctx):
195 version(ctx)