blob: 8d46c71bc188c432b858bc9f5c545ba4d5d2aa93 [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 Pesavento3fb27eb2022-12-31 14:00:51 -05006VERSION = '0.5.5'
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 Pesavento9c4bd6d2022-07-26 15:28:08 -040028 conf.find_program('dot', mandatory=False)
29
30 # Prefer pkgconf if it's installed, because it gives more correct results
31 # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348
32 # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg()
33 conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG')
34
Davide Pesavento5a6292d2022-03-12 15:26:16 -050035 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
Davide Pesavento3fb27eb2022-12-31 14:00:51 -050036 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'],
Davide Pesavento5a6292d2022-03-12 15:26:16 -050037 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Davide Pesaventoc47774f2019-11-09 17:25:09 -050038
39 boost_libs = ['system', 'iostreams']
40 if conf.env.WITH_TESTS:
41 boost_libs.append('unit_test_framework')
42
Alexander Afanasyev36eb3ed2017-01-11 12:35:58 -080043 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070044
Alexander Afanasyev12d5faa2017-09-21 19:04:22 -040045 conf.check_compiler_flags()
46
Davide Pesavento7ef57e22017-10-28 16:58:43 -040047 # Loading "late" to prevent tests from being compiled with profiling flags
48 conf.load('coverage')
Ashlesh Gawande687cf922017-05-30 15:04:16 -050049 conf.load('sanitizers')
50
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080051 # If there happens to be a static library, waf will put the corresponding -L flags
52 # before dynamic library flags. This can result in compilation failure when the
53 # system has a different version of the ChronoSync library installed.
Davide Pesaventoc47774f2019-11-09 17:25:09 -050054 conf.env.prepend_value('STLIBPATH', ['.'])
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080055
Davide Pesavento07684bc2021-02-07 20:09:28 -050056 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
Davide Pesaventoc47774f2019-11-09 17:25:09 -050057 # The config header will contain all defines that were added using conf.define()
58 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
59 # will not appear in the config header, but will instead be passed directly to the
60 # compiler on the command line.
Davide Pesavento07684bc2021-02-07 20:09:28 -050061 conf.write_config_header('src/detail/config.hpp', define_prefix='CHRONOSYNC_')
Yingdi Yub20ae812014-08-15 11:20:19 -070062
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070063def build(bld):
Davide Pesaventofae9def2019-01-29 14:34:33 -050064 bld.shlib(target='ChronoSync',
65 vnum=VERSION,
66 cnum=VERSION,
67 source=bld.path.ant_glob('src/**/*.cpp'),
68 use='NDN_CXX BOOST',
Davide Pesavento780e6462021-02-08 20:58:12 -050069 includes='src/detail',
70 export_includes='src src/detail')
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070071
Davide Pesaventoc47774f2019-11-09 17:25:09 -050072 if bld.env.WITH_TESTS:
Yingdi Yub20ae812014-08-15 11:20:19 -070073 bld.recurse('tests')
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070074
Davide Pesavento07684bc2021-02-07 20:09:28 -050075 srcdir = bld.path.find_dir('src')
76 bld.install_files('${INCLUDEDIR}/ChronoSync',
77 srcdir.ant_glob('**/*.hpp'),
78 cwd=srcdir,
79 relative_trick=True)
Alexander Afanasyevce001692013-07-14 11:34:41 -070080
Davide Pesavento07684bc2021-02-07 20:09:28 -050081 bld.install_files('${INCLUDEDIR}/ChronoSync',
82 'src/detail/config.hpp',
83 cwd=bld.path.get_bld().find_dir('src'),
84 relative_trick=True)
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080085
Davide Pesaventoc47774f2019-11-09 17:25:09 -050086 bld(features='subst',
Alexander Afanasyev7804c232013-07-14 12:15:41 -070087 source='ChronoSync.pc.in',
88 target='ChronoSync.pc',
Davide Pesaventoc47774f2019-11-09 17:25:09 -050089 install_path='${LIBDIR}/pkgconfig',
90 VERSION=VERSION)
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070091
Yingdi Yu06a678a2014-08-01 17:07:08 -070092def docs(bld):
93 from waflib import Options
94 Options.commands = ['doxygen', 'sphinx'] + Options.commands
95
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070096def doxygen(bld):
Yingdi Yu06a678a2014-08-01 17:07:08 -070097 version(bld)
98
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080099 if not bld.env.DOXYGEN:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500100 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Yingdi Yu06a678a2014-08-01 17:07:08 -0700101
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500102 bld(features='subst',
103 name='doxygen.conf',
104 source=['docs/doxygen.conf.in',
105 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
106 target=['docs/doxygen.conf',
107 'docs/named_data_theme/named_data_footer-with-analytics.html'],
108 VERSION=VERSION,
Davide Pesavento9c4bd6d2022-07-26 15:28:08 -0400109 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500110 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
111 if os.getenv('GOOGLE_ANALYTICS', None) \
112 else '../docs/named_data_theme/named_data_footer.html',
113 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
114
115 bld(features='doxygen',
116 doxyfile='docs/doxygen.conf',
117 use='doxygen.conf')
Yingdi Yu06a678a2014-08-01 17:07:08 -0700118
119def sphinx(bld):
120 version(bld)
121
122 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500123 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
124
125 bld(features='sphinx',
126 config='docs/conf.py',
127 outdir='docs',
128 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventoc47774f2019-11-09 17:25:09 -0500129 version=VERSION_BASE,
130 release=VERSION)
Yingdi Yu06a678a2014-08-01 17:07:08 -0700131
132def version(ctx):
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500133 # don't execute more than once
Yingdi Yu06a678a2014-08-01 17:07:08 -0700134 if getattr(Context.g_module, 'VERSION_BASE', None):
135 return
136
137 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500138 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Yingdi Yu06a678a2014-08-01 17:07:08 -0700139
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500140 # first, try to get a version string from git
141 gotVersionFromGit = False
Yingdi Yu06a678a2014-08-01 17:07:08 -0700142 try:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500143 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500144 out = subprocess.check_output(cmd, universal_newlines=True).strip()
145 if out:
146 gotVersionFromGit = True
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500147 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500148 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500149 else:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500150 # no tags matched
151 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento4a9395b2018-05-24 00:23:22 -0400152 except (OSError, subprocess.CalledProcessError):
Yingdi Yu06a678a2014-08-01 17:07:08 -0700153 pass
154
Alexander Afanasyev675d6fb2020-06-01 18:55:17 -0400155 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500156 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500157 try:
158 Context.g_module.VERSION = versionFile.read()
159 return
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500160 except EnvironmentError:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500161 pass
162
163 # version was obtained from git, update VERSION file if necessary
164 if versionFile is not None:
165 try:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500166 if versionFile.read() == Context.g_module.VERSION:
167 # already up-to-date
168 return
169 except EnvironmentError as e:
170 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500171 else:
Alexander Afanasyev675d6fb2020-06-01 18:55:17 -0400172 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500173
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500174 try:
175 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500176 except EnvironmentError as e:
177 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500178
Yingdi Yu06a678a2014-08-01 17:07:08 -0700179def dist(ctx):
Davide Pesavento2ff10562023-02-19 20:14:06 -0500180 ctx.algo = 'tar.xz'
Yingdi Yu06a678a2014-08-01 17:07:08 -0700181 version(ctx)
182
183def distcheck(ctx):
Davide Pesavento2ff10562023-02-19 20:14:06 -0500184 ctx.algo = 'tar.xz'
Yingdi Yu06a678a2014-08-01 17:07:08 -0700185 version(ctx)