blob: 89287e8c3039775ab1c133a78ec612b66af82f1f [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 Pesavento34f7eea2019-11-09 17:33:45 -050044 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
45 pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050046
Davide Pesavento17b266c2019-04-06 21:37:43 -040047 boost_libs = ['system', 'iostreams']
48 if conf.env.WITH_TESTS:
49 boost_libs.append('unit_test_framework')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050050
51 conf.check_boost(lib=boost_libs, mt=True)
52
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060053 for scheme in COMPRESSION_SCHEMES:
54 if getattr(conf.options, 'without_{}'.format(scheme)):
55 continue
56 conf.check_cxx(fragment=BOOST_COMPRESSION_CODE.format(scheme),
57 use='BOOST', execute=False, mandatory=False,
58 msg='Checking for {} support in boost iostreams'.format(scheme),
59 define_name='HAVE_{}'.format(scheme.upper()))
60
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050061 conf.check_compiler_flags()
62
Davide Pesavento17b266c2019-04-06 21:37:43 -040063 # Loading "late" to prevent tests from being compiled with profiling flags
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050064 conf.load('coverage')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050065 conf.load('sanitizers')
66
67 # If there happens to be a static library, waf will put the corresponding -L flags
68 # before dynamic library flags. This can result in compilation failure when the
69 # system has a different version of the PSync library installed.
Davide Pesavento17b266c2019-04-06 21:37:43 -040070 conf.env.prepend_value('STLIBPATH', ['.'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050071
Davide Pesavento17b266c2019-04-06 21:37:43 -040072 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
73 # The config header will contain all defines that were added using conf.define()
74 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
75 # will not appear in the config header, but will instead be passed directly to the
76 # compiler on the command line.
77 conf.write_config_header('PSync/detail/config.hpp', define_prefix='PSYNC_')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050078
79def build(bld):
Davide Pesavento34f7eea2019-11-09 17:33:45 -050080 bld.shlib(target='PSync',
81 vnum=VERSION,
82 cnum=VERSION,
83 source=bld.path.ant_glob('PSync/**/*.cpp'),
84 use='NDN_CXX BOOST',
85 includes='.',
86 export_includes='.')
Davide Pesavento17b266c2019-04-06 21:37:43 -040087
88 if bld.env.WITH_TESTS:
89 bld.recurse('tests')
90
91 if bld.env.WITH_EXAMPLES:
92 bld.recurse('examples')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050093
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060094 headers = bld.path.ant_glob('PSync/**/*.hpp')
Davide Pesavento34f7eea2019-11-09 17:33:45 -050095 bld.install_files(bld.env.INCLUDEDIR, headers,
96 relative_trick=True)
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060097
98 bld.install_files('${INCLUDEDIR}/PSync/detail',
99 bld.path.find_resource('PSync/detail/config.hpp'))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500100
Davide Pesavento17b266c2019-04-06 21:37:43 -0400101 bld(features='subst',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500102 source='PSync.pc.in',
103 target='PSync.pc',
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500104 install_path='${LIBDIR}/pkgconfig',
105 VERSION=VERSION)
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -0500106
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500107def docs(bld):
108 from waflib import Options
109 Options.commands = ['doxygen', 'sphinx'] + Options.commands
110
111def doxygen(bld):
112 version(bld)
113
114 if not bld.env.DOXYGEN:
115 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
116
117 bld(features='subst',
118 name='doxygen.conf',
119 source=['docs/doxygen.conf.in',
120 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
121 target=['docs/doxygen.conf',
122 'docs/named_data_theme/named_data_footer-with-analytics.html'],
123 VERSION=VERSION,
Davide Pesavento75496282021-04-25 16:38:22 -0400124 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500125 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
126 if os.getenv('GOOGLE_ANALYTICS', None) \
127 else '../docs/named_data_theme/named_data_footer.html',
128 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
129
130 bld(features='doxygen',
131 doxyfile='docs/doxygen.conf',
132 use='doxygen.conf')
133
134def sphinx(bld):
135 version(bld)
136
137 if not bld.env.SPHINX_BUILD:
138 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
139
140 bld(features='sphinx',
141 config='docs/conf.py',
142 outdir='docs',
143 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500144 version=VERSION_BASE,
145 release=VERSION)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500146
147def version(ctx):
148 # don't execute more than once
149 if getattr(Context.g_module, 'VERSION_BASE', None):
150 return
151
152 Context.g_module.VERSION_BASE = Context.g_module.VERSION
153 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
154
155 # first, try to get a version string from git
156 gotVersionFromGit = False
157 try:
158 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
159 out = subprocess.check_output(cmd, universal_newlines=True).strip()
160 if out:
161 gotVersionFromGit = True
162 if out.startswith(GIT_TAG_PREFIX):
163 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
164 else:
165 # no tags matched
166 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
167 except (OSError, subprocess.CalledProcessError):
168 pass
169
Alexander Afanasyev89edd8f2020-06-01 18:58:54 -0400170 versionFile = ctx.path.find_node('VERSION.info')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500171 if not gotVersionFromGit and versionFile is not None:
172 try:
173 Context.g_module.VERSION = versionFile.read()
174 return
175 except EnvironmentError:
176 pass
177
178 # version was obtained from git, update VERSION file if necessary
179 if versionFile is not None:
180 try:
181 if versionFile.read() == Context.g_module.VERSION:
182 # already up-to-date
183 return
184 except EnvironmentError as e:
185 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
186 else:
Alexander Afanasyev89edd8f2020-06-01 18:58:54 -0400187 versionFile = ctx.path.make_node('VERSION.info')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500188
189 try:
190 versionFile.write(Context.g_module.VERSION)
191 except EnvironmentError as e:
192 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
193
194def dist(ctx):
195 version(ctx)
196
197def distcheck(ctx):
198 version(ctx)