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 | 3fb27eb | 2022-12-31 14:00:51 -0500 | [diff] [blame] | 6 | VERSION = '0.5.5' |
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 | 9c4bd6d | 2022-07-26 15:28:08 -0400 | [diff] [blame] | 28 | conf.find_program('dot', mandatory=False) |
| 29 | |
| 30 | # Prefer pkgconf if it's installed, because it gives more correct results |
| 31 | # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348 |
| 32 | # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg() |
| 33 | conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG') |
| 34 | |
Davide Pesavento | 5a6292d | 2022-03-12 15:26:16 -0500 | [diff] [blame] | 35 | pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig') |
Davide Pesavento | 3fb27eb | 2022-12-31 14:00:51 -0500 | [diff] [blame] | 36 | conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'], |
Davide Pesavento | 5a6292d | 2022-03-12 15:26:16 -0500 | [diff] [blame] | 37 | uselib_store='NDN_CXX', pkg_config_path=pkg_config_path) |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 38 | |
| 39 | boost_libs = ['system', 'iostreams'] |
| 40 | if conf.env.WITH_TESTS: |
| 41 | boost_libs.append('unit_test_framework') |
| 42 | |
Alexander Afanasyev | 36eb3ed | 2017-01-11 12:35:58 -0800 | [diff] [blame] | 43 | conf.check_boost(lib=boost_libs, mt=True) |
Alexander Afanasyev | 0ad7c21 | 2012-04-05 13:31:14 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | 12d5faa | 2017-09-21 19:04:22 -0400 | [diff] [blame] | 45 | conf.check_compiler_flags() |
| 46 | |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 47 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 48 | conf.load('coverage') |
Ashlesh Gawande | 687cf92 | 2017-05-30 15:04:16 -0500 | [diff] [blame] | 49 | conf.load('sanitizers') |
| 50 | |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 51 | # If there happens to be a static library, waf will put the corresponding -L flags |
| 52 | # before dynamic library flags. This can result in compilation failure when the |
| 53 | # system has a different version of the ChronoSync library installed. |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 54 | conf.env.prepend_value('STLIBPATH', ['.']) |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 55 | |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame] | 56 | conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS) |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 57 | # The config header will contain all defines that were added using conf.define() |
| 58 | # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES |
| 59 | # will not appear in the config header, but will instead be passed directly to the |
| 60 | # compiler on the command line. |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame] | 61 | conf.write_config_header('src/detail/config.hpp', define_prefix='CHRONOSYNC_') |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 62 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 63 | def build(bld): |
Davide Pesavento | fae9def | 2019-01-29 14:34:33 -0500 | [diff] [blame] | 64 | bld.shlib(target='ChronoSync', |
| 65 | vnum=VERSION, |
| 66 | cnum=VERSION, |
| 67 | source=bld.path.ant_glob('src/**/*.cpp'), |
| 68 | use='NDN_CXX BOOST', |
Davide Pesavento | 780e646 | 2021-02-08 20:58:12 -0500 | [diff] [blame] | 69 | includes='src/detail', |
| 70 | export_includes='src src/detail') |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 71 | |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 72 | if bld.env.WITH_TESTS: |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 73 | bld.recurse('tests') |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 74 | |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame] | 75 | srcdir = bld.path.find_dir('src') |
| 76 | bld.install_files('${INCLUDEDIR}/ChronoSync', |
| 77 | srcdir.ant_glob('**/*.hpp'), |
| 78 | cwd=srcdir, |
| 79 | relative_trick=True) |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 80 | |
Davide Pesavento | 07684bc | 2021-02-07 20:09:28 -0500 | [diff] [blame] | 81 | bld.install_files('${INCLUDEDIR}/ChronoSync', |
| 82 | 'src/detail/config.hpp', |
| 83 | cwd=bld.path.get_bld().find_dir('src'), |
| 84 | relative_trick=True) |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 85 | |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 86 | bld(features='subst', |
Alexander Afanasyev | 7804c23 | 2013-07-14 12:15:41 -0700 | [diff] [blame] | 87 | source='ChronoSync.pc.in', |
| 88 | target='ChronoSync.pc', |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 89 | install_path='${LIBDIR}/pkgconfig', |
| 90 | VERSION=VERSION) |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 91 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 92 | def docs(bld): |
| 93 | from waflib import Options |
| 94 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 95 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 96 | def doxygen(bld): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 97 | version(bld) |
| 98 | |
Alexander Afanasyev | 34ebcb7 | 2012-03-08 15:54:55 -0800 | [diff] [blame] | 99 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 100 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 101 | |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 102 | bld(features='subst', |
| 103 | name='doxygen.conf', |
| 104 | source=['docs/doxygen.conf.in', |
| 105 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 106 | target=['docs/doxygen.conf', |
| 107 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 108 | VERSION=VERSION, |
Davide Pesavento | 9c4bd6d | 2022-07-26 15:28:08 -0400 | [diff] [blame] | 109 | HAVE_DOT='YES' if bld.env.DOT else 'NO', |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 110 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 111 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 112 | else '../docs/named_data_theme/named_data_footer.html', |
| 113 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 114 | |
| 115 | bld(features='doxygen', |
| 116 | doxyfile='docs/doxygen.conf', |
| 117 | use='doxygen.conf') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 118 | |
| 119 | def sphinx(bld): |
| 120 | version(bld) |
| 121 | |
| 122 | if not bld.env.SPHINX_BUILD: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 123 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 124 | |
| 125 | bld(features='sphinx', |
| 126 | config='docs/conf.py', |
| 127 | outdir='docs', |
| 128 | source=bld.path.ant_glob('docs/**/*.rst'), |
Davide Pesavento | c47774f | 2019-11-09 17:25:09 -0500 | [diff] [blame] | 129 | version=VERSION_BASE, |
| 130 | release=VERSION) |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 131 | |
| 132 | def version(ctx): |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 133 | # don't execute more than once |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 134 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 135 | return |
| 136 | |
| 137 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 138 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 139 | |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 140 | # first, try to get a version string from git |
| 141 | gotVersionFromGit = False |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 142 | try: |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 143 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 144 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 145 | if out: |
| 146 | gotVersionFromGit = True |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 147 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 148 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 149 | else: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 150 | # no tags matched |
| 151 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
Davide Pesavento | 4a9395b | 2018-05-24 00:23:22 -0400 | [diff] [blame] | 152 | except (OSError, subprocess.CalledProcessError): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 153 | pass |
| 154 | |
Alexander Afanasyev | 675d6fb | 2020-06-01 18:55:17 -0400 | [diff] [blame] | 155 | versionFile = ctx.path.find_node('VERSION.info') |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 156 | if not gotVersionFromGit and versionFile is not None: |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 157 | try: |
| 158 | Context.g_module.VERSION = versionFile.read() |
| 159 | return |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 160 | except EnvironmentError: |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 161 | pass |
| 162 | |
| 163 | # version was obtained from git, update VERSION file if necessary |
| 164 | if versionFile is not None: |
| 165 | try: |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 166 | if versionFile.read() == Context.g_module.VERSION: |
| 167 | # already up-to-date |
| 168 | return |
| 169 | except EnvironmentError as e: |
| 170 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 171 | else: |
Alexander Afanasyev | 675d6fb | 2020-06-01 18:55:17 -0400 | [diff] [blame] | 172 | versionFile = ctx.path.make_node('VERSION.info') |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 173 | |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 174 | try: |
| 175 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 40491df | 2018-03-09 16:29:52 -0500 | [diff] [blame] | 176 | except EnvironmentError as e: |
| 177 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame] | 178 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 179 | def dist(ctx): |
Davide Pesavento | 2ff1056 | 2023-02-19 20:14:06 -0500 | [diff] [blame] | 180 | ctx.algo = 'tar.xz' |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 181 | version(ctx) |
| 182 | |
| 183 | def distcheck(ctx): |
Davide Pesavento | 2ff1056 | 2023-02-19 20:14:06 -0500 | [diff] [blame] | 184 | ctx.algo = 'tar.xz' |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 185 | version(ctx) |