Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Davide Pesavento | 84348a2 | 2023-09-14 02:40:41 -0400 | [diff] [blame] | 3 | import os |
| 4 | import subprocess |
| 5 | from waflib import Context, Logs |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 6 | |
| 7 | VERSION = '0.1.0' |
| 8 | APPNAME = 'ndn-nac' |
Davide Pesavento | 44b0f8c | 2024-04-23 00:16:11 -0400 | [diff] [blame] | 9 | GIT_TAG_PREFIX = 'ndn-nac-' |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 10 | |
| 11 | def options(opt): |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 12 | opt.load(['compiler_cxx', 'gnu_dirs']) |
Davide Pesavento | d4689c8 | 2021-10-07 02:53:03 -0400 | [diff] [blame] | 13 | opt.load(['default-compiler-flags', |
| 14 | 'coverage', 'sanitizers', 'boost', |
Davide Pesavento | ecb2db1 | 2024-03-13 19:00:03 -0400 | [diff] [blame] | 15 | 'doxygen', 'sphinx'], |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 16 | tooldir=['.waf-tools']) |
| 17 | |
Davide Pesavento | 969d0f3 | 2023-09-14 14:28:41 -0400 | [diff] [blame] | 18 | optgrp = opt.add_option_group('NAC Options') |
Davide Pesavento | d4689c8 | 2021-10-07 02:53:03 -0400 | [diff] [blame] | 19 | optgrp.add_option('--with-examples', action='store_true', default=False, |
| 20 | help='Build examples') |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 21 | optgrp.add_option('--with-tests', action='store_true', default=False, |
| 22 | help='Build unit tests') |
Davide Pesavento | 969d0f3 | 2023-09-14 14:28:41 -0400 | [diff] [blame] | 23 | optgrp.add_option('--without-tools', action='store_false', default=True, dest='with_tools', |
| 24 | help='Do not build tools') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 25 | |
| 26 | def configure(conf): |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 27 | conf.load(['compiler_cxx', 'gnu_dirs', |
| 28 | 'default-compiler-flags', 'boost', |
Davide Pesavento | ecb2db1 | 2024-03-13 19:00:03 -0400 | [diff] [blame] | 29 | 'doxygen', 'sphinx']) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 30 | |
Davide Pesavento | d4689c8 | 2021-10-07 02:53:03 -0400 | [diff] [blame] | 31 | conf.env.WITH_EXAMPLES = conf.options.with_examples |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 32 | conf.env.WITH_TESTS = conf.options.with_tests |
Davide Pesavento | 969d0f3 | 2023-09-14 14:28:41 -0400 | [diff] [blame] | 33 | conf.env.WITH_TOOLS = conf.options.with_tools |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 34 | |
Davide Pesavento | 7e7bd89 | 2022-07-10 00:30:06 -0400 | [diff] [blame] | 35 | conf.find_program('dot', mandatory=False) |
| 36 | |
| 37 | # Prefer pkgconf if it's installed, because it gives more correct results |
| 38 | # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348 |
| 39 | # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg() |
| 40 | conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG') |
Davide Pesavento | ebeaeae | 2021-04-26 00:42:26 -0400 | [diff] [blame] | 41 | |
Davide Pesavento | 714dba0 | 2022-03-17 20:46:28 -0400 | [diff] [blame] | 42 | pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig') |
Davide Pesavento | d64a9d1 | 2023-01-01 16:30:03 -0500 | [diff] [blame] | 43 | conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'], |
Davide Pesavento | 714dba0 | 2022-03-17 20:46:28 -0400 | [diff] [blame] | 44 | uselib_store='NDN_CXX', pkg_config_path=pkg_config_path) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 45 | |
Davide Pesavento | f3872f2 | 2023-09-14 15:37:03 -0400 | [diff] [blame] | 46 | conf.check_boost() |
Davide Pesavento | f530be1 | 2023-09-22 15:50:31 -0400 | [diff] [blame] | 47 | if conf.env.BOOST_VERSION_NUMBER < 107100: |
| 48 | conf.fatal('The minimum supported version of Boost is 1.71.0.\n' |
| 49 | 'Please upgrade your distribution or manually install a newer version of Boost.\n' |
| 50 | 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost') |
Alexander Afanasyev | c993428 | 2018-07-17 18:41:36 -0400 | [diff] [blame] | 51 | |
Davide Pesavento | f3872f2 | 2023-09-14 15:37:03 -0400 | [diff] [blame] | 52 | if conf.env.WITH_TESTS: |
| 53 | conf.check_boost(lib='unit_test_framework', mt=True, uselib_store='BOOST_TESTS') |
| 54 | |
| 55 | if conf.env.WITH_TOOLS: |
| 56 | conf.check_boost(lib='program_options', mt=True, uselib_store='BOOST_TOOLS') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 57 | |
| 58 | conf.check_compiler_flags() |
| 59 | |
| 60 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 61 | conf.load('coverage') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 62 | conf.load('sanitizers') |
| 63 | |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 64 | # If there happens to be a static library, waf will put the corresponding -L flags |
| 65 | # before dynamic library flags. This can result in compilation failure when the |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 66 | # system has a different version of the ndn-nac library installed. |
| 67 | conf.env.prepend_value('STLIBPATH', ['.']) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 68 | |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 69 | conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS) |
| 70 | # The config header will contain all defines that were added using conf.define() |
| 71 | # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES |
| 72 | # will not appear in the config header, but will instead be passed directly to the |
| 73 | # compiler on the command line. |
Davide Pesavento | 3bf126f | 2023-09-14 20:35:02 -0400 | [diff] [blame] | 74 | conf.write_config_header('src/detail/config.hpp', define_prefix='NAC_') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 75 | |
| 76 | def build(bld): |
| 77 | version(bld) |
| 78 | |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 79 | bld(features='subst', |
| 80 | name='version.hpp', |
| 81 | source='src/version.hpp.in', |
| 82 | target='src/version.hpp', |
Davide Pesavento | 84348a2 | 2023-09-14 02:40:41 -0400 | [diff] [blame] | 83 | install_path='${INCLUDEDIR}/ndn-nac', |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 84 | VERSION_STRING=VERSION_BASE, |
| 85 | VERSION_BUILD=VERSION, |
| 86 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 87 | int(VERSION_SPLIT[1]) * 1000 + |
| 88 | int(VERSION_SPLIT[2]), |
| 89 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 90 | VERSION_MINOR=VERSION_SPLIT[1], |
| 91 | VERSION_PATCH=VERSION_SPLIT[2]) |
| 92 | |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 93 | bld.shlib( |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 94 | target='ndn-nac', |
| 95 | name='libndn-nac', |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 96 | vnum=VERSION_BASE, |
| 97 | cnum=VERSION_BASE, |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 98 | source=bld.path.ant_glob('src/**/*.cpp'), |
| 99 | use='BOOST NDN_CXX', |
Davide Pesavento | 3bf126f | 2023-09-14 20:35:02 -0400 | [diff] [blame] | 100 | includes='src', |
| 101 | export_includes='src') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 102 | |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 103 | if bld.env.WITH_TESTS: |
Alexander Afanasyev | 77f6ae1 | 2018-06-14 17:54:17 -0400 | [diff] [blame] | 104 | bld.recurse('tests') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 105 | |
Davide Pesavento | 969d0f3 | 2023-09-14 14:28:41 -0400 | [diff] [blame] | 106 | if bld.env.WITH_TOOLS: |
| 107 | bld.recurse('tools') |
| 108 | |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 109 | if bld.env.WITH_EXAMPLES: |
| 110 | bld.recurse('examples') |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 111 | |
Davide Pesavento | 84348a2 | 2023-09-14 02:40:41 -0400 | [diff] [blame] | 112 | # Install header files |
| 113 | bld.install_files('${INCLUDEDIR}/ndn-nac', bld.path.find_dir('src').ant_glob('*.hpp')) |
Davide Pesavento | 3bf126f | 2023-09-14 20:35:02 -0400 | [diff] [blame] | 114 | bld.install_files('${INCLUDEDIR}/ndn-nac/detail', 'src/detail/config.hpp') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 115 | |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 116 | bld(features='subst', |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 117 | source='libndn-nac.pc.in', |
| 118 | target='libndn-nac.pc', |
Davide Pesavento | 13527ec | 2019-11-09 13:50:36 -0500 | [diff] [blame] | 119 | install_path='${LIBDIR}/pkgconfig', |
| 120 | VERSION=VERSION) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 121 | |
| 122 | def docs(bld): |
| 123 | from waflib import Options |
| 124 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 125 | |
| 126 | def doxygen(bld): |
| 127 | version(bld) |
| 128 | |
| 129 | if not bld.env.DOXYGEN: |
| 130 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
| 131 | |
| 132 | bld(features='subst', |
| 133 | name='doxygen.conf', |
| 134 | source=['docs/doxygen.conf.in', |
| 135 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 136 | target=['docs/doxygen.conf', |
| 137 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 138 | VERSION=VERSION, |
Davide Pesavento | ebeaeae | 2021-04-26 00:42:26 -0400 | [diff] [blame] | 139 | HAVE_DOT='YES' if bld.env.DOT else 'NO', |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 140 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 141 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 142 | else '../docs/named_data_theme/named_data_footer.html', |
| 143 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 144 | |
| 145 | bld(features='doxygen', |
| 146 | doxyfile='docs/doxygen.conf', |
| 147 | use='doxygen.conf') |
| 148 | |
| 149 | def sphinx(bld): |
| 150 | version(bld) |
| 151 | |
| 152 | if not bld.env.SPHINX_BUILD: |
| 153 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 154 | |
| 155 | bld(features='sphinx', |
| 156 | config='docs/conf.py', |
| 157 | outdir='docs', |
| 158 | source=bld.path.ant_glob('docs/**/*.rst'), |
Davide Pesavento | ec61b74 | 2020-04-18 01:00:12 -0400 | [diff] [blame] | 159 | version=VERSION_BASE, |
| 160 | release=VERSION) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 161 | |
| 162 | def version(ctx): |
| 163 | # don't execute more than once |
| 164 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 165 | return |
| 166 | |
| 167 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 168 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
| 169 | |
| 170 | # first, try to get a version string from git |
Davide Pesavento | 44b0f8c | 2024-04-23 00:16:11 -0400 | [diff] [blame] | 171 | version_from_git = '' |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 172 | try: |
Davide Pesavento | 44b0f8c | 2024-04-23 00:16:11 -0400 | [diff] [blame] | 173 | cmd = ['git', 'describe', '--abbrev=8', '--always', '--match', f'{GIT_TAG_PREFIX}*'] |
| 174 | version_from_git = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip() |
| 175 | if version_from_git: |
| 176 | if GIT_TAG_PREFIX and version_from_git.startswith(GIT_TAG_PREFIX): |
| 177 | Context.g_module.VERSION = version_from_git[len(GIT_TAG_PREFIX):] |
| 178 | elif not GIT_TAG_PREFIX and ('.' in version_from_git or '-' in version_from_git): |
| 179 | Context.g_module.VERSION = version_from_git |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 180 | else: |
Davide Pesavento | 44b0f8c | 2024-04-23 00:16:11 -0400 | [diff] [blame] | 181 | # no tags matched (or we are in a shallow clone) |
| 182 | Context.g_module.VERSION = f'{VERSION_BASE}+git.{version_from_git}' |
Davide Pesavento | 84348a2 | 2023-09-14 02:40:41 -0400 | [diff] [blame] | 183 | except (OSError, subprocess.SubprocessError): |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 184 | pass |
| 185 | |
Davide Pesavento | 44b0f8c | 2024-04-23 00:16:11 -0400 | [diff] [blame] | 186 | # fallback to the VERSION.info file, if it exists and is not empty |
| 187 | version_from_file = '' |
| 188 | version_file = ctx.path.find_node('VERSION.info') |
| 189 | if version_file is not None: |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 190 | try: |
Davide Pesavento | 44b0f8c | 2024-04-23 00:16:11 -0400 | [diff] [blame] | 191 | version_from_file = version_file.read().strip() |
| 192 | except OSError as e: |
| 193 | Logs.warn(f'{e.filename} exists but is not readable ({e.strerror})') |
| 194 | if version_from_file and not version_from_git: |
| 195 | Context.g_module.VERSION = version_from_file |
| 196 | return |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 197 | |
Davide Pesavento | 44b0f8c | 2024-04-23 00:16:11 -0400 | [diff] [blame] | 198 | # update VERSION.info if necessary |
| 199 | if version_from_file == Context.g_module.VERSION: |
| 200 | # already up-to-date |
| 201 | return |
| 202 | if version_file is None: |
| 203 | version_file = ctx.path.make_node('VERSION.info') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 204 | try: |
Davide Pesavento | 44b0f8c | 2024-04-23 00:16:11 -0400 | [diff] [blame] | 205 | version_file.write(Context.g_module.VERSION) |
| 206 | except OSError as e: |
| 207 | Logs.warn(f'{e.filename} is not writable ({e.strerror})') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 208 | |
| 209 | def dist(ctx): |
Davide Pesavento | 7228e53 | 2023-02-18 02:26:45 -0500 | [diff] [blame] | 210 | ctx.algo = 'tar.xz' |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 211 | version(ctx) |
| 212 | |
| 213 | def distcheck(ctx): |
Davide Pesavento | 7228e53 | 2023-02-18 02:26:45 -0500 | [diff] [blame] | 214 | ctx.algo = 'tar.xz' |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 215 | version(ctx) |