blob: b3e2e4d202cf677b7afcde38243e3955a7c730c5 [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 Pesaventoebeaeae2021-04-26 00:42:26 -040031 conf.find_program('dot', var='DOT', mandatory=False)
32
Davide Pesavento714dba02022-03-17 20:46:28 -040033 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
34 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.0', '--cflags', '--libs'],
35 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040036
Davide Pesavento27680ae2019-04-06 19:40:01 -040037 boost_libs = ['system', 'program_options']
38 if conf.env.WITH_TESTS:
39 boost_libs.append('unit_test_framework')
Alexander Afanasyevc9934282018-07-17 18:41:36 -040040
Davide Pesavento27680ae2019-04-06 19:40:01 -040041 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040042
43 conf.check_compiler_flags()
44
45 # Loading "late" to prevent tests from being compiled with profiling flags
46 conf.load('coverage')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040047 conf.load('sanitizers')
48
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040049 # If there happens to be a static library, waf will put the corresponding -L flags
50 # before dynamic library flags. This can result in compilation failure when the
Davide Pesavento27680ae2019-04-06 19:40:01 -040051 # system has a different version of the ndn-nac library installed.
52 conf.env.prepend_value('STLIBPATH', ['.'])
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040053
Davide Pesavento27680ae2019-04-06 19:40:01 -040054 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
55 # The config header will contain all defines that were added using conf.define()
56 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
57 # will not appear in the config header, but will instead be passed directly to the
58 # compiler on the command line.
59 conf.write_config_header('config.hpp', define_prefix='NAC_')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040060
61def build(bld):
62 version(bld)
63
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040064 bld(features='subst',
65 name='version.hpp',
66 source='src/version.hpp.in',
67 target='src/version.hpp',
68 install_path=None,
69 VERSION_STRING=VERSION_BASE,
70 VERSION_BUILD=VERSION,
71 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
72 int(VERSION_SPLIT[1]) * 1000 +
73 int(VERSION_SPLIT[2]),
74 VERSION_MAJOR=VERSION_SPLIT[0],
75 VERSION_MINOR=VERSION_SPLIT[1],
76 VERSION_PATCH=VERSION_SPLIT[2])
77
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040078 bld.shlib(
Davide Pesavento8f9d0622018-11-27 01:23:37 -050079 target='ndn-nac',
80 name='libndn-nac',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040081 vnum=VERSION_BASE,
82 cnum=VERSION_BASE,
Davide Pesavento8f9d0622018-11-27 01:23:37 -050083 source=bld.path.ant_glob('src/**/*.cpp'),
84 use='BOOST NDN_CXX',
85 includes=['src', '.'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040086 export_includes=['src', '.'])
87
Davide Pesavento27680ae2019-04-06 19:40:01 -040088 bld.recurse('tools')
89
90 if bld.env.WITH_TESTS:
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040091 bld.recurse('tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040092
Davide Pesavento27680ae2019-04-06 19:40:01 -040093 if bld.env.WITH_EXAMPLES:
94 bld.recurse('examples')
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040095
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040096 bld.install_files(
Davide Pesavento13527ec2019-11-09 13:50:36 -050097 dest = '%s/ndn-nac' % bld.env.INCLUDEDIR,
98 files = bld.path.ant_glob(['src/*.hpp', 'common.hpp']),
Davide Pesavento8f9d0622018-11-27 01:23:37 -050099 cwd = bld.path.find_dir('src'),
Davide Pesavento13527ec2019-11-09 13:50:36 -0500100 relative_trick = False)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400101
102 bld.install_files(
Davide Pesavento13527ec2019-11-09 13:50:36 -0500103 dest = '%s/ndn-nac' % bld.env.INCLUDEDIR,
104 files = bld.path.get_bld().ant_glob(['src/*.hpp', 'common.hpp', 'config.hpp']),
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500105 cwd = bld.path.get_bld().find_dir('src'),
106 relative_trick = False)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400107
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500108 bld(features='subst',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400109 source='libndn-nac.pc.in',
110 target='libndn-nac.pc',
Davide Pesavento13527ec2019-11-09 13:50:36 -0500111 install_path='${LIBDIR}/pkgconfig',
112 VERSION=VERSION)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400113
114def docs(bld):
115 from waflib import Options
116 Options.commands = ['doxygen', 'sphinx'] + Options.commands
117
118def doxygen(bld):
119 version(bld)
120
121 if not bld.env.DOXYGEN:
122 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
123
124 bld(features='subst',
125 name='doxygen.conf',
126 source=['docs/doxygen.conf.in',
127 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
128 target=['docs/doxygen.conf',
129 'docs/named_data_theme/named_data_footer-with-analytics.html'],
130 VERSION=VERSION,
Davide Pesaventoebeaeae2021-04-26 00:42:26 -0400131 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400132 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
133 if os.getenv('GOOGLE_ANALYTICS', None) \
134 else '../docs/named_data_theme/named_data_footer.html',
135 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
136
137 bld(features='doxygen',
138 doxyfile='docs/doxygen.conf',
139 use='doxygen.conf')
140
141def sphinx(bld):
142 version(bld)
143
144 if not bld.env.SPHINX_BUILD:
145 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
146
147 bld(features='sphinx',
148 config='docs/conf.py',
149 outdir='docs',
150 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventoec61b742020-04-18 01:00:12 -0400151 version=VERSION_BASE,
152 release=VERSION)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400153
154def version(ctx):
155 # don't execute more than once
156 if getattr(Context.g_module, 'VERSION_BASE', None):
157 return
158
159 Context.g_module.VERSION_BASE = Context.g_module.VERSION
160 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
161
162 # first, try to get a version string from git
163 gotVersionFromGit = False
164 try:
165 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
166 out = subprocess.check_output(cmd, universal_newlines=True).strip()
167 if out:
168 gotVersionFromGit = True
169 if out.startswith(GIT_TAG_PREFIX):
170 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
171 else:
172 # no tags matched
173 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
174 except (OSError, subprocess.CalledProcessError):
175 pass
176
Alexander Afanasyev1b9be6c2020-06-01 19:20:41 -0400177 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400178 if not gotVersionFromGit and versionFile is not None:
179 try:
180 Context.g_module.VERSION = versionFile.read()
181 return
182 except EnvironmentError:
183 pass
184
185 # version was obtained from git, update VERSION file if necessary
186 if versionFile is not None:
187 try:
188 if versionFile.read() == Context.g_module.VERSION:
189 # already up-to-date
190 return
191 except EnvironmentError as e:
192 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
193 else:
Alexander Afanasyev1b9be6c2020-06-01 19:20:41 -0400194 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400195
196 try:
197 versionFile.write(Context.g_module.VERSION)
198 except EnvironmentError as e:
199 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
200
201def dist(ctx):
202 version(ctx)
203
204def distcheck(ctx):
205 version(ctx)