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 | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 9 | GIT_TAG_PREFIX = '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', |
| 15 | 'doxygen', 'sphinx_build'], |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 16 | tooldir=['.waf-tools']) |
| 17 | |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 18 | optgrp = opt.add_option_group('NDN-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') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 23 | |
| 24 | def configure(conf): |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 25 | conf.load(['compiler_cxx', 'gnu_dirs', |
| 26 | 'default-compiler-flags', 'boost', |
| 27 | 'doxygen', 'sphinx_build']) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 28 | |
Davide Pesavento | d4689c8 | 2021-10-07 02:53:03 -0400 | [diff] [blame] | 29 | conf.env.WITH_EXAMPLES = conf.options.with_examples |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 30 | conf.env.WITH_TESTS = conf.options.with_tests |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 31 | |
Davide Pesavento | 7e7bd89 | 2022-07-10 00:30:06 -0400 | [diff] [blame] | 32 | conf.find_program('dot', mandatory=False) |
| 33 | |
| 34 | # Prefer pkgconf if it's installed, because it gives more correct results |
| 35 | # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348 |
| 36 | # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg() |
| 37 | conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG') |
Davide Pesavento | ebeaeae | 2021-04-26 00:42:26 -0400 | [diff] [blame] | 38 | |
Davide Pesavento | 714dba0 | 2022-03-17 20:46:28 -0400 | [diff] [blame] | 39 | 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] | 40 | 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] | 41 | uselib_store='NDN_CXX', pkg_config_path=pkg_config_path) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 42 | |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 43 | boost_libs = ['system', 'program_options'] |
| 44 | if conf.env.WITH_TESTS: |
| 45 | boost_libs.append('unit_test_framework') |
Alexander Afanasyev | c993428 | 2018-07-17 18:41:36 -0400 | [diff] [blame] | 46 | |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 47 | conf.check_boost(lib=boost_libs, mt=True) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 48 | |
| 49 | conf.check_compiler_flags() |
| 50 | |
| 51 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 52 | conf.load('coverage') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 53 | conf.load('sanitizers') |
| 54 | |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [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 |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 57 | # system has a different version of the ndn-nac library installed. |
| 58 | conf.env.prepend_value('STLIBPATH', ['.']) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 59 | |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 60 | conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS) |
| 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. |
| 65 | conf.write_config_header('config.hpp', define_prefix='NAC_') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 66 | |
| 67 | def build(bld): |
| 68 | version(bld) |
| 69 | |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 70 | bld(features='subst', |
| 71 | name='version.hpp', |
| 72 | source='src/version.hpp.in', |
| 73 | target='src/version.hpp', |
Davide Pesavento | 84348a2 | 2023-09-14 02:40:41 -0400 | [diff] [blame^] | 74 | install_path='${INCLUDEDIR}/ndn-nac', |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 75 | VERSION_STRING=VERSION_BASE, |
| 76 | VERSION_BUILD=VERSION, |
| 77 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 78 | int(VERSION_SPLIT[1]) * 1000 + |
| 79 | int(VERSION_SPLIT[2]), |
| 80 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 81 | VERSION_MINOR=VERSION_SPLIT[1], |
| 82 | VERSION_PATCH=VERSION_SPLIT[2]) |
| 83 | |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 84 | bld.shlib( |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 85 | target='ndn-nac', |
| 86 | name='libndn-nac', |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 87 | vnum=VERSION_BASE, |
| 88 | cnum=VERSION_BASE, |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 89 | source=bld.path.ant_glob('src/**/*.cpp'), |
| 90 | use='BOOST NDN_CXX', |
| 91 | includes=['src', '.'], |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 92 | export_includes=['src', '.']) |
| 93 | |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 94 | bld.recurse('tools') |
| 95 | |
| 96 | if bld.env.WITH_TESTS: |
Alexander Afanasyev | 77f6ae1 | 2018-06-14 17:54:17 -0400 | [diff] [blame] | 97 | bld.recurse('tests') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 98 | |
Davide Pesavento | 27680ae | 2019-04-06 19:40:01 -0400 | [diff] [blame] | 99 | if bld.env.WITH_EXAMPLES: |
| 100 | bld.recurse('examples') |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 101 | |
Davide Pesavento | 84348a2 | 2023-09-14 02:40:41 -0400 | [diff] [blame^] | 102 | # Install header files |
| 103 | bld.install_files('${INCLUDEDIR}/ndn-nac', bld.path.find_dir('src').ant_glob('*.hpp')) |
| 104 | bld.install_files('${INCLUDEDIR}/ndn-nac', bld.path.find_resource('config.hpp')) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 105 | |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 106 | bld(features='subst', |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 107 | source='libndn-nac.pc.in', |
| 108 | target='libndn-nac.pc', |
Davide Pesavento | 13527ec | 2019-11-09 13:50:36 -0500 | [diff] [blame] | 109 | install_path='${LIBDIR}/pkgconfig', |
| 110 | VERSION=VERSION) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 111 | |
| 112 | def docs(bld): |
| 113 | from waflib import Options |
| 114 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 115 | |
| 116 | def doxygen(bld): |
| 117 | version(bld) |
| 118 | |
| 119 | if not bld.env.DOXYGEN: |
| 120 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
| 121 | |
| 122 | bld(features='subst', |
| 123 | name='doxygen.conf', |
| 124 | source=['docs/doxygen.conf.in', |
| 125 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 126 | target=['docs/doxygen.conf', |
| 127 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 128 | VERSION=VERSION, |
Davide Pesavento | ebeaeae | 2021-04-26 00:42:26 -0400 | [diff] [blame] | 129 | HAVE_DOT='YES' if bld.env.DOT else 'NO', |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 130 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 131 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 132 | else '../docs/named_data_theme/named_data_footer.html', |
| 133 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 134 | |
| 135 | bld(features='doxygen', |
| 136 | doxyfile='docs/doxygen.conf', |
| 137 | use='doxygen.conf') |
| 138 | |
| 139 | def sphinx(bld): |
| 140 | version(bld) |
| 141 | |
| 142 | if not bld.env.SPHINX_BUILD: |
| 143 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 144 | |
| 145 | bld(features='sphinx', |
| 146 | config='docs/conf.py', |
| 147 | outdir='docs', |
| 148 | source=bld.path.ant_glob('docs/**/*.rst'), |
Davide Pesavento | ec61b74 | 2020-04-18 01:00:12 -0400 | [diff] [blame] | 149 | version=VERSION_BASE, |
| 150 | release=VERSION) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 151 | |
| 152 | def version(ctx): |
| 153 | # don't execute more than once |
| 154 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 155 | return |
| 156 | |
| 157 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 158 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
| 159 | |
| 160 | # first, try to get a version string from git |
| 161 | gotVersionFromGit = False |
| 162 | try: |
Davide Pesavento | 84348a2 | 2023-09-14 02:40:41 -0400 | [diff] [blame^] | 163 | cmd = ['git', 'describe', '--always', '--match', f'{GIT_TAG_PREFIX}*'] |
| 164 | out = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip() |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 165 | if out: |
| 166 | gotVersionFromGit = True |
| 167 | if out.startswith(GIT_TAG_PREFIX): |
| 168 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
| 169 | else: |
| 170 | # no tags matched |
Davide Pesavento | 84348a2 | 2023-09-14 02:40:41 -0400 | [diff] [blame^] | 171 | Context.g_module.VERSION = f'{VERSION_BASE}-commit-{out}' |
| 172 | except (OSError, subprocess.SubprocessError): |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 173 | pass |
| 174 | |
Alexander Afanasyev | 1b9be6c | 2020-06-01 19:20:41 -0400 | [diff] [blame] | 175 | versionFile = ctx.path.find_node('VERSION.info') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 176 | if not gotVersionFromGit and versionFile is not None: |
| 177 | try: |
| 178 | Context.g_module.VERSION = versionFile.read() |
| 179 | return |
| 180 | except EnvironmentError: |
| 181 | pass |
| 182 | |
| 183 | # version was obtained from git, update VERSION file if necessary |
| 184 | if versionFile is not None: |
| 185 | try: |
| 186 | if versionFile.read() == Context.g_module.VERSION: |
| 187 | # already up-to-date |
| 188 | return |
| 189 | except EnvironmentError as e: |
Davide Pesavento | 84348a2 | 2023-09-14 02:40:41 -0400 | [diff] [blame^] | 190 | Logs.warn(f'{versionFile} exists but is not readable ({e.strerror})') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 191 | else: |
Alexander Afanasyev | 1b9be6c | 2020-06-01 19:20:41 -0400 | [diff] [blame] | 192 | versionFile = ctx.path.make_node('VERSION.info') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 193 | |
| 194 | try: |
| 195 | versionFile.write(Context.g_module.VERSION) |
| 196 | except EnvironmentError as e: |
Davide Pesavento | 84348a2 | 2023-09-14 02:40:41 -0400 | [diff] [blame^] | 197 | Logs.warn(f'{versionFile} is not writable ({e.strerror})') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 198 | |
| 199 | def dist(ctx): |
Davide Pesavento | 7228e53 | 2023-02-18 02:26:45 -0500 | [diff] [blame] | 200 | ctx.algo = 'tar.xz' |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 201 | version(ctx) |
| 202 | |
| 203 | def distcheck(ctx): |
Davide Pesavento | 7228e53 | 2023-02-18 02:26:45 -0500 | [diff] [blame] | 204 | ctx.algo = 'tar.xz' |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 205 | version(ctx) |