blob: 77da8595c9bbb0afd56385896f62b4286eee08e2 [file] [log] [blame]
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
Alexander Afanasyeve19f3f62018-10-16 11:25:27 -04003VERSION = '0.5.2'
Yingdi Yu06a678a2014-08-01 17:07:08 -07004APPNAME = 'ChronoSync'
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -05005GIT_TAG_PREFIX = ''
Davide Pesavento7ef57e22017-10-28 16:58:43 -04006
7from waflib import Logs, Utils, Context
Alexander Afanasyev40491df2018-03-09 16:29:52 -05008import os, subprocess
Alexander Afanasyev6af3c152012-06-07 21:14:24 -07009
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080010def options(opt):
Yingdi Yu06a678a2014-08-01 17:07:08 -070011 opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs'])
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080012 opt.load(['default-compiler-flags', 'boost', 'doxygen', 'sphinx_build',
Alexander Afanasyev40491df2018-03-09 16:29:52 -050013 'coverage', 'sanitizers'],
Yingdi Yu06a678a2014-08-01 17:07:08 -070014 tooldir=['.waf-tools'])
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070015
Davide Pesavento7ef57e22017-10-28 16:58:43 -040016 opt.add_option('--with-tests', action='store_true', default=False,
Davide Pesaventofae9def2019-01-29 14:34:33 -050017 help='Build unit tests')
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080018
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080019def configure(conf):
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080020 conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs',
Alexander Afanasyev40491df2018-03-09 16:29:52 -050021 'default-compiler-flags', 'boost', 'coverage',
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080022 'doxygen', 'sphinx_build'])
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070023
Davide Pesavento7ef57e22017-10-28 16:58:43 -040024 if 'PKG_CONFIG_PATH' not in os.environ:
25 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
Yingdi Yu06a678a2014-08-01 17:07:08 -070026 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
27 uselib_store='NDN_CXX', mandatory=True)
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070028
Alexander Afanasyev36eb3ed2017-01-11 12:35:58 -080029 boost_libs = 'system iostreams thread log log_setup'
Davide Pesavento7ef57e22017-10-28 16:58:43 -040030 if conf.options.with_tests:
Alexander Afanasyev40491df2018-03-09 16:29:52 -050031 conf.env['CHRONOSYNC_HAVE_TESTS'] = True
32 conf.define('CHRONOSYNC_HAVE_TESTS', 1)
Yingdi Yu06a678a2014-08-01 17:07:08 -070033 boost_libs += ' unit_test_framework'
Alexander Afanasyev36eb3ed2017-01-11 12:35:58 -080034 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070035
Alexander Afanasyev12d5faa2017-09-21 19:04:22 -040036 conf.check_compiler_flags()
37
Davide Pesavento7ef57e22017-10-28 16:58:43 -040038 # Loading "late" to prevent tests from being compiled with profiling flags
39 conf.load('coverage')
40
Ashlesh Gawande687cf922017-05-30 15:04:16 -050041 conf.load('sanitizers')
42
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080043 # If there happens to be a static library, waf will put the corresponding -L flags
44 # before dynamic library flags. This can result in compilation failure when the
45 # system has a different version of the ChronoSync library installed.
46 conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH']
47
Yingdi Yub20ae812014-08-15 11:20:19 -070048 conf.write_config_header('config.hpp')
49
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070050def build(bld):
Davide Pesaventofae9def2019-01-29 14:34:33 -050051 bld.shlib(target='ChronoSync',
52 vnum=VERSION,
53 cnum=VERSION,
54 source=bld.path.ant_glob('src/**/*.cpp'),
55 use='NDN_CXX BOOST',
56 includes='src .',
57 export_includes='src .')
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070058
Davide Pesaventofae9def2019-01-29 14:34:33 -050059 if bld.env['CHRONOSYNC_HAVE_TESTS']:
Yingdi Yub20ae812014-08-15 11:20:19 -070060 bld.recurse('tests')
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070061
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070062 bld.install_files(
Alexander Afanasyev40491df2018-03-09 16:29:52 -050063 dest = '%s/ChronoSync' % bld.env['INCLUDEDIR'],
64 files = bld.path.ant_glob(['src/*.hpp', 'common.hpp']),
Davide Pesaventofae9def2019-01-29 14:34:33 -050065 cwd = bld.path.find_dir('src'),
66 relative_trick = False)
Alexander Afanasyevce001692013-07-14 11:34:41 -070067
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070068 bld.install_files(
Alexander Afanasyev40491df2018-03-09 16:29:52 -050069 dest = '%s/ChronoSync' % bld.env['INCLUDEDIR'],
70 files = bld.path.get_bld().ant_glob(['src/*.hpp', 'common.hpp', 'config.hpp']),
Davide Pesaventofae9def2019-01-29 14:34:33 -050071 cwd = bld.path.get_bld().find_dir('src'),
Alexander Afanasyev40491df2018-03-09 16:29:52 -050072 relative_trick = False)
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080073
Alexander Afanasyev40491df2018-03-09 16:29:52 -050074 bld(features = 'subst',
Alexander Afanasyev7804c232013-07-14 12:15:41 -070075 source='ChronoSync.pc.in',
76 target='ChronoSync.pc',
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070077 install_path = '${LIBDIR}/pkgconfig',
78 PREFIX = bld.env['PREFIX'],
Alexander Afanasyevce001692013-07-14 11:34:41 -070079 INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Alexander Afanasyev40491df2018-03-09 16:29:52 -050080 VERSION = VERSION)
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070081
Yingdi Yu06a678a2014-08-01 17:07:08 -070082def docs(bld):
83 from waflib import Options
84 Options.commands = ['doxygen', 'sphinx'] + Options.commands
85
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070086def doxygen(bld):
Yingdi Yu06a678a2014-08-01 17:07:08 -070087 version(bld)
88
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080089 if not bld.env.DOXYGEN:
Alexander Afanasyev40491df2018-03-09 16:29:52 -050090 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Yingdi Yu06a678a2014-08-01 17:07:08 -070091
Alexander Afanasyev40491df2018-03-09 16:29:52 -050092 bld(features='subst',
93 name='doxygen.conf',
94 source=['docs/doxygen.conf.in',
95 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
96 target=['docs/doxygen.conf',
97 'docs/named_data_theme/named_data_footer-with-analytics.html'],
98 VERSION=VERSION,
99 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
100 if os.getenv('GOOGLE_ANALYTICS', None) \
101 else '../docs/named_data_theme/named_data_footer.html',
102 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
103
104 bld(features='doxygen',
105 doxyfile='docs/doxygen.conf',
106 use='doxygen.conf')
Yingdi Yu06a678a2014-08-01 17:07:08 -0700107
108def sphinx(bld):
109 version(bld)
110
111 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500112 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
113
114 bld(features='sphinx',
115 config='docs/conf.py',
116 outdir='docs',
117 source=bld.path.ant_glob('docs/**/*.rst'),
118 VERSION=VERSION)
Yingdi Yu06a678a2014-08-01 17:07:08 -0700119
120def version(ctx):
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500121 # don't execute more than once
Yingdi Yu06a678a2014-08-01 17:07:08 -0700122 if getattr(Context.g_module, 'VERSION_BASE', None):
123 return
124
125 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500126 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Yingdi Yu06a678a2014-08-01 17:07:08 -0700127
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500128 # first, try to get a version string from git
129 gotVersionFromGit = False
Yingdi Yu06a678a2014-08-01 17:07:08 -0700130 try:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500131 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500132 out = subprocess.check_output(cmd, universal_newlines=True).strip()
133 if out:
134 gotVersionFromGit = True
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500135 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500136 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500137 else:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500138 # no tags matched
139 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento4a9395b2018-05-24 00:23:22 -0400140 except (OSError, subprocess.CalledProcessError):
Yingdi Yu06a678a2014-08-01 17:07:08 -0700141 pass
142
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500143 versionFile = ctx.path.find_node('VERSION')
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500144 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500145 try:
146 Context.g_module.VERSION = versionFile.read()
147 return
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500148 except EnvironmentError:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500149 pass
150
151 # version was obtained from git, update VERSION file if necessary
152 if versionFile is not None:
153 try:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500154 if versionFile.read() == Context.g_module.VERSION:
155 # already up-to-date
156 return
157 except EnvironmentError as e:
158 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500159 else:
160 versionFile = ctx.path.make_node('VERSION')
161
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500162 try:
163 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500164 except EnvironmentError as e:
165 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500166
Yingdi Yu06a678a2014-08-01 17:07:08 -0700167def dist(ctx):
168 version(ctx)
169
170def distcheck(ctx):
171 version(ctx)