blob: 833277c0cdb1d44d2fb53659978b2691b888a393 [file] [log] [blame]
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -04001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
Davide Pesavento84348a22023-09-14 02:40:41 -04003import os
4import subprocess
5from waflib import Context, Logs
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -04006
7VERSION = '0.1.0'
8APPNAME = 'ndn-nac'
Davide Pesavento8f9d0622018-11-27 01:23:37 -05009GIT_TAG_PREFIX = 'nac-'
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040010
11def options(opt):
Davide Pesavento8f9d0622018-11-27 01:23:37 -050012 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesaventod4689c82021-10-07 02:53:03 -040013 opt.load(['default-compiler-flags',
14 'coverage', 'sanitizers', 'boost',
15 'doxygen', 'sphinx_build'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040016 tooldir=['.waf-tools'])
17
Davide Pesavento969d0f32023-09-14 14:28:41 -040018 optgrp = opt.add_option_group('NAC Options')
Davide Pesaventod4689c82021-10-07 02:53:03 -040019 optgrp.add_option('--with-examples', action='store_true', default=False,
20 help='Build examples')
Davide Pesavento27680ae2019-04-06 19:40:01 -040021 optgrp.add_option('--with-tests', action='store_true', default=False,
22 help='Build unit tests')
Davide Pesavento969d0f32023-09-14 14:28:41 -040023 optgrp.add_option('--without-tools', action='store_false', default=True, dest='with_tools',
24 help='Do not build tools')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040025
26def configure(conf):
Davide Pesavento8f9d0622018-11-27 01:23:37 -050027 conf.load(['compiler_cxx', 'gnu_dirs',
28 'default-compiler-flags', 'boost',
29 'doxygen', 'sphinx_build'])
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040030
Davide Pesaventod4689c82021-10-07 02:53:03 -040031 conf.env.WITH_EXAMPLES = conf.options.with_examples
Davide Pesavento27680ae2019-04-06 19:40:01 -040032 conf.env.WITH_TESTS = conf.options.with_tests
Davide Pesavento969d0f32023-09-14 14:28:41 -040033 conf.env.WITH_TOOLS = conf.options.with_tools
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040034
Davide Pesavento7e7bd892022-07-10 00:30:06 -040035 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 Pesaventoebeaeae2021-04-26 00:42:26 -040041
Davide Pesavento714dba02022-03-17 20:46:28 -040042 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
Davide Pesaventod64a9d12023-01-01 16:30:03 -050043 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'],
Davide Pesavento714dba02022-03-17 20:46:28 -040044 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040045
Davide Pesaventof3872f22023-09-14 15:37:03 -040046 conf.check_boost()
Alexander Afanasyevc9934282018-07-17 18:41:36 -040047
Davide Pesaventof3872f22023-09-14 15:37:03 -040048 if conf.env.WITH_TESTS:
49 conf.check_boost(lib='unit_test_framework', mt=True, uselib_store='BOOST_TESTS')
50
51 if conf.env.WITH_TOOLS:
52 conf.check_boost(lib='program_options', mt=True, uselib_store='BOOST_TOOLS')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040053
54 conf.check_compiler_flags()
55
56 # Loading "late" to prevent tests from being compiled with profiling flags
57 conf.load('coverage')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040058 conf.load('sanitizers')
59
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040060 # If there happens to be a static library, waf will put the corresponding -L flags
61 # before dynamic library flags. This can result in compilation failure when the
Davide Pesavento27680ae2019-04-06 19:40:01 -040062 # system has a different version of the ndn-nac library installed.
63 conf.env.prepend_value('STLIBPATH', ['.'])
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040064
Davide Pesavento27680ae2019-04-06 19:40:01 -040065 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
66 # The config header will contain all defines that were added using conf.define()
67 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
68 # will not appear in the config header, but will instead be passed directly to the
69 # compiler on the command line.
70 conf.write_config_header('config.hpp', define_prefix='NAC_')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040071
72def build(bld):
73 version(bld)
74
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040075 bld(features='subst',
76 name='version.hpp',
77 source='src/version.hpp.in',
78 target='src/version.hpp',
Davide Pesavento84348a22023-09-14 02:40:41 -040079 install_path='${INCLUDEDIR}/ndn-nac',
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040080 VERSION_STRING=VERSION_BASE,
81 VERSION_BUILD=VERSION,
82 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
83 int(VERSION_SPLIT[1]) * 1000 +
84 int(VERSION_SPLIT[2]),
85 VERSION_MAJOR=VERSION_SPLIT[0],
86 VERSION_MINOR=VERSION_SPLIT[1],
87 VERSION_PATCH=VERSION_SPLIT[2])
88
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040089 bld.shlib(
Davide Pesavento8f9d0622018-11-27 01:23:37 -050090 target='ndn-nac',
91 name='libndn-nac',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040092 vnum=VERSION_BASE,
93 cnum=VERSION_BASE,
Davide Pesavento8f9d0622018-11-27 01:23:37 -050094 source=bld.path.ant_glob('src/**/*.cpp'),
95 use='BOOST NDN_CXX',
96 includes=['src', '.'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040097 export_includes=['src', '.'])
98
Davide Pesavento27680ae2019-04-06 19:40:01 -040099 if bld.env.WITH_TESTS:
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -0400100 bld.recurse('tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400101
Davide Pesavento969d0f32023-09-14 14:28:41 -0400102 if bld.env.WITH_TOOLS:
103 bld.recurse('tools')
104
Davide Pesavento27680ae2019-04-06 19:40:01 -0400105 if bld.env.WITH_EXAMPLES:
106 bld.recurse('examples')
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -0400107
Davide Pesavento84348a22023-09-14 02:40:41 -0400108 # Install header files
109 bld.install_files('${INCLUDEDIR}/ndn-nac', bld.path.find_dir('src').ant_glob('*.hpp'))
110 bld.install_files('${INCLUDEDIR}/ndn-nac', bld.path.find_resource('config.hpp'))
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400111
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500112 bld(features='subst',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400113 source='libndn-nac.pc.in',
114 target='libndn-nac.pc',
Davide Pesavento13527ec2019-11-09 13:50:36 -0500115 install_path='${LIBDIR}/pkgconfig',
116 VERSION=VERSION)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400117
118def docs(bld):
119 from waflib import Options
120 Options.commands = ['doxygen', 'sphinx'] + Options.commands
121
122def doxygen(bld):
123 version(bld)
124
125 if not bld.env.DOXYGEN:
126 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
127
128 bld(features='subst',
129 name='doxygen.conf',
130 source=['docs/doxygen.conf.in',
131 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
132 target=['docs/doxygen.conf',
133 'docs/named_data_theme/named_data_footer-with-analytics.html'],
134 VERSION=VERSION,
Davide Pesaventoebeaeae2021-04-26 00:42:26 -0400135 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400136 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
137 if os.getenv('GOOGLE_ANALYTICS', None) \
138 else '../docs/named_data_theme/named_data_footer.html',
139 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
140
141 bld(features='doxygen',
142 doxyfile='docs/doxygen.conf',
143 use='doxygen.conf')
144
145def sphinx(bld):
146 version(bld)
147
148 if not bld.env.SPHINX_BUILD:
149 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
150
151 bld(features='sphinx',
152 config='docs/conf.py',
153 outdir='docs',
154 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventoec61b742020-04-18 01:00:12 -0400155 version=VERSION_BASE,
156 release=VERSION)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400157
158def version(ctx):
159 # don't execute more than once
160 if getattr(Context.g_module, 'VERSION_BASE', None):
161 return
162
163 Context.g_module.VERSION_BASE = Context.g_module.VERSION
164 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
165
166 # first, try to get a version string from git
167 gotVersionFromGit = False
168 try:
Davide Pesavento84348a22023-09-14 02:40:41 -0400169 cmd = ['git', 'describe', '--always', '--match', f'{GIT_TAG_PREFIX}*']
170 out = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400171 if out:
172 gotVersionFromGit = True
173 if out.startswith(GIT_TAG_PREFIX):
174 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
175 else:
176 # no tags matched
Davide Pesavento84348a22023-09-14 02:40:41 -0400177 Context.g_module.VERSION = f'{VERSION_BASE}-commit-{out}'
178 except (OSError, subprocess.SubprocessError):
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400179 pass
180
Alexander Afanasyev1b9be6c2020-06-01 19:20:41 -0400181 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400182 if not gotVersionFromGit and versionFile is not None:
183 try:
184 Context.g_module.VERSION = versionFile.read()
185 return
186 except EnvironmentError:
187 pass
188
189 # version was obtained from git, update VERSION file if necessary
190 if versionFile is not None:
191 try:
192 if versionFile.read() == Context.g_module.VERSION:
193 # already up-to-date
194 return
195 except EnvironmentError as e:
Davide Pesavento84348a22023-09-14 02:40:41 -0400196 Logs.warn(f'{versionFile} exists but is not readable ({e.strerror})')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400197 else:
Alexander Afanasyev1b9be6c2020-06-01 19:20:41 -0400198 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400199
200 try:
201 versionFile.write(Context.g_module.VERSION)
202 except EnvironmentError as e:
Davide Pesavento84348a22023-09-14 02:40:41 -0400203 Logs.warn(f'{versionFile} is not writable ({e.strerror})')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400204
205def dist(ctx):
Davide Pesavento7228e532023-02-18 02:26:45 -0500206 ctx.algo = 'tar.xz'
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400207 version(ctx)
208
209def distcheck(ctx):
Davide Pesavento7228e532023-02-18 02:26:45 -0500210 ctx.algo = 'tar.xz'
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400211 version(ctx)