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 | |
Saurab Dulal | 32b97d7 | 2020-12-12 23:57:36 -0600 | [diff] [blame] | 6 | VERSION = '0.3.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 | 7549628 | 2021-04-25 16:38:22 -0400 | [diff] [blame] | 42 | conf.find_program('dot', var='DOT', mandatory=False) |
| 43 | |
Davide Pesavento | 85a73d2 | 2022-03-06 16:00:01 -0500 | [diff] [blame] | 44 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 47 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 48 | boost_libs = ['system', 'iostreams'] |
| 49 | if conf.env.WITH_TESTS: |
| 50 | boost_libs.append('unit_test_framework') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 51 | |
| 52 | conf.check_boost(lib=boost_libs, mt=True) |
| 53 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 54 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 62 | conf.check_compiler_flags() |
| 63 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 64 | # Loading "late" to prevent tests from being compiled with profiling flags |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 65 | conf.load('coverage') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 66 | 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 Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 71 | conf.env.prepend_value('STLIBPATH', ['.']) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 72 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 73 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 79 | |
| 80 | def build(bld): |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 81 | 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 Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 88 | |
| 89 | if bld.env.WITH_TESTS: |
| 90 | bld.recurse('tests') |
| 91 | |
| 92 | if bld.env.WITH_EXAMPLES: |
| 93 | bld.recurse('examples') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 94 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 95 | headers = bld.path.ant_glob('PSync/**/*.hpp') |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 96 | bld.install_files(bld.env.INCLUDEDIR, headers, |
| 97 | relative_trick=True) |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 98 | |
| 99 | bld.install_files('${INCLUDEDIR}/PSync/detail', |
| 100 | bld.path.find_resource('PSync/detail/config.hpp')) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 101 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 102 | bld(features='subst', |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 103 | source='PSync.pc.in', |
| 104 | target='PSync.pc', |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 105 | install_path='${LIBDIR}/pkgconfig', |
| 106 | VERSION=VERSION) |
Ashlesh Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame] | 107 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 108 | def docs(bld): |
| 109 | from waflib import Options |
| 110 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 111 | |
| 112 | def 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 Pesavento | 7549628 | 2021-04-25 16:38:22 -0400 | [diff] [blame] | 125 | HAVE_DOT='YES' if bld.env.DOT else 'NO', |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 126 | 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 | |
| 135 | def 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 Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 145 | version=VERSION_BASE, |
| 146 | release=VERSION) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 147 | |
| 148 | def 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 Afanasyev | 89edd8f | 2020-06-01 18:58:54 -0400 | [diff] [blame] | 171 | versionFile = ctx.path.find_node('VERSION.info') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 172 | 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 Afanasyev | 89edd8f | 2020-06-01 18:58:54 -0400 | [diff] [blame] | 188 | versionFile = ctx.path.make_node('VERSION.info') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 189 | |
| 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 | |
| 195 | def dist(ctx): |
| 196 | version(ctx) |
| 197 | |
| 198 | def distcheck(ctx): |
| 199 | version(ctx) |