blob: 6d8d47600e384b40910166331a106c29e096e28b [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):
Davide Pesavento5f408ae2020-07-15 21:17:04 -040011 opt.load(['compiler_cxx', 'gnu_dirs'])
12 opt.load(['default-compiler-flags',
13 'coverage', 'sanitizers', 'boost',
14 'doxygen', 'sphinx_build'],
Yingdi Yu06a678a2014-08-01 17:07:08 -070015 tooldir=['.waf-tools'])
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070016
Davide Pesaventoc47774f2019-11-09 17:25:09 -050017 optgrp = opt.add_option_group('ChronoSync Options')
18 optgrp.add_option('--with-tests', action='store_true', default=False,
19 help='Build unit tests')
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080020
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080021def configure(conf):
Davide Pesavento5f408ae2020-07-15 21:17:04 -040022 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesaventoc47774f2019-11-09 17:25:09 -050023 'default-compiler-flags', 'boost',
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080024 'doxygen', 'sphinx_build'])
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070025
Davide Pesaventoc47774f2019-11-09 17:25:09 -050026 conf.env.WITH_TESTS = conf.options.with_tests
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070027
Davide Pesaventoc47774f2019-11-09 17:25:09 -050028 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
29 pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR))
30
31 boost_libs = ['system', 'iostreams']
32 if conf.env.WITH_TESTS:
33 boost_libs.append('unit_test_framework')
34
Alexander Afanasyev36eb3ed2017-01-11 12:35:58 -080035 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070036
Alexander Afanasyev12d5faa2017-09-21 19:04:22 -040037 conf.check_compiler_flags()
38
Davide Pesavento7ef57e22017-10-28 16:58:43 -040039 # Loading "late" to prevent tests from being compiled with profiling flags
40 conf.load('coverage')
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.
Davide Pesaventoc47774f2019-11-09 17:25:09 -050046 conf.env.prepend_value('STLIBPATH', ['.'])
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080047
Davide Pesavento07684bc2021-02-07 20:09:28 -050048 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
Davide Pesaventoc47774f2019-11-09 17:25:09 -050049 # The config header will contain all defines that were added using conf.define()
50 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
51 # will not appear in the config header, but will instead be passed directly to the
52 # compiler on the command line.
Davide Pesavento07684bc2021-02-07 20:09:28 -050053 conf.write_config_header('src/detail/config.hpp', define_prefix='CHRONOSYNC_')
Yingdi Yub20ae812014-08-15 11:20:19 -070054
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070055def build(bld):
Davide Pesaventofae9def2019-01-29 14:34:33 -050056 bld.shlib(target='ChronoSync',
57 vnum=VERSION,
58 cnum=VERSION,
59 source=bld.path.ant_glob('src/**/*.cpp'),
60 use='NDN_CXX BOOST',
61 includes='src .',
62 export_includes='src .')
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070063
Davide Pesaventoc47774f2019-11-09 17:25:09 -050064 if bld.env.WITH_TESTS:
Yingdi Yub20ae812014-08-15 11:20:19 -070065 bld.recurse('tests')
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070066
Davide Pesavento07684bc2021-02-07 20:09:28 -050067 srcdir = bld.path.find_dir('src')
68 bld.install_files('${INCLUDEDIR}/ChronoSync',
69 srcdir.ant_glob('**/*.hpp'),
70 cwd=srcdir,
71 relative_trick=True)
Alexander Afanasyevce001692013-07-14 11:34:41 -070072
Davide Pesavento07684bc2021-02-07 20:09:28 -050073 bld.install_files('${INCLUDEDIR}/ChronoSync',
74 'src/detail/config.hpp',
75 cwd=bld.path.get_bld().find_dir('src'),
76 relative_trick=True)
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)