blob: 11ae78511095d9440394df222dbf6fb5df012473 [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
Davide Pesavento17b266c2019-04-06 21:37:43 -04003from waflib import Context, Logs, Utils
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05004import 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
Davide Pesavento17b266c2019-04-06 21:37:43 -040016 optgrp = opt.add_option_group('PSync Options')
17 optgrp.add_option('--with-examples', action='store_true', default=False,
18 help='Build examples')
19 optgrp.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
Davide Pesavento17b266c2019-04-06 21:37:43 -040027 conf.env.WITH_EXAMPLES = conf.options.with_examples
28 conf.env.WITH_TESTS = conf.options.with_tests
29
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050030 if 'PKG_CONFIG_PATH' not in os.environ:
31 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
Davide Pesavento17b266c2019-04-06 21:37:43 -040032 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050033
Davide Pesavento17b266c2019-04-06 21:37:43 -040034 boost_libs = ['system', 'iostreams']
35 if conf.env.WITH_TESTS:
36 boost_libs.append('unit_test_framework')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050037
38 conf.check_boost(lib=boost_libs, mt=True)
39
40 conf.check_compiler_flags()
41
Davide Pesavento17b266c2019-04-06 21:37:43 -040042 # Loading "late" to prevent tests from being compiled with profiling flags
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050043 conf.load('coverage')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050044 conf.load('sanitizers')
45
46 # 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
48 # system has a different version of the PSync library installed.
Davide Pesavento17b266c2019-04-06 21:37:43 -040049 conf.env.prepend_value('STLIBPATH', ['.'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050050
Davide Pesavento17b266c2019-04-06 21:37:43 -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('PSync/detail/config.hpp', define_prefix='PSYNC_')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050057
58def build(bld):
59 bld.shlib(
60 target='PSync',
Ashlesh Gawande3cb0b1b2019-03-07 15:43:20 -080061 vnum=VERSION,
62 cnum=VERSION,
Davide Pesavento17b266c2019-04-06 21:37:43 -040063 source=bld.path.ant_glob('PSync/**/*.cpp'),
64 use='BOOST NDN_CXX',
65 includes='.',
66 export_includes='.')
67
68 if bld.env.WITH_TESTS:
69 bld.recurse('tests')
70
71 if bld.env.WITH_EXAMPLES:
72 bld.recurse('examples')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050073
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060074 headers = bld.path.ant_glob('PSync/**/*.hpp')
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060075 bld.install_files(bld.env['INCLUDEDIR'], headers, relative_trick=True)
76
77 bld.install_files('${INCLUDEDIR}/PSync/detail',
78 bld.path.find_resource('PSync/detail/config.hpp'))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050079
Davide Pesavento17b266c2019-04-06 21:37:43 -040080 bld(features='subst',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050081 source='PSync.pc.in',
82 target='PSync.pc',
83 install_path = '${LIBDIR}/pkgconfig',
84 PREFIX = bld.env['PREFIX'],
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060085 INCLUDEDIR = bld.env['INCLUDEDIR'],
Davide Pesavento17b266c2019-04-06 21:37:43 -040086 VERSION = VERSION)
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050087
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050088def docs(bld):
89 from waflib import Options
90 Options.commands = ['doxygen', 'sphinx'] + Options.commands
91
92def doxygen(bld):
93 version(bld)
94
95 if not bld.env.DOXYGEN:
96 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
97
98 bld(features='subst',
99 name='doxygen.conf',
100 source=['docs/doxygen.conf.in',
101 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
102 target=['docs/doxygen.conf',
103 'docs/named_data_theme/named_data_footer-with-analytics.html'],
104 VERSION=VERSION,
105 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
106 if os.getenv('GOOGLE_ANALYTICS', None) \
107 else '../docs/named_data_theme/named_data_footer.html',
108 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
109
110 bld(features='doxygen',
111 doxyfile='docs/doxygen.conf',
112 use='doxygen.conf')
113
114def sphinx(bld):
115 version(bld)
116
117 if not bld.env.SPHINX_BUILD:
118 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
119
120 bld(features='sphinx',
121 config='docs/conf.py',
122 outdir='docs',
123 source=bld.path.ant_glob('docs/**/*.rst'),
124 VERSION=VERSION)
125
126def version(ctx):
127 # don't execute more than once
128 if getattr(Context.g_module, 'VERSION_BASE', None):
129 return
130
131 Context.g_module.VERSION_BASE = Context.g_module.VERSION
132 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
133
134 # first, try to get a version string from git
135 gotVersionFromGit = False
136 try:
137 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
138 out = subprocess.check_output(cmd, universal_newlines=True).strip()
139 if out:
140 gotVersionFromGit = True
141 if out.startswith(GIT_TAG_PREFIX):
142 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
143 else:
144 # no tags matched
145 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
146 except (OSError, subprocess.CalledProcessError):
147 pass
148
149 versionFile = ctx.path.find_node('VERSION')
150 if not gotVersionFromGit and versionFile is not None:
151 try:
152 Context.g_module.VERSION = versionFile.read()
153 return
154 except EnvironmentError:
155 pass
156
157 # version was obtained from git, update VERSION file if necessary
158 if versionFile is not None:
159 try:
160 if versionFile.read() == Context.g_module.VERSION:
161 # already up-to-date
162 return
163 except EnvironmentError as e:
164 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
165 else:
166 versionFile = ctx.path.make_node('VERSION')
167
168 try:
169 versionFile.write(Context.g_module.VERSION)
170 except EnvironmentError as e:
171 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
172
173def dist(ctx):
174 version(ctx)
175
176def distcheck(ctx):
177 version(ctx)