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 | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 3 | VERSION = '0.5.0' |
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, |
| 17 | dest='with_tests', 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): |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 51 | bld.shlib( |
| 52 | target='ChronoSync', |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 53 | vnum = VERSION, |
| 54 | cnum = VERSION, |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 55 | source = bld.path.ant_glob(['src/**/*.cpp', 'src/**/*.proto']), |
Alexander Afanasyev | 36eb3ed | 2017-01-11 12:35:58 -0800 | [diff] [blame] | 56 | use = 'BOOST NDN_CXX', |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 57 | includes = ['src', '.'], |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 58 | export_includes=['src', '.']) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 60 | # Unit tests |
Yingdi Yu | 9d5679a | 2015-02-01 00:17:58 -0800 | [diff] [blame] | 61 | if bld.env["CHRONOSYNC_HAVE_TESTS"]: |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 62 | bld.recurse('tests') |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 63 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 64 | bld.install_files( |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 65 | dest = '%s/ChronoSync' % bld.env['INCLUDEDIR'], |
| 66 | files = bld.path.ant_glob(['src/*.hpp', 'common.hpp']), |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 67 | cwd = bld.path.find_dir("src"), |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 68 | relative_trick = False, |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 69 | ) |
| 70 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 71 | bld.install_files( |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 72 | dest = '%s/ChronoSync' % bld.env['INCLUDEDIR'], |
| 73 | files = bld.path.get_bld().ant_glob(['src/*.hpp', 'common.hpp', 'config.hpp']), |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 74 | cwd = bld.path.get_bld().find_dir("src"), |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 75 | relative_trick = False) |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 76 | |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 77 | bld(features = 'subst', |
Alexander Afanasyev | 7804c23 | 2013-07-14 12:15:41 -0700 | [diff] [blame] | 78 | source='ChronoSync.pc.in', |
| 79 | target='ChronoSync.pc', |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 80 | install_path = '${LIBDIR}/pkgconfig', |
| 81 | PREFIX = bld.env['PREFIX'], |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 82 | INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 83 | VERSION = VERSION) |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 84 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 85 | def docs(bld): |
| 86 | from waflib import Options |
| 87 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 88 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 89 | def doxygen(bld): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 90 | version(bld) |
| 91 | |
Alexander Afanasyev | 34ebcb7 | 2012-03-08 15:54:55 -0800 | [diff] [blame] | 92 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 93 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 94 | |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 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') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 110 | |
| 111 | def sphinx(bld): |
| 112 | version(bld) |
| 113 | |
| 114 | if not bld.env.SPHINX_BUILD: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 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'), |
| 121 | VERSION=VERSION) |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 122 | |
| 123 | def version(ctx): |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 124 | # don't execute more than once |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 125 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 126 | return |
| 127 | |
| 128 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 129 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 130 | |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 131 | # first, try to get a version string from git |
| 132 | gotVersionFromGit = False |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 133 | try: |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 134 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 135 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 136 | if out: |
| 137 | gotVersionFromGit = True |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 138 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 139 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 140 | else: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 141 | # no tags matched |
| 142 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
| 143 | except subprocess.CalledProcessError: |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 144 | pass |
| 145 | |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 146 | versionFile = ctx.path.find_node('VERSION') |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 147 | if not gotVersionFromGit and versionFile is not None: |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 148 | try: |
| 149 | Context.g_module.VERSION = versionFile.read() |
| 150 | return |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 151 | except EnvironmentError: |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 152 | pass |
| 153 | |
| 154 | # version was obtained from git, update VERSION file if necessary |
| 155 | if versionFile is not None: |
| 156 | try: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 157 | if versionFile.read() == Context.g_module.VERSION: |
| 158 | # already up-to-date |
| 159 | return |
| 160 | except EnvironmentError as e: |
| 161 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 162 | else: |
| 163 | versionFile = ctx.path.make_node('VERSION') |
| 164 | |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 165 | try: |
| 166 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame^] | 167 | except EnvironmentError as e: |
| 168 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 169 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 170 | def dist(ctx): |
| 171 | version(ctx) |
| 172 | |
| 173 | def distcheck(ctx): |
| 174 | version(ctx) |