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