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