blob: 6d3946c5422b161cdf3d0afeeeef233ed59df93c [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 Pesavento13527ec2019-11-09 13:50:36 -050029 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
30 pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR))
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040031
Davide Pesavento27680ae2019-04-06 19:40:01 -040032 boost_libs = ['system', 'program_options']
33 if conf.env.WITH_TESTS:
34 boost_libs.append('unit_test_framework')
Alexander Afanasyevc9934282018-07-17 18:41:36 -040035
Davide Pesavento27680ae2019-04-06 19:40:01 -040036 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040037
38 conf.check_compiler_flags()
39
40 # Loading "late" to prevent tests from being compiled with profiling flags
41 conf.load('coverage')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040042 conf.load('sanitizers')
43
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040044 # If there happens to be a static library, waf will put the corresponding -L flags
45 # before dynamic library flags. This can result in compilation failure when the
Davide Pesavento27680ae2019-04-06 19:40:01 -040046 # system has a different version of the ndn-nac library installed.
47 conf.env.prepend_value('STLIBPATH', ['.'])
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040048
Davide Pesavento27680ae2019-04-06 19:40:01 -040049 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
50 # The config header will contain all defines that were added using conf.define()
51 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
52 # will not appear in the config header, but will instead be passed directly to the
53 # compiler on the command line.
54 conf.write_config_header('config.hpp', define_prefix='NAC_')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040055
56def build(bld):
57 version(bld)
58
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040059 bld(features='subst',
60 name='version.hpp',
61 source='src/version.hpp.in',
62 target='src/version.hpp',
63 install_path=None,
64 VERSION_STRING=VERSION_BASE,
65 VERSION_BUILD=VERSION,
66 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
67 int(VERSION_SPLIT[1]) * 1000 +
68 int(VERSION_SPLIT[2]),
69 VERSION_MAJOR=VERSION_SPLIT[0],
70 VERSION_MINOR=VERSION_SPLIT[1],
71 VERSION_PATCH=VERSION_SPLIT[2])
72
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040073 bld.shlib(
Davide Pesavento8f9d0622018-11-27 01:23:37 -050074 target='ndn-nac',
75 name='libndn-nac',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040076 vnum=VERSION_BASE,
77 cnum=VERSION_BASE,
Davide Pesavento8f9d0622018-11-27 01:23:37 -050078 source=bld.path.ant_glob('src/**/*.cpp'),
79 use='BOOST NDN_CXX',
80 includes=['src', '.'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040081 export_includes=['src', '.'])
82
Davide Pesavento27680ae2019-04-06 19:40:01 -040083 bld.recurse('tools')
84
85 if bld.env.WITH_TESTS:
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040086 bld.recurse('tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040087
Davide Pesavento27680ae2019-04-06 19:40:01 -040088 if bld.env.WITH_EXAMPLES:
89 bld.recurse('examples')
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040090
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040091 bld.install_files(
Davide Pesavento13527ec2019-11-09 13:50:36 -050092 dest = '%s/ndn-nac' % bld.env.INCLUDEDIR,
93 files = bld.path.ant_glob(['src/*.hpp', 'common.hpp']),
Davide Pesavento8f9d0622018-11-27 01:23:37 -050094 cwd = bld.path.find_dir('src'),
Davide Pesavento13527ec2019-11-09 13:50:36 -050095 relative_trick = False)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040096
97 bld.install_files(
Davide Pesavento13527ec2019-11-09 13:50:36 -050098 dest = '%s/ndn-nac' % bld.env.INCLUDEDIR,
99 files = bld.path.get_bld().ant_glob(['src/*.hpp', 'common.hpp', 'config.hpp']),
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500100 cwd = bld.path.get_bld().find_dir('src'),
101 relative_trick = False)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400102
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500103 bld(features='subst',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400104 source='libndn-nac.pc.in',
105 target='libndn-nac.pc',
Davide Pesavento13527ec2019-11-09 13:50:36 -0500106 install_path='${LIBDIR}/pkgconfig',
107 VERSION=VERSION)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400108
109def docs(bld):
110 from waflib import Options
111 Options.commands = ['doxygen', 'sphinx'] + Options.commands
112
113def doxygen(bld):
114 version(bld)
115
116 if not bld.env.DOXYGEN:
117 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
118
119 bld(features='subst',
120 name='doxygen.conf',
121 source=['docs/doxygen.conf.in',
122 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
123 target=['docs/doxygen.conf',
124 'docs/named_data_theme/named_data_footer-with-analytics.html'],
125 VERSION=VERSION,
126 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
127 if os.getenv('GOOGLE_ANALYTICS', None) \
128 else '../docs/named_data_theme/named_data_footer.html',
129 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
130
131 bld(features='doxygen',
132 doxyfile='docs/doxygen.conf',
133 use='doxygen.conf')
134
135def sphinx(bld):
136 version(bld)
137
138 if not bld.env.SPHINX_BUILD:
139 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
140
141 bld(features='sphinx',
142 config='docs/conf.py',
143 outdir='docs',
144 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventoec61b742020-04-18 01:00:12 -0400145 version=VERSION_BASE,
146 release=VERSION)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400147
148def version(ctx):
149 # don't execute more than once
150 if getattr(Context.g_module, 'VERSION_BASE', None):
151 return
152
153 Context.g_module.VERSION_BASE = Context.g_module.VERSION
154 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
155
156 # first, try to get a version string from git
157 gotVersionFromGit = False
158 try:
159 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
160 out = subprocess.check_output(cmd, universal_newlines=True).strip()
161 if out:
162 gotVersionFromGit = True
163 if out.startswith(GIT_TAG_PREFIX):
164 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
165 else:
166 # no tags matched
167 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
168 except (OSError, subprocess.CalledProcessError):
169 pass
170
171 versionFile = ctx.path.find_node('VERSION')
172 if not gotVersionFromGit and versionFile is not None:
173 try:
174 Context.g_module.VERSION = versionFile.read()
175 return
176 except EnvironmentError:
177 pass
178
179 # version was obtained from git, update VERSION file if necessary
180 if versionFile is not None:
181 try:
182 if versionFile.read() == Context.g_module.VERSION:
183 # already up-to-date
184 return
185 except EnvironmentError as e:
186 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
187 else:
188 versionFile = ctx.path.make_node('VERSION')
189
190 try:
191 versionFile.write(Context.g_module.VERSION)
192 except EnvironmentError as e:
193 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
194
195def dist(ctx):
196 version(ctx)
197
198def distcheck(ctx):
199 version(ctx)