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 | |
| 6 | VERSION = '0.1.0' |
| 7 | APPNAME = 'PSync' |
| 8 | GIT_TAG_PREFIX = '' |
| 9 | |
| 10 | def options(opt): |
| 11 | opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) |
Davide Pesavento | da27849 | 2019-01-29 15:00:49 -0500 | [diff] [blame] | 12 | opt.load(['default-compiler-flags', 'coverage', 'sanitizers', |
| 13 | 'boost', 'doxygen', 'sphinx_build'], |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 14 | tooldir=['.waf-tools']) |
| 15 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 16 | optgrp = opt.add_option_group('PSync Options') |
| 17 | optgrp.add_option('--with-examples', action='store_true', default=False, |
| 18 | help='Build examples') |
| 19 | optgrp.add_option('--with-tests', action='store_true', default=False, |
| 20 | help='Build unit tests') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 21 | |
| 22 | def configure(conf): |
Davide Pesavento | da27849 | 2019-01-29 15:00:49 -0500 | [diff] [blame] | 23 | conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', |
| 24 | 'default-compiler-flags', 'boost', |
| 25 | 'doxygen', 'sphinx_build']) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 26 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 27 | conf.env.WITH_EXAMPLES = conf.options.with_examples |
| 28 | conf.env.WITH_TESTS = conf.options.with_tests |
| 29 | |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame^] | 30 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX', |
| 31 | 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] | 32 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 33 | boost_libs = ['system', 'iostreams'] |
| 34 | if conf.env.WITH_TESTS: |
| 35 | boost_libs.append('unit_test_framework') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 36 | |
| 37 | conf.check_boost(lib=boost_libs, mt=True) |
| 38 | |
| 39 | conf.check_compiler_flags() |
| 40 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 41 | # Loading "late" to prevent tests from being compiled with profiling flags |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 42 | conf.load('coverage') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 43 | conf.load('sanitizers') |
| 44 | |
| 45 | # If there happens to be a static library, waf will put the corresponding -L flags |
| 46 | # before dynamic library flags. This can result in compilation failure when the |
| 47 | # system has a different version of the PSync library installed. |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 48 | conf.env.prepend_value('STLIBPATH', ['.']) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 49 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 50 | conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS) |
| 51 | # The config header will contain all defines that were added using conf.define() |
| 52 | # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES |
| 53 | # will not appear in the config header, but will instead be passed directly to the |
| 54 | # compiler on the command line. |
| 55 | conf.write_config_header('PSync/detail/config.hpp', define_prefix='PSYNC_') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 56 | |
| 57 | def build(bld): |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame^] | 58 | bld.shlib(target='PSync', |
| 59 | vnum=VERSION, |
| 60 | cnum=VERSION, |
| 61 | source=bld.path.ant_glob('PSync/**/*.cpp'), |
| 62 | use='NDN_CXX BOOST', |
| 63 | includes='.', |
| 64 | export_includes='.') |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 65 | |
| 66 | if bld.env.WITH_TESTS: |
| 67 | bld.recurse('tests') |
| 68 | |
| 69 | if bld.env.WITH_EXAMPLES: |
| 70 | bld.recurse('examples') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 71 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 72 | headers = bld.path.ant_glob('PSync/**/*.hpp') |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame^] | 73 | bld.install_files(bld.env.INCLUDEDIR, headers, |
| 74 | relative_trick=True) |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 75 | |
| 76 | bld.install_files('${INCLUDEDIR}/PSync/detail', |
| 77 | bld.path.find_resource('PSync/detail/config.hpp')) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 78 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 79 | bld(features='subst', |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 80 | source='PSync.pc.in', |
| 81 | target='PSync.pc', |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame^] | 82 | install_path='${LIBDIR}/pkgconfig', |
| 83 | VERSION=VERSION) |
Ashlesh Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame] | 84 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 85 | def docs(bld): |
| 86 | from waflib import Options |
| 87 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 88 | |
| 89 | def doxygen(bld): |
| 90 | version(bld) |
| 91 | |
| 92 | if not bld.env.DOXYGEN: |
| 93 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
| 94 | |
| 95 | bld(features='subst', |
| 96 | name='doxygen.conf', |
| 97 | source=['docs/doxygen.conf.in', |
| 98 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 99 | target=['docs/doxygen.conf', |
| 100 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 101 | VERSION=VERSION, |
| 102 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 103 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 104 | else '../docs/named_data_theme/named_data_footer.html', |
| 105 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 106 | |
| 107 | bld(features='doxygen', |
| 108 | doxyfile='docs/doxygen.conf', |
| 109 | use='doxygen.conf') |
| 110 | |
| 111 | def sphinx(bld): |
| 112 | version(bld) |
| 113 | |
| 114 | if not bld.env.SPHINX_BUILD: |
| 115 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 116 | |
| 117 | bld(features='sphinx', |
| 118 | config='docs/conf.py', |
| 119 | outdir='docs', |
| 120 | source=bld.path.ant_glob('docs/**/*.rst'), |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame^] | 121 | version=VERSION_BASE, |
| 122 | release=VERSION) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 123 | |
| 124 | def version(ctx): |
| 125 | # don't execute more than once |
| 126 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 127 | return |
| 128 | |
| 129 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 130 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
| 131 | |
| 132 | # first, try to get a version string from git |
| 133 | gotVersionFromGit = False |
| 134 | try: |
| 135 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
| 136 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 137 | if out: |
| 138 | gotVersionFromGit = True |
| 139 | if out.startswith(GIT_TAG_PREFIX): |
| 140 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
| 141 | else: |
| 142 | # no tags matched |
| 143 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
| 144 | except (OSError, subprocess.CalledProcessError): |
| 145 | pass |
| 146 | |
| 147 | versionFile = ctx.path.find_node('VERSION') |
| 148 | if not gotVersionFromGit and versionFile is not None: |
| 149 | try: |
| 150 | Context.g_module.VERSION = versionFile.read() |
| 151 | return |
| 152 | except EnvironmentError: |
| 153 | pass |
| 154 | |
| 155 | # version was obtained from git, update VERSION file if necessary |
| 156 | if versionFile is not None: |
| 157 | try: |
| 158 | if versionFile.read() == Context.g_module.VERSION: |
| 159 | # already up-to-date |
| 160 | return |
| 161 | except EnvironmentError as e: |
| 162 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
| 163 | else: |
| 164 | versionFile = ctx.path.make_node('VERSION') |
| 165 | |
| 166 | try: |
| 167 | versionFile.write(Context.g_module.VERSION) |
| 168 | except EnvironmentError as e: |
| 169 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
| 170 | |
| 171 | def dist(ctx): |
| 172 | version(ctx) |
| 173 | |
| 174 | def distcheck(ctx): |
| 175 | version(ctx) |