blob: 9412e7dfaa08381d559a28e48da4d6f04a46800f [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3from waflib import Logs, Utils, Context
4import os, subprocess
5
6VERSION = '0.1.0'
7APPNAME = 'PSync'
8GIT_TAG_PREFIX = ''
9
10def options(opt):
11 opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs'])
Davide Pesaventoda278492019-01-29 15:00:49 -050012 opt.load(['default-compiler-flags', 'coverage', 'sanitizers',
13 'boost', 'doxygen', 'sphinx_build'],
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050014 tooldir=['.waf-tools'])
15
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050016 opt.add_option('--with-examples', action='store_true', default=False,
17 help='Build examples')
18
19 opt.add_option('--with-tests', action='store_true', default=False,
20 help='Build unit tests')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050021
22def configure(conf):
Davide Pesaventoda278492019-01-29 15:00:49 -050023 conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs',
24 'default-compiler-flags', 'boost',
25 'doxygen', 'sphinx_build'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050026
27 if 'PKG_CONFIG_PATH' not in os.environ:
28 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
29
30 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
31 uselib_store='NDN_CXX', mandatory=True)
32
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050033 conf.env['WITH_TESTS'] = conf.options.with_tests
34 conf.env['WITH_EXAMPLES'] = conf.options.with_examples
35
Ashlesh Gawandef375bcc2019-02-22 12:43:47 -060036 boost_libs = 'system thread log log_setup iostreams'
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050037 if conf.env['WITH_TESTS']:
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050038 conf.define('WITH_TESTS', 1);
39 boost_libs += ' unit_test_framework'
40
41 conf.check_boost(lib=boost_libs, mt=True)
42
43 conf.check_compiler_flags()
44
45 conf.load('coverage')
46
47 conf.load('sanitizers')
48
49 # 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
51 # system has a different version of the PSync library installed.
52 conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH']
53
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060054 conf.write_config_header('PSync/detail/config.hpp')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050055
56def build(bld):
57 bld.shlib(
58 target='PSync',
Ashlesh Gawande3cb0b1b2019-03-07 15:43:20 -080059 vnum=VERSION,
60 cnum=VERSION,
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060061 source = bld.path.ant_glob('PSync/**/*.cpp'),
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050062 use = 'BOOST NDN_CXX',
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060063 includes = '.',
64 export_includes='.',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050065 )
66
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060067 headers = bld.path.ant_glob('PSync/**/*.hpp')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050068
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060069 bld.install_files(bld.env['INCLUDEDIR'], headers, relative_trick=True)
70
71 bld.install_files('${INCLUDEDIR}/PSync/detail',
72 bld.path.find_resource('PSync/detail/config.hpp'))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050073
74 pc = bld(
75 features = "subst",
76 source='PSync.pc.in',
77 target='PSync.pc',
78 install_path = '${LIBDIR}/pkgconfig',
79 PREFIX = bld.env['PREFIX'],
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060080 INCLUDEDIR = bld.env['INCLUDEDIR'],
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050081 VERSION = VERSION,
82 )
83
84 if bld.env['WITH_TESTS']:
85 bld.recurse('tests')
86
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050087 if bld.env['WITH_EXAMPLES']:
88 bld.recurse('examples')
89
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050090def docs(bld):
91 from waflib import Options
92 Options.commands = ['doxygen', 'sphinx'] + Options.commands
93
94def doxygen(bld):
95 version(bld)
96
97 if not bld.env.DOXYGEN:
98 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
99
100 bld(features='subst',
101 name='doxygen.conf',
102 source=['docs/doxygen.conf.in',
103 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
104 target=['docs/doxygen.conf',
105 'docs/named_data_theme/named_data_footer-with-analytics.html'],
106 VERSION=VERSION,
107 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
108 if os.getenv('GOOGLE_ANALYTICS', None) \
109 else '../docs/named_data_theme/named_data_footer.html',
110 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
111
112 bld(features='doxygen',
113 doxyfile='docs/doxygen.conf',
114 use='doxygen.conf')
115
116def sphinx(bld):
117 version(bld)
118
119 if not bld.env.SPHINX_BUILD:
120 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
121
122 bld(features='sphinx',
123 config='docs/conf.py',
124 outdir='docs',
125 source=bld.path.ant_glob('docs/**/*.rst'),
126 VERSION=VERSION)
127
128def version(ctx):
129 # don't execute more than once
130 if getattr(Context.g_module, 'VERSION_BASE', None):
131 return
132
133 Context.g_module.VERSION_BASE = Context.g_module.VERSION
134 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
135
136 # first, try to get a version string from git
137 gotVersionFromGit = False
138 try:
139 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
140 out = subprocess.check_output(cmd, universal_newlines=True).strip()
141 if out:
142 gotVersionFromGit = True
143 if out.startswith(GIT_TAG_PREFIX):
144 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
145 else:
146 # no tags matched
147 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
148 except (OSError, subprocess.CalledProcessError):
149 pass
150
151 versionFile = ctx.path.find_node('VERSION')
152 if not gotVersionFromGit and versionFile is not None:
153 try:
154 Context.g_module.VERSION = versionFile.read()
155 return
156 except EnvironmentError:
157 pass
158
159 # version was obtained from git, update VERSION file if necessary
160 if versionFile is not None:
161 try:
162 if versionFile.read() == Context.g_module.VERSION:
163 # already up-to-date
164 return
165 except EnvironmentError as e:
166 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
167 else:
168 versionFile = ctx.path.make_node('VERSION')
169
170 try:
171 versionFile.write(Context.g_module.VERSION)
172 except EnvironmentError as e:
173 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
174
175def dist(ctx):
176 version(ctx)
177
178def distcheck(ctx):
179 version(ctx)