blob: 6e49d2a1ceb00b412477af7e5e09c926dd478877 [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 -05008PACKAGE_BUGREPORT = 'https://redmine.named-data.net/projects/nac'
9GIT_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 Pesavento27680ae2019-04-06 19:40:01 -040013 opt.load(['default-compiler-flags', 'coverage', 'sanitizers',
14 'boost', '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')
18 optgrp.add_option('--with-tests', action='store_true', default=False,
19 help='Build unit tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040020
21def configure(conf):
Davide Pesavento8f9d0622018-11-27 01:23:37 -050022 conf.load(['compiler_cxx', 'gnu_dirs',
23 'default-compiler-flags', 'boost',
24 'doxygen', 'sphinx_build'])
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040025
Davide Pesavento27680ae2019-04-06 19:40:01 -040026 conf.env.WITH_EXAMPLES = True
27 conf.env.WITH_TESTS = conf.options.with_tests
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040028
Davide Pesaventoebeaeae2021-04-26 00:42:26 -040029 conf.find_program('dot', var='DOT', mandatory=False)
30
Davide Pesavento13527ec2019-11-09 13:50:36 -050031 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
32 pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR))
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040033
Davide Pesavento27680ae2019-04-06 19:40:01 -040034 boost_libs = ['system', 'program_options']
35 if conf.env.WITH_TESTS:
36 boost_libs.append('unit_test_framework')
Alexander Afanasyevc9934282018-07-17 18:41:36 -040037
Davide Pesavento27680ae2019-04-06 19:40:01 -040038 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040039
40 conf.check_compiler_flags()
41
42 # Loading "late" to prevent tests from being compiled with profiling flags
43 conf.load('coverage')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040044 conf.load('sanitizers')
45
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040046 # If there happens to be a static library, waf will put the corresponding -L flags
47 # before dynamic library flags. This can result in compilation failure when the
Davide Pesavento27680ae2019-04-06 19:40:01 -040048 # system has a different version of the ndn-nac library installed.
49 conf.env.prepend_value('STLIBPATH', ['.'])
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040050
Davide Pesavento27680ae2019-04-06 19:40:01 -040051 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
52 # The config header will contain all defines that were added using conf.define()
53 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
54 # will not appear in the config header, but will instead be passed directly to the
55 # compiler on the command line.
56 conf.write_config_header('config.hpp', define_prefix='NAC_')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040057
58def build(bld):
59 version(bld)
60
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040061 bld(features='subst',
62 name='version.hpp',
63 source='src/version.hpp.in',
64 target='src/version.hpp',
65 install_path=None,
66 VERSION_STRING=VERSION_BASE,
67 VERSION_BUILD=VERSION,
68 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
69 int(VERSION_SPLIT[1]) * 1000 +
70 int(VERSION_SPLIT[2]),
71 VERSION_MAJOR=VERSION_SPLIT[0],
72 VERSION_MINOR=VERSION_SPLIT[1],
73 VERSION_PATCH=VERSION_SPLIT[2])
74
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040075 bld.shlib(
Davide Pesavento8f9d0622018-11-27 01:23:37 -050076 target='ndn-nac',
77 name='libndn-nac',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040078 vnum=VERSION_BASE,
79 cnum=VERSION_BASE,
Davide Pesavento8f9d0622018-11-27 01:23:37 -050080 source=bld.path.ant_glob('src/**/*.cpp'),
81 use='BOOST NDN_CXX',
82 includes=['src', '.'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040083 export_includes=['src', '.'])
84
Davide Pesavento27680ae2019-04-06 19:40:01 -040085 bld.recurse('tools')
86
87 if bld.env.WITH_TESTS:
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040088 bld.recurse('tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040089
Davide Pesavento27680ae2019-04-06 19:40:01 -040090 if bld.env.WITH_EXAMPLES:
91 bld.recurse('examples')
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040092
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040093 bld.install_files(
Davide Pesavento13527ec2019-11-09 13:50:36 -050094 dest = '%s/ndn-nac' % bld.env.INCLUDEDIR,
95 files = bld.path.ant_glob(['src/*.hpp', 'common.hpp']),
Davide Pesavento8f9d0622018-11-27 01:23:37 -050096 cwd = bld.path.find_dir('src'),
Davide Pesavento13527ec2019-11-09 13:50:36 -050097 relative_trick = False)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040098
99 bld.install_files(
Davide Pesavento13527ec2019-11-09 13:50:36 -0500100 dest = '%s/ndn-nac' % bld.env.INCLUDEDIR,
101 files = bld.path.get_bld().ant_glob(['src/*.hpp', 'common.hpp', 'config.hpp']),
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500102 cwd = bld.path.get_bld().find_dir('src'),
103 relative_trick = False)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400104
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500105 bld(features='subst',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400106 source='libndn-nac.pc.in',
107 target='libndn-nac.pc',
Davide Pesavento13527ec2019-11-09 13:50:36 -0500108 install_path='${LIBDIR}/pkgconfig',
109 VERSION=VERSION)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400110
111def docs(bld):
112 from waflib import Options
113 Options.commands = ['doxygen', 'sphinx'] + Options.commands
114
115def doxygen(bld):
116 version(bld)
117
118 if not bld.env.DOXYGEN:
119 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
120
121 bld(features='subst',
122 name='doxygen.conf',
123 source=['docs/doxygen.conf.in',
124 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
125 target=['docs/doxygen.conf',
126 'docs/named_data_theme/named_data_footer-with-analytics.html'],
127 VERSION=VERSION,
Davide Pesaventoebeaeae2021-04-26 00:42:26 -0400128 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400129 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
130 if os.getenv('GOOGLE_ANALYTICS', None) \
131 else '../docs/named_data_theme/named_data_footer.html',
132 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
133
134 bld(features='doxygen',
135 doxyfile='docs/doxygen.conf',
136 use='doxygen.conf')
137
138def sphinx(bld):
139 version(bld)
140
141 if not bld.env.SPHINX_BUILD:
142 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
143
144 bld(features='sphinx',
145 config='docs/conf.py',
146 outdir='docs',
147 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventoec61b742020-04-18 01:00:12 -0400148 version=VERSION_BASE,
149 release=VERSION)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400150
151def version(ctx):
152 # don't execute more than once
153 if getattr(Context.g_module, 'VERSION_BASE', None):
154 return
155
156 Context.g_module.VERSION_BASE = Context.g_module.VERSION
157 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
158
159 # first, try to get a version string from git
160 gotVersionFromGit = False
161 try:
162 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
163 out = subprocess.check_output(cmd, universal_newlines=True).strip()
164 if out:
165 gotVersionFromGit = True
166 if out.startswith(GIT_TAG_PREFIX):
167 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
168 else:
169 # no tags matched
170 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
171 except (OSError, subprocess.CalledProcessError):
172 pass
173
Alexander Afanasyev1b9be6c2020-06-01 19:20:41 -0400174 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400175 if not gotVersionFromGit and versionFile is not None:
176 try:
177 Context.g_module.VERSION = versionFile.read()
178 return
179 except EnvironmentError:
180 pass
181
182 # version was obtained from git, update VERSION file if necessary
183 if versionFile is not None:
184 try:
185 if versionFile.read() == Context.g_module.VERSION:
186 # already up-to-date
187 return
188 except EnvironmentError as e:
189 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
190 else:
Alexander Afanasyev1b9be6c2020-06-01 19:20:41 -0400191 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400192
193 try:
194 versionFile.write(Context.g_module.VERSION)
195 except EnvironmentError as e:
196 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
197
198def dist(ctx):
199 version(ctx)
200
201def distcheck(ctx):
202 version(ctx)