Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 3 | from waflib import Context, Logs, Utils |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 4 | import os, subprocess |
| 5 | |
Ashlesh Gawande | 5a89547 | 2020-01-25 18:07:32 -0800 | [diff] [blame] | 6 | VERSION = '0.2.0' |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 7 | APPNAME = 'PSync' |
| 8 | GIT_TAG_PREFIX = '' |
| 9 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 10 | BOOST_COMPRESSION_CODE = ''' |
| 11 | #include <boost/iostreams/filter/{0}.hpp> |
| 12 | int main() {{ boost::iostreams::{0}_compressor test; }} |
| 13 | ''' |
| 14 | |
| 15 | COMPRESSION_SCHEMES = ['zlib', 'gzip', 'bzip2', 'lzma', 'zstd'] |
| 16 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 17 | def options(opt): |
Davide Pesavento | 042dfb3 | 2020-07-23 21:07:16 -0400 | [diff] [blame] | 18 | opt.load(['compiler_cxx', 'gnu_dirs']) |
| 19 | opt.load(['default-compiler-flags', |
| 20 | 'coverage', 'sanitizers', 'boost', |
| 21 | 'doxygen', 'sphinx_build'], |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 22 | tooldir=['.waf-tools']) |
| 23 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 24 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 29 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 30 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 34 | def configure(conf): |
Davide Pesavento | 042dfb3 | 2020-07-23 21:07:16 -0400 | [diff] [blame] | 35 | conf.load(['compiler_cxx', 'gnu_dirs', |
Davide Pesavento | da27849 | 2019-01-29 15:00:49 -0500 | [diff] [blame] | 36 | 'default-compiler-flags', 'boost', |
| 37 | 'doxygen', 'sphinx_build']) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 38 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 39 | conf.env.WITH_EXAMPLES = conf.options.with_examples |
| 40 | conf.env.WITH_TESTS = conf.options.with_tests |
| 41 | |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 42 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 44 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 45 | boost_libs = ['system', 'iostreams'] |
| 46 | if conf.env.WITH_TESTS: |
| 47 | boost_libs.append('unit_test_framework') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 48 | |
| 49 | conf.check_boost(lib=boost_libs, mt=True) |
| 50 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 51 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 59 | conf.check_compiler_flags() |
| 60 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 61 | # Loading "late" to prevent tests from being compiled with profiling flags |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 62 | conf.load('coverage') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 63 | 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 Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 68 | conf.env.prepend_value('STLIBPATH', ['.']) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 69 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 70 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 76 | |
| 77 | def build(bld): |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 78 | 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 Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 85 | |
| 86 | if bld.env.WITH_TESTS: |
| 87 | bld.recurse('tests') |
| 88 | |
| 89 | if bld.env.WITH_EXAMPLES: |
| 90 | bld.recurse('examples') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 91 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 92 | headers = bld.path.ant_glob('PSync/**/*.hpp') |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 93 | bld.install_files(bld.env.INCLUDEDIR, headers, |
| 94 | relative_trick=True) |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 95 | |
| 96 | bld.install_files('${INCLUDEDIR}/PSync/detail', |
| 97 | bld.path.find_resource('PSync/detail/config.hpp')) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 98 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 99 | bld(features='subst', |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 100 | source='PSync.pc.in', |
| 101 | target='PSync.pc', |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 102 | install_path='${LIBDIR}/pkgconfig', |
| 103 | VERSION=VERSION) |
Ashlesh Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame] | 104 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 105 | def docs(bld): |
| 106 | from waflib import Options |
| 107 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 108 | |
| 109 | def 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 | |
| 131 | def 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 Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 141 | version=VERSION_BASE, |
| 142 | release=VERSION) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 143 | |
| 144 | def 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 Afanasyev | 89edd8f | 2020-06-01 18:58:54 -0400 | [diff] [blame] | 167 | versionFile = ctx.path.find_node('VERSION.info') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 168 | 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 Afanasyev | 89edd8f | 2020-06-01 18:58:54 -0400 | [diff] [blame] | 184 | versionFile = ctx.path.make_node('VERSION.info') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 185 | |
| 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 | |
| 191 | def dist(ctx): |
| 192 | version(ctx) |
| 193 | |
| 194 | def distcheck(ctx): |
| 195 | version(ctx) |