blob: 5687dd3b13d0411c3ea8299abffc69170b0aa7e6 [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
29 if 'PKG_CONFIG_PATH' not in os.environ:
30 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
Davide Pesavento27680ae2019-04-06 19:40:01 -040031 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040032
Davide Pesavento27680ae2019-04-06 19:40:01 -040033 boost_libs = ['system', 'program_options']
34 if conf.env.WITH_TESTS:
35 boost_libs.append('unit_test_framework')
Alexander Afanasyevc9934282018-07-17 18:41:36 -040036
Davide Pesavento27680ae2019-04-06 19:40:01 -040037 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040038
39 conf.check_compiler_flags()
40
41 # Loading "late" to prevent tests from being compiled with profiling flags
42 conf.load('coverage')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040043 conf.load('sanitizers')
44
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040045 # If there happens to be a static library, waf will put the corresponding -L flags
46 # before dynamic library flags. This can result in compilation failure when the
Davide Pesavento27680ae2019-04-06 19:40:01 -040047 # system has a different version of the ndn-nac library installed.
48 conf.env.prepend_value('STLIBPATH', ['.'])
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040049
Davide Pesavento27680ae2019-04-06 19:40:01 -040050 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
51 # The config header will contain all defines that were added using conf.define()
52 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
53 # will not appear in the config header, but will instead be passed directly to the
54 # compiler on the command line.
55 conf.write_config_header('config.hpp', define_prefix='NAC_')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040056
57def build(bld):
58 version(bld)
59
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040060 bld(features='subst',
61 name='version.hpp',
62 source='src/version.hpp.in',
63 target='src/version.hpp',
64 install_path=None,
65 VERSION_STRING=VERSION_BASE,
66 VERSION_BUILD=VERSION,
67 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
68 int(VERSION_SPLIT[1]) * 1000 +
69 int(VERSION_SPLIT[2]),
70 VERSION_MAJOR=VERSION_SPLIT[0],
71 VERSION_MINOR=VERSION_SPLIT[1],
72 VERSION_PATCH=VERSION_SPLIT[2])
73
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040074 bld.shlib(
Davide Pesavento8f9d0622018-11-27 01:23:37 -050075 target='ndn-nac',
76 name='libndn-nac',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040077 vnum=VERSION_BASE,
78 cnum=VERSION_BASE,
Davide Pesavento8f9d0622018-11-27 01:23:37 -050079 source=bld.path.ant_glob('src/**/*.cpp'),
80 use='BOOST NDN_CXX',
81 includes=['src', '.'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040082 export_includes=['src', '.'])
83
Davide Pesavento27680ae2019-04-06 19:40:01 -040084 bld.recurse('tools')
85
86 if bld.env.WITH_TESTS:
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040087 bld.recurse('tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040088
Davide Pesavento27680ae2019-04-06 19:40:01 -040089 if bld.env.WITH_EXAMPLES:
90 bld.recurse('examples')
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040091
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040092 bld.install_files(
Davide Pesavento8f9d0622018-11-27 01:23:37 -050093 dest = '%s/ndn-nac' % bld.env['INCLUDEDIR'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040094 files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']),
Davide Pesavento8f9d0622018-11-27 01:23:37 -050095 cwd = bld.path.find_dir('src'),
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040096 relative_trick = True)
97
98 bld.install_files(
Davide Pesavento8f9d0622018-11-27 01:23:37 -050099 dest = '%s/ndn-nac' % bld.env['INCLUDEDIR'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400100 files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'common.hpp', 'config.hpp']),
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500101 cwd = bld.path.get_bld().find_dir('src'),
102 relative_trick = False)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400103
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500104 bld(features='subst',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400105 source='libndn-nac.pc.in',
106 target='libndn-nac.pc',
107 install_path = '${LIBDIR}/pkgconfig',
108 PREFIX = bld.env['PREFIX'],
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500109 INCLUDEDIR = '%s/ndn-nac' % bld.env['INCLUDEDIR'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400110 VERSION = VERSION)
111
112def docs(bld):
113 from waflib import Options
114 Options.commands = ['doxygen', 'sphinx'] + Options.commands
115
116def 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,
129 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'),
148 VERSION=VERSION)
149
150def version(ctx):
151 # don't execute more than once
152 if getattr(Context.g_module, 'VERSION_BASE', None):
153 return
154
155 Context.g_module.VERSION_BASE = Context.g_module.VERSION
156 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
157
158 # first, try to get a version string from git
159 gotVersionFromGit = False
160 try:
161 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
162 out = subprocess.check_output(cmd, universal_newlines=True).strip()
163 if out:
164 gotVersionFromGit = True
165 if out.startswith(GIT_TAG_PREFIX):
166 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
167 else:
168 # no tags matched
169 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
170 except (OSError, subprocess.CalledProcessError):
171 pass
172
173 versionFile = ctx.path.find_node('VERSION')
174 if not gotVersionFromGit and versionFile is not None:
175 try:
176 Context.g_module.VERSION = versionFile.read()
177 return
178 except EnvironmentError:
179 pass
180
181 # version was obtained from git, update VERSION file if necessary
182 if versionFile is not None:
183 try:
184 if versionFile.read() == Context.g_module.VERSION:
185 # already up-to-date
186 return
187 except EnvironmentError as e:
188 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
189 else:
190 versionFile = ctx.path.make_node('VERSION')
191
192 try:
193 versionFile.write(Context.g_module.VERSION)
194 except EnvironmentError as e:
195 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
196
197def dist(ctx):
198 version(ctx)
199
200def distcheck(ctx):
201 version(ctx)