blob: 848dbf1cbcdf86e631517385a29637cb5f37bb33 [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
Davide Pesaventoc47774f2019-11-09 17:25:09 -05003from waflib import Context, Logs, Utils
4import os, subprocess
5
Davide Pesaventodd000762020-01-15 01:34:33 -05006VERSION = '0.5.3'
Yingdi Yu06a678a2014-08-01 17:07:08 -07007APPNAME = 'ChronoSync'
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -05008GIT_TAG_PREFIX = ''
Davide Pesavento7ef57e22017-10-28 16:58:43 -04009
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 Pesaventoc47774f2019-11-09 17:25:09 -050016 optgrp = opt.add_option_group('ChronoSync Options')
17 optgrp.add_option('--with-tests', action='store_true', default=False,
18 help='Build unit tests')
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080019
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080020def configure(conf):
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080021 conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs',
Davide Pesaventoc47774f2019-11-09 17:25:09 -050022 'default-compiler-flags', 'boost',
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080023 'doxygen', 'sphinx_build'])
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070024
Davide Pesaventoc47774f2019-11-09 17:25:09 -050025 conf.env.WITH_TESTS = conf.options.with_tests
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070026
Davide Pesaventoc47774f2019-11-09 17:25:09 -050027 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
28 pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR))
29
30 boost_libs = ['system', 'iostreams']
31 if conf.env.WITH_TESTS:
32 boost_libs.append('unit_test_framework')
33
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')
Ashlesh Gawande687cf922017-05-30 15:04:16 -050040 conf.load('sanitizers')
41
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080042 # If there happens to be a static library, waf will put the corresponding -L flags
43 # before dynamic library flags. This can result in compilation failure when the
44 # system has a different version of the ChronoSync library installed.
Davide Pesaventoc47774f2019-11-09 17:25:09 -050045 conf.env.prepend_value('STLIBPATH', ['.'])
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080046
Davide Pesaventoc47774f2019-11-09 17:25:09 -050047 conf.define_cond('CHRONOSYNC_HAVE_TESTS', conf.env.WITH_TESTS)
48 # The config header will contain all defines that were added using conf.define()
49 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
50 # will not appear in the config header, but will instead be passed directly to the
51 # compiler on the command line.
Yingdi Yub20ae812014-08-15 11:20:19 -070052 conf.write_config_header('config.hpp')
53
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070054def build(bld):
Davide Pesaventofae9def2019-01-29 14:34:33 -050055 bld.shlib(target='ChronoSync',
56 vnum=VERSION,
57 cnum=VERSION,
58 source=bld.path.ant_glob('src/**/*.cpp'),
59 use='NDN_CXX BOOST',
60 includes='src .',
61 export_includes='src .')
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070062
Davide Pesaventoc47774f2019-11-09 17:25:09 -050063 if bld.env.WITH_TESTS:
Yingdi Yub20ae812014-08-15 11:20:19 -070064 bld.recurse('tests')
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070065
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070066 bld.install_files(
Davide Pesaventoc47774f2019-11-09 17:25:09 -050067 dest = '%s/ChronoSync' % bld.env.INCLUDEDIR,
Alexander Afanasyev40491df2018-03-09 16:29:52 -050068 files = bld.path.ant_glob(['src/*.hpp', 'common.hpp']),
Davide Pesaventofae9def2019-01-29 14:34:33 -050069 cwd = bld.path.find_dir('src'),
70 relative_trick = False)
Alexander Afanasyevce001692013-07-14 11:34:41 -070071
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070072 bld.install_files(
Davide Pesaventoc47774f2019-11-09 17:25:09 -050073 dest = '%s/ChronoSync' % bld.env.INCLUDEDIR,
Alexander Afanasyev40491df2018-03-09 16:29:52 -050074 files = bld.path.get_bld().ant_glob(['src/*.hpp', 'common.hpp', 'config.hpp']),
Davide Pesaventofae9def2019-01-29 14:34:33 -050075 cwd = bld.path.get_bld().find_dir('src'),
Alexander Afanasyev40491df2018-03-09 16:29:52 -050076 relative_trick = False)
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080077
Davide Pesaventoc47774f2019-11-09 17:25:09 -050078 bld(features='subst',
Alexander Afanasyev7804c232013-07-14 12:15:41 -070079 source='ChronoSync.pc.in',
80 target='ChronoSync.pc',
Davide Pesaventoc47774f2019-11-09 17:25:09 -050081 install_path='${LIBDIR}/pkgconfig',
82 VERSION=VERSION)
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070083
Yingdi Yu06a678a2014-08-01 17:07:08 -070084def docs(bld):
85 from waflib import Options
86 Options.commands = ['doxygen', 'sphinx'] + Options.commands
87
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070088def doxygen(bld):
Yingdi Yu06a678a2014-08-01 17:07:08 -070089 version(bld)
90
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080091 if not bld.env.DOXYGEN:
Alexander Afanasyev40491df2018-03-09 16:29:52 -050092 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Yingdi Yu06a678a2014-08-01 17:07:08 -070093
Alexander Afanasyev40491df2018-03-09 16:29:52 -050094 bld(features='subst',
95 name='doxygen.conf',
96 source=['docs/doxygen.conf.in',
97 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
98 target=['docs/doxygen.conf',
99 'docs/named_data_theme/named_data_footer-with-analytics.html'],
100 VERSION=VERSION,
101 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
102 if os.getenv('GOOGLE_ANALYTICS', None) \
103 else '../docs/named_data_theme/named_data_footer.html',
104 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
105
106 bld(features='doxygen',
107 doxyfile='docs/doxygen.conf',
108 use='doxygen.conf')
Yingdi Yu06a678a2014-08-01 17:07:08 -0700109
110def sphinx(bld):
111 version(bld)
112
113 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500114 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
115
116 bld(features='sphinx',
117 config='docs/conf.py',
118 outdir='docs',
119 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventoc47774f2019-11-09 17:25:09 -0500120 version=VERSION_BASE,
121 release=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)
Davide Pesavento4a9395b2018-05-24 00:23:22 -0400143 except (OSError, subprocess.CalledProcessError):
Yingdi Yu06a678a2014-08-01 17:07:08 -0700144 pass
145
Alexander Afanasyev675d6fb2020-06-01 18:55:17 -0400146 versionFile = ctx.path.find_node('VERSION.info')
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:
Alexander Afanasyev675d6fb2020-06-01 18:55:17 -0400163 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500164
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)