blob: ee0e754aeff6526edf5b936a6bdeeb590ef868e3 [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
6VERSION = '0.1.0'
7APPNAME = '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):
18 opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs'])
Davide Pesaventoda278492019-01-29 15:00:49 -050019 opt.load(['default-compiler-flags', 'coverage', 'sanitizers',
20 'boost', 'doxygen', 'sphinx_build'],
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050021 tooldir=['.waf-tools'])
22
Davide Pesavento17b266c2019-04-06 21:37:43 -040023 optgrp = opt.add_option_group('PSync Options')
24 optgrp.add_option('--with-examples', action='store_true', default=False,
25 help='Build examples')
26 optgrp.add_option('--with-tests', action='store_true', default=False,
27 help='Build unit tests')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050028
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060029 for scheme in COMPRESSION_SCHEMES:
30 optgrp.add_option('--without-{}'.format(scheme), action='store_true', default=False,
31 help='Build without {}'.format(scheme))
32
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050033def configure(conf):
Davide Pesaventoda278492019-01-29 15:00:49 -050034 conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs',
35 'default-compiler-flags', 'boost',
36 'doxygen', 'sphinx_build'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050037
Davide Pesavento17b266c2019-04-06 21:37:43 -040038 conf.env.WITH_EXAMPLES = conf.options.with_examples
39 conf.env.WITH_TESTS = conf.options.with_tests
40
Davide Pesavento34f7eea2019-11-09 17:33:45 -050041 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
42 pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050043
Davide Pesavento17b266c2019-04-06 21:37:43 -040044 boost_libs = ['system', 'iostreams']
45 if conf.env.WITH_TESTS:
46 boost_libs.append('unit_test_framework')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050047
48 conf.check_boost(lib=boost_libs, mt=True)
49
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060050 for scheme in COMPRESSION_SCHEMES:
51 if getattr(conf.options, 'without_{}'.format(scheme)):
52 continue
53 conf.check_cxx(fragment=BOOST_COMPRESSION_CODE.format(scheme),
54 use='BOOST', execute=False, mandatory=False,
55 msg='Checking for {} support in boost iostreams'.format(scheme),
56 define_name='HAVE_{}'.format(scheme.upper()))
57
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050058 conf.check_compiler_flags()
59
Davide Pesavento17b266c2019-04-06 21:37:43 -040060 # Loading "late" to prevent tests from being compiled with profiling flags
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050061 conf.load('coverage')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050062 conf.load('sanitizers')
63
64 # If there happens to be a static library, waf will put the corresponding -L flags
65 # before dynamic library flags. This can result in compilation failure when the
66 # system has a different version of the PSync library installed.
Davide Pesavento17b266c2019-04-06 21:37:43 -040067 conf.env.prepend_value('STLIBPATH', ['.'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050068
Davide Pesavento17b266c2019-04-06 21:37:43 -040069 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
70 # The config header will contain all defines that were added using conf.define()
71 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
72 # will not appear in the config header, but will instead be passed directly to the
73 # compiler on the command line.
74 conf.write_config_header('PSync/detail/config.hpp', define_prefix='PSYNC_')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050075
76def build(bld):
Davide Pesavento34f7eea2019-11-09 17:33:45 -050077 bld.shlib(target='PSync',
78 vnum=VERSION,
79 cnum=VERSION,
80 source=bld.path.ant_glob('PSync/**/*.cpp'),
81 use='NDN_CXX BOOST',
82 includes='.',
83 export_includes='.')
Davide Pesavento17b266c2019-04-06 21:37:43 -040084
85 if bld.env.WITH_TESTS:
86 bld.recurse('tests')
87
88 if bld.env.WITH_EXAMPLES:
89 bld.recurse('examples')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050090
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060091 headers = bld.path.ant_glob('PSync/**/*.hpp')
Davide Pesavento34f7eea2019-11-09 17:33:45 -050092 bld.install_files(bld.env.INCLUDEDIR, headers,
93 relative_trick=True)
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060094
95 bld.install_files('${INCLUDEDIR}/PSync/detail',
96 bld.path.find_resource('PSync/detail/config.hpp'))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050097
Davide Pesavento17b266c2019-04-06 21:37:43 -040098 bld(features='subst',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050099 source='PSync.pc.in',
100 target='PSync.pc',
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500101 install_path='${LIBDIR}/pkgconfig',
102 VERSION=VERSION)
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -0500103
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500104def docs(bld):
105 from waflib import Options
106 Options.commands = ['doxygen', 'sphinx'] + Options.commands
107
108def doxygen(bld):
109 version(bld)
110
111 if not bld.env.DOXYGEN:
112 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
113
114 bld(features='subst',
115 name='doxygen.conf',
116 source=['docs/doxygen.conf.in',
117 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
118 target=['docs/doxygen.conf',
119 'docs/named_data_theme/named_data_footer-with-analytics.html'],
120 VERSION=VERSION,
121 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
122 if os.getenv('GOOGLE_ANALYTICS', None) \
123 else '../docs/named_data_theme/named_data_footer.html',
124 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
125
126 bld(features='doxygen',
127 doxyfile='docs/doxygen.conf',
128 use='doxygen.conf')
129
130def sphinx(bld):
131 version(bld)
132
133 if not bld.env.SPHINX_BUILD:
134 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
135
136 bld(features='sphinx',
137 config='docs/conf.py',
138 outdir='docs',
139 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500140 version=VERSION_BASE,
141 release=VERSION)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500142
143def version(ctx):
144 # don't execute more than once
145 if getattr(Context.g_module, 'VERSION_BASE', None):
146 return
147
148 Context.g_module.VERSION_BASE = Context.g_module.VERSION
149 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
150
151 # first, try to get a version string from git
152 gotVersionFromGit = False
153 try:
154 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
155 out = subprocess.check_output(cmd, universal_newlines=True).strip()
156 if out:
157 gotVersionFromGit = True
158 if out.startswith(GIT_TAG_PREFIX):
159 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
160 else:
161 # no tags matched
162 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
163 except (OSError, subprocess.CalledProcessError):
164 pass
165
166 versionFile = ctx.path.find_node('VERSION')
167 if not gotVersionFromGit and versionFile is not None:
168 try:
169 Context.g_module.VERSION = versionFile.read()
170 return
171 except EnvironmentError:
172 pass
173
174 # version was obtained from git, update VERSION file if necessary
175 if versionFile is not None:
176 try:
177 if versionFile.read() == Context.g_module.VERSION:
178 # already up-to-date
179 return
180 except EnvironmentError as e:
181 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
182 else:
183 versionFile = ctx.path.make_node('VERSION')
184
185 try:
186 versionFile.write(Context.g_module.VERSION)
187 except EnvironmentError as e:
188 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
189
190def dist(ctx):
191 version(ctx)
192
193def distcheck(ctx):
194 version(ctx)