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 | |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 3 | from waflib import Context, Logs, Utils |
| 4 | import os, subprocess |
| 5 | |
Davide Pesavento | dd00076 | 2020-01-15 01:34:33 -0500 | [diff] [blame] | 6 | VERSION = '0.5.3' |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 7 | APPNAME = 'ChronoSync' |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 8 | GIT_TAG_PREFIX = '' |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 9 | |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 10 | def options(opt): |
Davide Pesavento | 5f408ae | 2020-07-15 21:17:04 -0400 | [diff] [blame] | 11 | opt.load(['compiler_cxx', 'gnu_dirs']) |
| 12 | opt.load(['default-compiler-flags', |
| 13 | 'coverage', 'sanitizers', 'boost', |
| 14 | 'doxygen', 'sphinx_build'], |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 15 | tooldir=['.waf-tools']) |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 16 | |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 17 | optgrp = opt.add_option_group('ChronoSync Options') |
| 18 | optgrp.add_option('--with-tests', action='store_true', default=False, |
| 19 | help='Build unit tests') |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 20 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 21 | def configure(conf): |
Davide Pesavento | 5f408ae | 2020-07-15 21:17:04 -0400 | [diff] [blame] | 22 | conf.load(['compiler_cxx', 'gnu_dirs', |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 23 | 'default-compiler-flags', 'boost', |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 24 | 'doxygen', 'sphinx_build']) |
Alexander Afanasyev | 158ec0d | 2012-04-05 13:48:55 -0700 | [diff] [blame] | 25 | |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 26 | conf.env.WITH_TESTS = conf.options.with_tests |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 27 | |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 28 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX', |
| 29 | pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR)) |
| 30 | |
| 31 | boost_libs = ['system', 'iostreams'] |
| 32 | if conf.env.WITH_TESTS: |
| 33 | boost_libs.append('unit_test_framework') |
| 34 | |
Alexander Afanasyev | 36eb3ed | 2017-01-11 12:35:58 -0800 | [diff] [blame] | 35 | conf.check_boost(lib=boost_libs, mt=True) |
Alexander Afanasyev | 0ad7c21 | 2012-04-05 13:31:14 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | 12d5faa | 2017-09-21 19:04:22 -0400 | [diff] [blame] | 37 | conf.check_compiler_flags() |
| 38 | |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 39 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 40 | conf.load('coverage') |
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. |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 46 | conf.env.prepend_value('STLIBPATH', ['.']) |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 47 | |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame^] | 48 | conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS) |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 49 | # The config header will contain all defines that were added using conf.define() |
| 50 | # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES |
| 51 | # will not appear in the config header, but will instead be passed directly to the |
| 52 | # compiler on the command line. |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame^] | 53 | conf.write_config_header('src/detail/config.hpp', define_prefix='CHRONOSYNC_') |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 54 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 55 | def build(bld): |
Davide Pesavento | fae9def | 2019-01-29 14:34:33 -0500 | [diff] [blame] | 56 | bld.shlib(target='ChronoSync', |
| 57 | vnum=VERSION, |
| 58 | cnum=VERSION, |
| 59 | source=bld.path.ant_glob('src/**/*.cpp'), |
| 60 | use='NDN_CXX BOOST', |
| 61 | includes='src .', |
| 62 | export_includes='src .') |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 63 | |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 64 | if bld.env.WITH_TESTS: |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 65 | bld.recurse('tests') |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 66 | |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame^] | 67 | srcdir = bld.path.find_dir('src') |
| 68 | bld.install_files('${INCLUDEDIR}/ChronoSync', |
| 69 | srcdir.ant_glob('**/*.hpp'), |
| 70 | cwd=srcdir, |
| 71 | relative_trick=True) |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 72 | |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame^] | 73 | bld.install_files('${INCLUDEDIR}/ChronoSync', |
| 74 | 'src/detail/config.hpp', |
| 75 | cwd=bld.path.get_bld().find_dir('src'), |
| 76 | relative_trick=True) |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 77 | |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 78 | bld(features='subst', |
Alexander Afanasyev | 7804c23 | 2013-07-14 12:15:41 -0700 | [diff] [blame] | 79 | source='ChronoSync.pc.in', |
| 80 | target='ChronoSync.pc', |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 81 | install_path='${LIBDIR}/pkgconfig', |
| 82 | VERSION=VERSION) |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 83 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 84 | def docs(bld): |
| 85 | from waflib import Options |
| 86 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 87 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 88 | def doxygen(bld): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 89 | version(bld) |
| 90 | |
Alexander Afanasyev | 34ebcb7 | 2012-03-08 15:54:55 -0800 | [diff] [blame] | 91 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 92 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 94 | bld(features='subst', |
| 95 | name='doxygen.conf', |
| 96 | source=['docs/doxygen.conf.in', |
| 97 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 98 | target=['docs/doxygen.conf', |
| 99 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 100 | VERSION=VERSION, |
| 101 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 102 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 103 | else '../docs/named_data_theme/named_data_footer.html', |
| 104 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 105 | |
| 106 | bld(features='doxygen', |
| 107 | doxyfile='docs/doxygen.conf', |
| 108 | use='doxygen.conf') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 109 | |
| 110 | def sphinx(bld): |
| 111 | version(bld) |
| 112 | |
| 113 | if not bld.env.SPHINX_BUILD: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 114 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 115 | |
| 116 | bld(features='sphinx', |
| 117 | config='docs/conf.py', |
| 118 | outdir='docs', |
| 119 | source=bld.path.ant_glob('docs/**/*.rst'), |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 120 | version=VERSION_BASE, |
| 121 | release=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) |
Davide Pesavento | 4a9395b | 2018-05-24 00:23:22 -0400 | [diff] [blame] | 143 | except (OSError, subprocess.CalledProcessError): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 144 | pass |
| 145 | |
Alexander Afanasyev | 675d6fb | 2020-06-01 18:55:17 -0400 | [diff] [blame] | 146 | versionFile = ctx.path.find_node('VERSION.info') |
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: |
Alexander Afanasyev | 675d6fb | 2020-06-01 18:55:17 -0400 | [diff] [blame] | 163 | versionFile = ctx.path.make_node('VERSION.info') |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 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) |