blob: 82aafb605ae73759fa681b92b61ab053e518a124 [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 Afanasyevf5fca3a2018-02-22 10:50:04 -05003VERSION = '0.5.0'
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,
17 dest='with_tests', 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):
Alexander Afanasyev40491df2018-03-09 16:29:52 -050051 bld.shlib(
52 target='ChronoSync',
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080053 vnum = VERSION,
54 cnum = VERSION,
Yingdi Yub20ae812014-08-15 11:20:19 -070055 source = bld.path.ant_glob(['src/**/*.cpp', 'src/**/*.proto']),
Alexander Afanasyev36eb3ed2017-01-11 12:35:58 -080056 use = 'BOOST NDN_CXX',
Yingdi Yub20ae812014-08-15 11:20:19 -070057 includes = ['src', '.'],
Alexander Afanasyev40491df2018-03-09 16:29:52 -050058 export_includes=['src', '.'])
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070059
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070060 # Unit tests
Yingdi Yu9d5679a2015-02-01 00:17:58 -080061 if bld.env["CHRONOSYNC_HAVE_TESTS"]:
Yingdi Yub20ae812014-08-15 11:20:19 -070062 bld.recurse('tests')
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070063
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070064 bld.install_files(
Alexander Afanasyev40491df2018-03-09 16:29:52 -050065 dest = '%s/ChronoSync' % bld.env['INCLUDEDIR'],
66 files = bld.path.ant_glob(['src/*.hpp', 'common.hpp']),
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070067 cwd = bld.path.find_dir("src"),
Yingdi Yuf7ede412014-08-30 20:37:52 -070068 relative_trick = False,
Alexander Afanasyevce001692013-07-14 11:34:41 -070069 )
70
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070071 bld.install_files(
Alexander Afanasyev40491df2018-03-09 16:29:52 -050072 dest = '%s/ChronoSync' % bld.env['INCLUDEDIR'],
73 files = bld.path.get_bld().ant_glob(['src/*.hpp', 'common.hpp', 'config.hpp']),
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070074 cwd = bld.path.get_bld().find_dir("src"),
Alexander Afanasyev40491df2018-03-09 16:29:52 -050075 relative_trick = False)
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080076
Alexander Afanasyev40491df2018-03-09 16:29:52 -050077 bld(features = 'subst',
Alexander Afanasyev7804c232013-07-14 12:15:41 -070078 source='ChronoSync.pc.in',
79 target='ChronoSync.pc',
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070080 install_path = '${LIBDIR}/pkgconfig',
81 PREFIX = bld.env['PREFIX'],
Alexander Afanasyevce001692013-07-14 11:34:41 -070082 INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Alexander Afanasyev40491df2018-03-09 16:29:52 -050083 VERSION = VERSION)
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070084
Yingdi Yu06a678a2014-08-01 17:07:08 -070085def docs(bld):
86 from waflib import Options
87 Options.commands = ['doxygen', 'sphinx'] + Options.commands
88
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070089def doxygen(bld):
Yingdi Yu06a678a2014-08-01 17:07:08 -070090 version(bld)
91
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080092 if not bld.env.DOXYGEN:
Alexander Afanasyev40491df2018-03-09 16:29:52 -050093 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Yingdi Yu06a678a2014-08-01 17:07:08 -070094
Alexander Afanasyev40491df2018-03-09 16:29:52 -050095 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')
Yingdi Yu06a678a2014-08-01 17:07:08 -0700110
111def sphinx(bld):
112 version(bld)
113
114 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500115 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'),
121 VERSION=VERSION)
Yingdi Yu06a678a2014-08-01 17:07:08 -0700122
123def version(ctx):
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500124 # don't execute more than once
Yingdi Yu06a678a2014-08-01 17:07:08 -0700125 if getattr(Context.g_module, 'VERSION_BASE', None):
126 return
127
128 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500129 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Yingdi Yu06a678a2014-08-01 17:07:08 -0700130
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500131 # first, try to get a version string from git
132 gotVersionFromGit = False
Yingdi Yu06a678a2014-08-01 17:07:08 -0700133 try:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500134 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500135 out = subprocess.check_output(cmd, universal_newlines=True).strip()
136 if out:
137 gotVersionFromGit = True
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500138 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500139 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500140 else:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500141 # no tags matched
142 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
143 except subprocess.CalledProcessError:
Yingdi Yu06a678a2014-08-01 17:07:08 -0700144 pass
145
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500146 versionFile = ctx.path.find_node('VERSION')
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500147 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500148 try:
149 Context.g_module.VERSION = versionFile.read()
150 return
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500151 except EnvironmentError:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500152 pass
153
154 # version was obtained from git, update VERSION file if necessary
155 if versionFile is not None:
156 try:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500157 if versionFile.read() == Context.g_module.VERSION:
158 # already up-to-date
159 return
160 except EnvironmentError as e:
161 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500162 else:
163 versionFile = ctx.path.make_node('VERSION')
164
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500165 try:
166 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500167 except EnvironmentError as e:
168 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500169
Yingdi Yu06a678a2014-08-01 17:07:08 -0700170def dist(ctx):
171 version(ctx)
172
173def distcheck(ctx):
174 version(ctx)