blob: ea3916ff0e33b5f63d40c3281eb25fd24f482736 [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 Pesavento9330c2e2023-09-14 21:38:02 -04003import os
4import subprocess
5from waflib import Context, Logs
Davide Pesaventoc47774f2019-11-09 17:25:09 -05006
Davide Pesavento3fb27eb2022-12-31 14:00:51 -05007VERSION = '0.5.5'
Yingdi Yu06a678a2014-08-01 17:07:08 -07008APPNAME = 'ChronoSync'
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -05009GIT_TAG_PREFIX = ''
Davide Pesavento7ef57e22017-10-28 16:58:43 -040010
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080011def options(opt):
Davide Pesavento5f408ae2020-07-15 21:17:04 -040012 opt.load(['compiler_cxx', 'gnu_dirs'])
13 opt.load(['default-compiler-flags',
14 'coverage', 'sanitizers', 'boost',
15 'doxygen', 'sphinx_build'],
Yingdi Yu06a678a2014-08-01 17:07:08 -070016 tooldir=['.waf-tools'])
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070017
Davide Pesaventoc47774f2019-11-09 17:25:09 -050018 optgrp = opt.add_option_group('ChronoSync Options')
19 optgrp.add_option('--with-tests', action='store_true', default=False,
20 help='Build unit tests')
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080021
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080022def configure(conf):
Davide Pesavento5f408ae2020-07-15 21:17:04 -040023 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesaventoc47774f2019-11-09 17:25:09 -050024 'default-compiler-flags', 'boost',
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080025 'doxygen', 'sphinx_build'])
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070026
Davide Pesaventoc47774f2019-11-09 17:25:09 -050027 conf.env.WITH_TESTS = conf.options.with_tests
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070028
Davide Pesavento9c4bd6d2022-07-26 15:28:08 -040029 conf.find_program('dot', mandatory=False)
30
31 # Prefer pkgconf if it's installed, because it gives more correct results
32 # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348
33 # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg()
34 conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG')
35
Davide Pesavento5a6292d2022-03-12 15:26:16 -050036 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
Davide Pesavento3fb27eb2022-12-31 14:00:51 -050037 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'],
Davide Pesavento5a6292d2022-03-12 15:26:16 -050038 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Davide Pesaventoc47774f2019-11-09 17:25:09 -050039
Davide Pesavento9330c2e2023-09-14 21:38:02 -040040 conf.check_boost(lib='iostreams', mt=True)
Davide Pesavento1af79492023-09-22 15:45:21 -040041 if conf.env.BOOST_VERSION_NUMBER < 107100:
42 conf.fatal('The minimum supported version of Boost is 1.71.0.\n'
43 'Please upgrade your distribution or manually install a newer version of Boost.\n'
44 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
Davide Pesaventoc47774f2019-11-09 17:25:09 -050045
Davide Pesavento9330c2e2023-09-14 21:38:02 -040046 if conf.env.WITH_TESTS:
47 conf.check_boost(lib='filesystem unit_test_framework', mt=True, uselib_store='BOOST_TESTS')
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070048
Alexander Afanasyev12d5faa2017-09-21 19:04:22 -040049 conf.check_compiler_flags()
50
Davide Pesavento7ef57e22017-10-28 16:58:43 -040051 # Loading "late" to prevent tests from being compiled with profiling flags
52 conf.load('coverage')
Ashlesh Gawande687cf922017-05-30 15:04:16 -050053 conf.load('sanitizers')
54
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080055 # If there happens to be a static library, waf will put the corresponding -L flags
56 # before dynamic library flags. This can result in compilation failure when the
57 # system has a different version of the ChronoSync library installed.
Davide Pesaventoc47774f2019-11-09 17:25:09 -050058 conf.env.prepend_value('STLIBPATH', ['.'])
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080059
Davide Pesavento07684bc2021-02-07 20:09:28 -050060 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
Davide Pesaventoc47774f2019-11-09 17:25:09 -050061 # The config header will contain all defines that were added using conf.define()
62 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
63 # will not appear in the config header, but will instead be passed directly to the
64 # compiler on the command line.
Davide Pesavento07684bc2021-02-07 20:09:28 -050065 conf.write_config_header('src/detail/config.hpp', define_prefix='CHRONOSYNC_')
Yingdi Yub20ae812014-08-15 11:20:19 -070066
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070067def build(bld):
Davide Pesavento9330c2e2023-09-14 21:38:02 -040068 bld.shlib(
69 target='ChronoSync',
70 vnum=VERSION,
71 cnum=VERSION,
72 source=bld.path.ant_glob('src/**/*.cpp'),
73 use='BOOST NDN_CXX',
74 includes='src/detail',
75 export_includes='src src/detail')
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070076
Davide Pesaventoc47774f2019-11-09 17:25:09 -050077 if bld.env.WITH_TESTS:
Yingdi Yub20ae812014-08-15 11:20:19 -070078 bld.recurse('tests')
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070079
Davide Pesavento9330c2e2023-09-14 21:38:02 -040080 # Install header files
Davide Pesavento07684bc2021-02-07 20:09:28 -050081 srcdir = bld.path.find_dir('src')
82 bld.install_files('${INCLUDEDIR}/ChronoSync',
83 srcdir.ant_glob('**/*.hpp'),
84 cwd=srcdir,
85 relative_trick=True)
Davide Pesavento9330c2e2023-09-14 21:38:02 -040086 bld.install_files('${INCLUDEDIR}/ChronoSync/detail', 'src/detail/config.hpp')
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080087
Davide Pesaventoc47774f2019-11-09 17:25:09 -050088 bld(features='subst',
Alexander Afanasyev7804c232013-07-14 12:15:41 -070089 source='ChronoSync.pc.in',
90 target='ChronoSync.pc',
Davide Pesaventoc47774f2019-11-09 17:25:09 -050091 install_path='${LIBDIR}/pkgconfig',
92 VERSION=VERSION)
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070093
Yingdi Yu06a678a2014-08-01 17:07:08 -070094def docs(bld):
95 from waflib import Options
96 Options.commands = ['doxygen', 'sphinx'] + Options.commands
97
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070098def doxygen(bld):
Yingdi Yu06a678a2014-08-01 17:07:08 -070099 version(bld)
100
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -0800101 if not bld.env.DOXYGEN:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500102 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Yingdi Yu06a678a2014-08-01 17:07:08 -0700103
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500104 bld(features='subst',
105 name='doxygen.conf',
106 source=['docs/doxygen.conf.in',
107 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
108 target=['docs/doxygen.conf',
109 'docs/named_data_theme/named_data_footer-with-analytics.html'],
110 VERSION=VERSION,
Davide Pesavento9c4bd6d2022-07-26 15:28:08 -0400111 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500112 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
113 if os.getenv('GOOGLE_ANALYTICS', None) \
114 else '../docs/named_data_theme/named_data_footer.html',
115 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
116
117 bld(features='doxygen',
118 doxyfile='docs/doxygen.conf',
119 use='doxygen.conf')
Yingdi Yu06a678a2014-08-01 17:07:08 -0700120
121def sphinx(bld):
122 version(bld)
123
124 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500125 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
126
127 bld(features='sphinx',
128 config='docs/conf.py',
129 outdir='docs',
130 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventoc47774f2019-11-09 17:25:09 -0500131 version=VERSION_BASE,
132 release=VERSION)
Yingdi Yu06a678a2014-08-01 17:07:08 -0700133
134def version(ctx):
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500135 # don't execute more than once
Yingdi Yu06a678a2014-08-01 17:07:08 -0700136 if getattr(Context.g_module, 'VERSION_BASE', None):
137 return
138
139 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500140 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Yingdi Yu06a678a2014-08-01 17:07:08 -0700141
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500142 # first, try to get a version string from git
143 gotVersionFromGit = False
Yingdi Yu06a678a2014-08-01 17:07:08 -0700144 try:
Davide Pesavento9330c2e2023-09-14 21:38:02 -0400145 cmd = ['git', 'describe', '--always', '--match', f'{GIT_TAG_PREFIX}*']
146 out = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500147 if out:
148 gotVersionFromGit = True
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500149 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500150 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500151 else:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500152 # no tags matched
Davide Pesavento9330c2e2023-09-14 21:38:02 -0400153 Context.g_module.VERSION = f'{VERSION_BASE}-commit-{out}'
154 except (OSError, subprocess.SubprocessError):
Yingdi Yu06a678a2014-08-01 17:07:08 -0700155 pass
156
Alexander Afanasyev675d6fb2020-06-01 18:55:17 -0400157 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500158 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500159 try:
160 Context.g_module.VERSION = versionFile.read()
161 return
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500162 except EnvironmentError:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500163 pass
164
165 # version was obtained from git, update VERSION file if necessary
166 if versionFile is not None:
167 try:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500168 if versionFile.read() == Context.g_module.VERSION:
169 # already up-to-date
170 return
171 except EnvironmentError as e:
Davide Pesavento9330c2e2023-09-14 21:38:02 -0400172 Logs.warn(f'{versionFile} exists but is not readable ({e.strerror})')
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500173 else:
Alexander Afanasyev675d6fb2020-06-01 18:55:17 -0400174 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500175
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500176 try:
177 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500178 except EnvironmentError as e:
Davide Pesavento9330c2e2023-09-14 21:38:02 -0400179 Logs.warn(f'{versionFile} is not writable ({e.strerror})')
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500180
Yingdi Yu06a678a2014-08-01 17:07:08 -0700181def dist(ctx):
Davide Pesavento2ff10562023-02-19 20:14:06 -0500182 ctx.algo = 'tar.xz'
Yingdi Yu06a678a2014-08-01 17:07:08 -0700183 version(ctx)
184
185def distcheck(ctx):
Davide Pesavento2ff10562023-02-19 20:14:06 -0500186 ctx.algo = 'tar.xz'
Yingdi Yu06a678a2014-08-01 17:07:08 -0700187 version(ctx)