Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Alexander Afanasyev | e19f3f6 | 2018-10-16 11:25:27 -0400 | [diff] [blame] | 3 | VERSION = '0.5.2' |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 4 | APPNAME = 'ChronoSync' |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 5 | GIT_TAG_PREFIX = '' |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 6 | |
| 7 | from waflib import Logs, Utils, Context |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 8 | import os, subprocess |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 9 | |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 10 | def options(opt): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 11 | opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 12 | opt.load(['default-compiler-flags', 'boost', 'doxygen', 'sphinx_build', |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 13 | 'coverage', 'sanitizers'], |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 14 | tooldir=['.waf-tools']) |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 15 | |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 16 | opt.add_option('--with-tests', action='store_true', default=False, |
Davide Pesavento | fae9def | 2019-01-29 14:34:33 -0500 | [diff] [blame^] | 17 | help='Build unit tests') |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 18 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 19 | def configure(conf): |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 20 | conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 21 | 'default-compiler-flags', 'boost', 'coverage', |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 22 | 'doxygen', 'sphinx_build']) |
Alexander Afanasyev | 158ec0d | 2012-04-05 13:48:55 -0700 | [diff] [blame] | 23 | |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 24 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 25 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 26 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 27 | uselib_store='NDN_CXX', mandatory=True) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 28 | |
Alexander Afanasyev | 36eb3ed | 2017-01-11 12:35:58 -0800 | [diff] [blame] | 29 | boost_libs = 'system iostreams thread log log_setup' |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 30 | if conf.options.with_tests: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 31 | conf.env['CHRONOSYNC_HAVE_TESTS'] = True |
| 32 | conf.define('CHRONOSYNC_HAVE_TESTS', 1) |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 33 | boost_libs += ' unit_test_framework' |
Alexander Afanasyev | 36eb3ed | 2017-01-11 12:35:58 -0800 | [diff] [blame] | 34 | conf.check_boost(lib=boost_libs, mt=True) |
Alexander Afanasyev | 0ad7c21 | 2012-04-05 13:31:14 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 12d5faa | 2017-09-21 19:04:22 -0400 | [diff] [blame] | 36 | conf.check_compiler_flags() |
| 37 | |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 38 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 39 | conf.load('coverage') |
| 40 | |
Ashlesh Gawande | 687cf92 | 2017-05-30 15:04:16 -0500 | [diff] [blame] | 41 | conf.load('sanitizers') |
| 42 | |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 43 | # If there happens to be a static library, waf will put the corresponding -L flags |
| 44 | # before dynamic library flags. This can result in compilation failure when the |
| 45 | # system has a different version of the ChronoSync library installed. |
| 46 | conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH'] |
| 47 | |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 48 | conf.write_config_header('config.hpp') |
| 49 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 50 | def build(bld): |
Davide Pesavento | fae9def | 2019-01-29 14:34:33 -0500 | [diff] [blame^] | 51 | bld.shlib(target='ChronoSync', |
| 52 | vnum=VERSION, |
| 53 | cnum=VERSION, |
| 54 | source=bld.path.ant_glob('src/**/*.cpp'), |
| 55 | use='NDN_CXX BOOST', |
| 56 | includes='src .', |
| 57 | export_includes='src .') |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 58 | |
Davide Pesavento | fae9def | 2019-01-29 14:34:33 -0500 | [diff] [blame^] | 59 | if bld.env['CHRONOSYNC_HAVE_TESTS']: |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 60 | bld.recurse('tests') |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 61 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 62 | bld.install_files( |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 63 | dest = '%s/ChronoSync' % bld.env['INCLUDEDIR'], |
| 64 | files = bld.path.ant_glob(['src/*.hpp', 'common.hpp']), |
Davide Pesavento | fae9def | 2019-01-29 14:34:33 -0500 | [diff] [blame^] | 65 | cwd = bld.path.find_dir('src'), |
| 66 | relative_trick = False) |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 67 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 68 | bld.install_files( |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 69 | dest = '%s/ChronoSync' % bld.env['INCLUDEDIR'], |
| 70 | files = bld.path.get_bld().ant_glob(['src/*.hpp', 'common.hpp', 'config.hpp']), |
Davide Pesavento | fae9def | 2019-01-29 14:34:33 -0500 | [diff] [blame^] | 71 | cwd = bld.path.get_bld().find_dir('src'), |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 72 | relative_trick = False) |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 73 | |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 74 | bld(features = 'subst', |
Alexander Afanasyev | 7804c23 | 2013-07-14 12:15:41 -0700 | [diff] [blame] | 75 | source='ChronoSync.pc.in', |
| 76 | target='ChronoSync.pc', |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 77 | install_path = '${LIBDIR}/pkgconfig', |
| 78 | PREFIX = bld.env['PREFIX'], |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 79 | INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 80 | VERSION = VERSION) |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 81 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 82 | def docs(bld): |
| 83 | from waflib import Options |
| 84 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 85 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 86 | def doxygen(bld): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 87 | version(bld) |
| 88 | |
Alexander Afanasyev | 34ebcb7 | 2012-03-08 15:54:55 -0800 | [diff] [blame] | 89 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 90 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 91 | |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 92 | bld(features='subst', |
| 93 | name='doxygen.conf', |
| 94 | source=['docs/doxygen.conf.in', |
| 95 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 96 | target=['docs/doxygen.conf', |
| 97 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 98 | VERSION=VERSION, |
| 99 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 100 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 101 | else '../docs/named_data_theme/named_data_footer.html', |
| 102 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 103 | |
| 104 | bld(features='doxygen', |
| 105 | doxyfile='docs/doxygen.conf', |
| 106 | use='doxygen.conf') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 107 | |
| 108 | def sphinx(bld): |
| 109 | version(bld) |
| 110 | |
| 111 | if not bld.env.SPHINX_BUILD: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 112 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 113 | |
| 114 | bld(features='sphinx', |
| 115 | config='docs/conf.py', |
| 116 | outdir='docs', |
| 117 | source=bld.path.ant_glob('docs/**/*.rst'), |
| 118 | VERSION=VERSION) |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 119 | |
| 120 | def version(ctx): |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 121 | # don't execute more than once |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 122 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 123 | return |
| 124 | |
| 125 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 126 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 127 | |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 128 | # first, try to get a version string from git |
| 129 | gotVersionFromGit = False |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 130 | try: |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 131 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 132 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 133 | if out: |
| 134 | gotVersionFromGit = True |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 135 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 136 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 137 | else: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 138 | # no tags matched |
| 139 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
Davide Pesavento | 4a9395b | 2018-05-24 00:23:22 -0400 | [diff] [blame] | 140 | except (OSError, subprocess.CalledProcessError): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 141 | pass |
| 142 | |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 143 | versionFile = ctx.path.find_node('VERSION') |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 144 | if not gotVersionFromGit and versionFile is not None: |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 145 | try: |
| 146 | Context.g_module.VERSION = versionFile.read() |
| 147 | return |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 148 | except EnvironmentError: |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 149 | pass |
| 150 | |
| 151 | # version was obtained from git, update VERSION file if necessary |
| 152 | if versionFile is not None: |
| 153 | try: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 154 | if versionFile.read() == Context.g_module.VERSION: |
| 155 | # already up-to-date |
| 156 | return |
| 157 | except EnvironmentError as e: |
| 158 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 159 | else: |
| 160 | versionFile = ctx.path.make_node('VERSION') |
| 161 | |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 162 | try: |
| 163 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 164 | except EnvironmentError as e: |
| 165 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 166 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 167 | def dist(ctx): |
| 168 | version(ctx) |
| 169 | |
| 170 | def distcheck(ctx): |
| 171 | version(ctx) |