blob: 8c89ab5abb25f68d2bd816db9fd92011eb6470ea [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
Davide Pesavento34f7eea2019-11-09 17:33:45 -050030 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
31 pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050032
Davide Pesavento17b266c2019-04-06 21:37:43 -040033 boost_libs = ['system', 'iostreams']
34 if conf.env.WITH_TESTS:
35 boost_libs.append('unit_test_framework')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050036
37 conf.check_boost(lib=boost_libs, mt=True)
38
39 conf.check_compiler_flags()
40
Davide Pesavento17b266c2019-04-06 21:37:43 -040041 # Loading "late" to prevent tests from being compiled with profiling flags
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050042 conf.load('coverage')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050043 conf.load('sanitizers')
44
45 # 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
47 # system has a different version of the PSync library installed.
Davide Pesavento17b266c2019-04-06 21:37:43 -040048 conf.env.prepend_value('STLIBPATH', ['.'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050049
Davide Pesavento17b266c2019-04-06 21:37:43 -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('PSync/detail/config.hpp', define_prefix='PSYNC_')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050056
57def build(bld):
Davide Pesavento34f7eea2019-11-09 17:33:45 -050058 bld.shlib(target='PSync',
59 vnum=VERSION,
60 cnum=VERSION,
61 source=bld.path.ant_glob('PSync/**/*.cpp'),
62 use='NDN_CXX BOOST',
63 includes='.',
64 export_includes='.')
Davide Pesavento17b266c2019-04-06 21:37:43 -040065
66 if bld.env.WITH_TESTS:
67 bld.recurse('tests')
68
69 if bld.env.WITH_EXAMPLES:
70 bld.recurse('examples')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050071
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060072 headers = bld.path.ant_glob('PSync/**/*.hpp')
Davide Pesavento34f7eea2019-11-09 17:33:45 -050073 bld.install_files(bld.env.INCLUDEDIR, headers,
74 relative_trick=True)
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060075
76 bld.install_files('${INCLUDEDIR}/PSync/detail',
77 bld.path.find_resource('PSync/detail/config.hpp'))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050078
Davide Pesavento17b266c2019-04-06 21:37:43 -040079 bld(features='subst',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050080 source='PSync.pc.in',
81 target='PSync.pc',
Davide Pesavento34f7eea2019-11-09 17:33:45 -050082 install_path='${LIBDIR}/pkgconfig',
83 VERSION=VERSION)
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050084
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050085def docs(bld):
86 from waflib import Options
87 Options.commands = ['doxygen', 'sphinx'] + Options.commands
88
89def doxygen(bld):
90 version(bld)
91
92 if not bld.env.DOXYGEN:
93 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
94
95 bld(features='subst',
96 name='doxygen.conf',
97 source=['docs/doxygen.conf.in',
98 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
99 target=['docs/doxygen.conf',
100 'docs/named_data_theme/named_data_footer-with-analytics.html'],
101 VERSION=VERSION,
102 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
103 if os.getenv('GOOGLE_ANALYTICS', None) \
104 else '../docs/named_data_theme/named_data_footer.html',
105 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
106
107 bld(features='doxygen',
108 doxyfile='docs/doxygen.conf',
109 use='doxygen.conf')
110
111def sphinx(bld):
112 version(bld)
113
114 if not bld.env.SPHINX_BUILD:
115 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
116
117 bld(features='sphinx',
118 config='docs/conf.py',
119 outdir='docs',
120 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500121 version=VERSION_BASE,
122 release=VERSION)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500123
124def version(ctx):
125 # don't execute more than once
126 if getattr(Context.g_module, 'VERSION_BASE', None):
127 return
128
129 Context.g_module.VERSION_BASE = Context.g_module.VERSION
130 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
131
132 # first, try to get a version string from git
133 gotVersionFromGit = False
134 try:
135 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
136 out = subprocess.check_output(cmd, universal_newlines=True).strip()
137 if out:
138 gotVersionFromGit = True
139 if out.startswith(GIT_TAG_PREFIX):
140 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
141 else:
142 # no tags matched
143 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
144 except (OSError, subprocess.CalledProcessError):
145 pass
146
147 versionFile = ctx.path.find_node('VERSION')
148 if not gotVersionFromGit and versionFile is not None:
149 try:
150 Context.g_module.VERSION = versionFile.read()
151 return
152 except EnvironmentError:
153 pass
154
155 # version was obtained from git, update VERSION file if necessary
156 if versionFile is not None:
157 try:
158 if versionFile.read() == Context.g_module.VERSION:
159 # already up-to-date
160 return
161 except EnvironmentError as e:
162 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
163 else:
164 versionFile = ctx.path.make_node('VERSION')
165
166 try:
167 versionFile.write(Context.g_module.VERSION)
168 except EnvironmentError as e:
169 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
170
171def dist(ctx):
172 version(ctx)
173
174def distcheck(ctx):
175 version(ctx)