blob: b83b00877ee0e7107ffbd74ebefccf742e9e3512 [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
3from waflib import Context, Logs, Utils
4import os, subprocess
5
6VERSION = '0.1.0'
7APPNAME = 'ndn-nac'
Davide Pesavento8f9d0622018-11-27 01:23:37 -05008GIT_TAG_PREFIX = 'nac-'
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -04009
10def options(opt):
Davide Pesavento8f9d0622018-11-27 01:23:37 -050011 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesaventod4689c82021-10-07 02:53:03 -040012 opt.load(['default-compiler-flags',
13 'coverage', 'sanitizers', 'boost',
14 'doxygen', 'sphinx_build'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040015 tooldir=['.waf-tools'])
16
Davide Pesavento27680ae2019-04-06 19:40:01 -040017 optgrp = opt.add_option_group('NDN-NAC Options')
Davide Pesaventod4689c82021-10-07 02:53:03 -040018 optgrp.add_option('--with-examples', action='store_true', default=False,
19 help='Build examples')
Davide Pesavento27680ae2019-04-06 19:40:01 -040020 optgrp.add_option('--with-tests', action='store_true', default=False,
21 help='Build unit tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040022
23def configure(conf):
Davide Pesavento8f9d0622018-11-27 01:23:37 -050024 conf.load(['compiler_cxx', 'gnu_dirs',
25 'default-compiler-flags', 'boost',
26 'doxygen', 'sphinx_build'])
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040027
Davide Pesaventod4689c82021-10-07 02:53:03 -040028 conf.env.WITH_EXAMPLES = conf.options.with_examples
Davide Pesavento27680ae2019-04-06 19:40:01 -040029 conf.env.WITH_TESTS = conf.options.with_tests
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040030
Davide Pesavento7e7bd892022-07-10 00:30:06 -040031 conf.find_program('dot', mandatory=False)
32
33 # Prefer pkgconf if it's installed, because it gives more correct results
34 # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348
35 # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg()
36 conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG')
Davide Pesaventoebeaeae2021-04-26 00:42:26 -040037
Davide Pesavento714dba02022-03-17 20:46:28 -040038 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
39 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.0', '--cflags', '--libs'],
40 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040041
Davide Pesavento27680ae2019-04-06 19:40:01 -040042 boost_libs = ['system', 'program_options']
43 if conf.env.WITH_TESTS:
44 boost_libs.append('unit_test_framework')
Alexander Afanasyevc9934282018-07-17 18:41:36 -040045
Davide Pesavento27680ae2019-04-06 19:40:01 -040046 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040047
48 conf.check_compiler_flags()
49
50 # Loading "late" to prevent tests from being compiled with profiling flags
51 conf.load('coverage')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040052 conf.load('sanitizers')
53
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040054 # If there happens to be a static library, waf will put the corresponding -L flags
55 # before dynamic library flags. This can result in compilation failure when the
Davide Pesavento27680ae2019-04-06 19:40:01 -040056 # system has a different version of the ndn-nac library installed.
57 conf.env.prepend_value('STLIBPATH', ['.'])
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040058
Davide Pesavento27680ae2019-04-06 19:40:01 -040059 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
60 # The config header will contain all defines that were added using conf.define()
61 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
62 # will not appear in the config header, but will instead be passed directly to the
63 # compiler on the command line.
64 conf.write_config_header('config.hpp', define_prefix='NAC_')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040065
66def build(bld):
67 version(bld)
68
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040069 bld(features='subst',
70 name='version.hpp',
71 source='src/version.hpp.in',
72 target='src/version.hpp',
73 install_path=None,
74 VERSION_STRING=VERSION_BASE,
75 VERSION_BUILD=VERSION,
76 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
77 int(VERSION_SPLIT[1]) * 1000 +
78 int(VERSION_SPLIT[2]),
79 VERSION_MAJOR=VERSION_SPLIT[0],
80 VERSION_MINOR=VERSION_SPLIT[1],
81 VERSION_PATCH=VERSION_SPLIT[2])
82
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040083 bld.shlib(
Davide Pesavento8f9d0622018-11-27 01:23:37 -050084 target='ndn-nac',
85 name='libndn-nac',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040086 vnum=VERSION_BASE,
87 cnum=VERSION_BASE,
Davide Pesavento8f9d0622018-11-27 01:23:37 -050088 source=bld.path.ant_glob('src/**/*.cpp'),
89 use='BOOST NDN_CXX',
90 includes=['src', '.'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040091 export_includes=['src', '.'])
92
Davide Pesavento27680ae2019-04-06 19:40:01 -040093 bld.recurse('tools')
94
95 if bld.env.WITH_TESTS:
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040096 bld.recurse('tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040097
Davide Pesavento27680ae2019-04-06 19:40:01 -040098 if bld.env.WITH_EXAMPLES:
99 bld.recurse('examples')
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -0400100
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400101 bld.install_files(
Davide Pesavento13527ec2019-11-09 13:50:36 -0500102 dest = '%s/ndn-nac' % bld.env.INCLUDEDIR,
103 files = bld.path.ant_glob(['src/*.hpp', 'common.hpp']),
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500104 cwd = bld.path.find_dir('src'),
Davide Pesavento13527ec2019-11-09 13:50:36 -0500105 relative_trick = False)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400106
107 bld.install_files(
Davide Pesavento13527ec2019-11-09 13:50:36 -0500108 dest = '%s/ndn-nac' % bld.env.INCLUDEDIR,
109 files = bld.path.get_bld().ant_glob(['src/*.hpp', 'common.hpp', 'config.hpp']),
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500110 cwd = bld.path.get_bld().find_dir('src'),
111 relative_trick = False)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400112
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500113 bld(features='subst',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400114 source='libndn-nac.pc.in',
115 target='libndn-nac.pc',
Davide Pesavento13527ec2019-11-09 13:50:36 -0500116 install_path='${LIBDIR}/pkgconfig',
117 VERSION=VERSION)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400118
119def docs(bld):
120 from waflib import Options
121 Options.commands = ['doxygen', 'sphinx'] + Options.commands
122
123def doxygen(bld):
124 version(bld)
125
126 if not bld.env.DOXYGEN:
127 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
128
129 bld(features='subst',
130 name='doxygen.conf',
131 source=['docs/doxygen.conf.in',
132 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
133 target=['docs/doxygen.conf',
134 'docs/named_data_theme/named_data_footer-with-analytics.html'],
135 VERSION=VERSION,
Davide Pesaventoebeaeae2021-04-26 00:42:26 -0400136 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400137 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
138 if os.getenv('GOOGLE_ANALYTICS', None) \
139 else '../docs/named_data_theme/named_data_footer.html',
140 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
141
142 bld(features='doxygen',
143 doxyfile='docs/doxygen.conf',
144 use='doxygen.conf')
145
146def sphinx(bld):
147 version(bld)
148
149 if not bld.env.SPHINX_BUILD:
150 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
151
152 bld(features='sphinx',
153 config='docs/conf.py',
154 outdir='docs',
155 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventoec61b742020-04-18 01:00:12 -0400156 version=VERSION_BASE,
157 release=VERSION)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400158
159def version(ctx):
160 # don't execute more than once
161 if getattr(Context.g_module, 'VERSION_BASE', None):
162 return
163
164 Context.g_module.VERSION_BASE = Context.g_module.VERSION
165 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
166
167 # first, try to get a version string from git
168 gotVersionFromGit = False
169 try:
170 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
171 out = subprocess.check_output(cmd, universal_newlines=True).strip()
172 if out:
173 gotVersionFromGit = True
174 if out.startswith(GIT_TAG_PREFIX):
175 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
176 else:
177 # no tags matched
178 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
179 except (OSError, subprocess.CalledProcessError):
180 pass
181
Alexander Afanasyev1b9be6c2020-06-01 19:20:41 -0400182 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400183 if not gotVersionFromGit and versionFile is not None:
184 try:
185 Context.g_module.VERSION = versionFile.read()
186 return
187 except EnvironmentError:
188 pass
189
190 # version was obtained from git, update VERSION file if necessary
191 if versionFile is not None:
192 try:
193 if versionFile.read() == Context.g_module.VERSION:
194 # already up-to-date
195 return
196 except EnvironmentError as e:
197 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
198 else:
Alexander Afanasyev1b9be6c2020-06-01 19:20:41 -0400199 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400200
201 try:
202 versionFile.write(Context.g_module.VERSION)
203 except EnvironmentError as e:
204 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
205
206def dist(ctx):
207 version(ctx)
208
209def distcheck(ctx):
210 version(ctx)