blob: 03a29952868950b4d8bf883193f94ed96eefa79f [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 Pesaventoc47774f2019-11-09 17:25:09 -050048 conf.define_cond('CHRONOSYNC_HAVE_TESTS', conf.env.WITH_TESTS)
49 # 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.
Yingdi Yub20ae812014-08-15 11:20:19 -070053 conf.write_config_header('config.hpp')
54
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
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070067 bld.install_files(
Davide Pesaventoc47774f2019-11-09 17:25:09 -050068 dest = '%s/ChronoSync' % bld.env.INCLUDEDIR,
Alexander Afanasyev40491df2018-03-09 16:29:52 -050069 files = bld.path.ant_glob(['src/*.hpp', 'common.hpp']),
Davide Pesaventofae9def2019-01-29 14:34:33 -050070 cwd = bld.path.find_dir('src'),
71 relative_trick = False)
Alexander Afanasyevce001692013-07-14 11:34:41 -070072
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070073 bld.install_files(
Davide Pesaventoc47774f2019-11-09 17:25:09 -050074 dest = '%s/ChronoSync' % bld.env.INCLUDEDIR,
Alexander Afanasyev40491df2018-03-09 16:29:52 -050075 files = bld.path.get_bld().ant_glob(['src/*.hpp', 'common.hpp', 'config.hpp']),
Davide Pesaventofae9def2019-01-29 14:34:33 -050076 cwd = bld.path.get_bld().find_dir('src'),
Alexander Afanasyev40491df2018-03-09 16:29:52 -050077 relative_trick = False)
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080078
Davide Pesaventoc47774f2019-11-09 17:25:09 -050079 bld(features='subst',
Alexander Afanasyev7804c232013-07-14 12:15:41 -070080 source='ChronoSync.pc.in',
81 target='ChronoSync.pc',
Davide Pesaventoc47774f2019-11-09 17:25:09 -050082 install_path='${LIBDIR}/pkgconfig',
83 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'),
Davide Pesaventoc47774f2019-11-09 17:25:09 -0500121 version=VERSION_BASE,
122 release=VERSION)
Yingdi Yu06a678a2014-08-01 17:07:08 -0700123
124def version(ctx):
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500125 # don't execute more than once
Yingdi Yu06a678a2014-08-01 17:07:08 -0700126 if getattr(Context.g_module, 'VERSION_BASE', None):
127 return
128
129 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500130 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Yingdi Yu06a678a2014-08-01 17:07:08 -0700131
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500132 # first, try to get a version string from git
133 gotVersionFromGit = False
Yingdi Yu06a678a2014-08-01 17:07:08 -0700134 try:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500135 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500136 out = subprocess.check_output(cmd, universal_newlines=True).strip()
137 if out:
138 gotVersionFromGit = True
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500139 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500140 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500141 else:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500142 # no tags matched
143 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento4a9395b2018-05-24 00:23:22 -0400144 except (OSError, subprocess.CalledProcessError):
Yingdi Yu06a678a2014-08-01 17:07:08 -0700145 pass
146
Alexander Afanasyev675d6fb2020-06-01 18:55:17 -0400147 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500148 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500149 try:
150 Context.g_module.VERSION = versionFile.read()
151 return
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500152 except EnvironmentError:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500153 pass
154
155 # version was obtained from git, update VERSION file if necessary
156 if versionFile is not None:
157 try:
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500158 if versionFile.read() == Context.g_module.VERSION:
159 # already up-to-date
160 return
161 except EnvironmentError as e:
162 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500163 else:
Alexander Afanasyev675d6fb2020-06-01 18:55:17 -0400164 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500165
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500166 try:
167 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev40491df2018-03-09 16:29:52 -0500168 except EnvironmentError as e:
169 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500170
Yingdi Yu06a678a2014-08-01 17:07:08 -0700171def dist(ctx):
172 version(ctx)
173
174def distcheck(ctx):
175 version(ctx)