Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame^] | 3 | VERSION = '0.5.0' |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 4 | APPNAME = 'ChronoSync' |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame^] | 5 | GIT_TAG_PREFIX = '' |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 6 | |
| 7 | from waflib import Logs, Utils, Context |
| 8 | import os |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 9 | |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 10 | def options(opt): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 11 | opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 12 | opt.load(['default-compiler-flags', 'boost', 'doxygen', 'sphinx_build', |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 13 | 'coverage', 'sanitizers', 'pch'], |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 14 | tooldir=['.waf-tools']) |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 15 | |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 16 | opt.add_option('--with-tests', action='store_true', default=False, |
| 17 | dest='with_tests', help='''Build unit tests''') |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 18 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 19 | def configure(conf): |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 20 | conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', |
Ashlesh Gawande | 687cf92 | 2017-05-30 15:04:16 -0500 | [diff] [blame] | 21 | 'default-compiler-flags', 'boost', 'pch', 'coverage', |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 22 | 'doxygen', 'sphinx_build']) |
Alexander Afanasyev | 158ec0d | 2012-04-05 13:48:55 -0700 | [diff] [blame] | 23 | |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 24 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 25 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 26 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 27 | uselib_store='NDN_CXX', mandatory=True) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 28 | |
Alexander Afanasyev | 36eb3ed | 2017-01-11 12:35:58 -0800 | [diff] [blame] | 29 | boost_libs = 'system iostreams thread log log_setup' |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 30 | if conf.options.with_tests: |
Yingdi Yu | 9d5679a | 2015-02-01 00:17:58 -0800 | [diff] [blame] | 31 | conf.env['CHRONOSYNC_HAVE_TESTS'] = 1 |
| 32 | conf.define('CHRONOSYNC_HAVE_TESTS', 1); |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 33 | boost_libs += ' unit_test_framework' |
Alexander Afanasyev | 36eb3ed | 2017-01-11 12:35:58 -0800 | [diff] [blame] | 34 | conf.check_boost(lib=boost_libs, mt=True) |
Alexander Afanasyev | 0ad7c21 | 2012-04-05 13:31:14 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 12d5faa | 2017-09-21 19:04:22 -0400 | [diff] [blame] | 36 | conf.check_compiler_flags() |
| 37 | |
Davide Pesavento | 7ef57e2 | 2017-10-28 16:58:43 -0400 | [diff] [blame] | 38 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 39 | conf.load('coverage') |
| 40 | |
Ashlesh Gawande | 687cf92 | 2017-05-30 15:04:16 -0500 | [diff] [blame] | 41 | conf.load('sanitizers') |
| 42 | |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 43 | # 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. |
| 46 | conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH'] |
| 47 | |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 48 | conf.write_config_header('config.hpp') |
| 49 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 50 | def build(bld): |
| 51 | libsync = bld( |
Alexander Afanasyev | f46eac5 | 2013-07-26 11:27:39 -0700 | [diff] [blame] | 52 | target="ChronoSync", |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 53 | vnum = VERSION, |
| 54 | cnum = VERSION, |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 55 | features=['cxx', 'cxxshlib'], |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 56 | source = bld.path.ant_glob(['src/**/*.cpp', 'src/**/*.proto']), |
Alexander Afanasyev | 36eb3ed | 2017-01-11 12:35:58 -0800 | [diff] [blame] | 57 | use = 'BOOST NDN_CXX', |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 58 | includes = ['src', '.'], |
Yingdi Yu | dea99be | 2014-08-15 10:45:43 -0700 | [diff] [blame] | 59 | export_includes=['src', '.'], |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 60 | ) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 61 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 62 | # Unit tests |
Yingdi Yu | 9d5679a | 2015-02-01 00:17:58 -0800 | [diff] [blame] | 63 | if bld.env["CHRONOSYNC_HAVE_TESTS"]: |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 64 | bld.recurse('tests') |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 65 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 66 | bld.install_files( |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 67 | dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 68 | files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']), |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 69 | cwd = bld.path.find_dir("src"), |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 70 | relative_trick = False, |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 71 | ) |
| 72 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 73 | bld.install_files( |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 74 | dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 75 | files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp', 'config.hpp']), |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 76 | cwd = bld.path.get_bld().find_dir("src"), |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 77 | relative_trick = False, |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 78 | ) |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 79 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 80 | pc = bld( |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 81 | features = "subst", |
Alexander Afanasyev | 7804c23 | 2013-07-14 12:15:41 -0700 | [diff] [blame] | 82 | source='ChronoSync.pc.in', |
| 83 | target='ChronoSync.pc', |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 84 | install_path = '${LIBDIR}/pkgconfig', |
| 85 | PREFIX = bld.env['PREFIX'], |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 86 | INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 87 | VERSION = VERSION, |
| 88 | ) |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 89 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 90 | def docs(bld): |
| 91 | from waflib import Options |
| 92 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 93 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 94 | def doxygen(bld): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 95 | version(bld) |
| 96 | |
Alexander Afanasyev | 34ebcb7 | 2012-03-08 15:54:55 -0800 | [diff] [blame] | 97 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame^] | 98 | Logs.error("ERROR: cannot build documentation (`doxygen' not found in $PATH)") |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 99 | else: |
| 100 | bld(features="subst", |
| 101 | name="doxygen-conf", |
| 102 | source=["docs/doxygen.conf.in", |
| 103 | "docs/named_data_theme/named_data_footer-with-analytics.html.in"], |
| 104 | target=["docs/doxygen.conf", |
| 105 | "docs/named_data_theme/named_data_footer-with-analytics.html"], |
| 106 | VERSION=VERSION, |
| 107 | HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \ |
| 108 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 109 | else "../docs/named_data_theme/named_data_footer.html", |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame^] | 110 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', "")) |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 111 | |
| 112 | bld(features="doxygen", |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame^] | 113 | doxyfile="docs/doxygen.conf", |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 114 | use="doxygen-conf") |
| 115 | |
| 116 | def sphinx(bld): |
| 117 | version(bld) |
| 118 | |
| 119 | if not bld.env.SPHINX_BUILD: |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame^] | 120 | bld.fatal("ERROR: cannot build documentation (`sphinx-build' not found in $PATH)") |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 121 | else: |
| 122 | bld(features="sphinx", |
| 123 | outdir="docs", |
| 124 | source=bld.path.ant_glob("docs/**/*.rst"), |
| 125 | config="docs/conf.py", |
| 126 | VERSION=VERSION) |
| 127 | |
| 128 | def version(ctx): |
| 129 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 130 | return |
| 131 | |
| 132 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 133 | Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')] |
| 134 | |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame^] | 135 | didGetVersion = False |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 136 | try: |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame^] | 137 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 138 | p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE, |
| 139 | stderr=None, stdin=None) |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame^] | 140 | out = str(p.communicate()[0].strip()) |
| 141 | didGetVersion = (p.returncode == 0 and out != "") |
| 142 | if didGetVersion: |
| 143 | if out.startswith(GIT_TAG_PREFIX): |
| 144 | Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):] |
| 145 | else: |
| 146 | Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out) |
| 147 | except OSError: |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 148 | pass |
| 149 | |
Alexander Afanasyev | f5fca3a | 2018-02-22 10:50:04 -0500 | [diff] [blame^] | 150 | versionFile = ctx.path.find_node('VERSION') |
| 151 | |
| 152 | if not didGetVersion and versionFile is not None: |
| 153 | try: |
| 154 | Context.g_module.VERSION = versionFile.read() |
| 155 | return |
| 156 | except (OSError, IOError): |
| 157 | pass |
| 158 | |
| 159 | # version was obtained from git, update VERSION file if necessary |
| 160 | if versionFile is not None: |
| 161 | try: |
| 162 | version = versionFile.read() |
| 163 | if version == Context.g_module.VERSION: |
| 164 | return # no need to update |
| 165 | except (OSError, IOError): |
| 166 | Logs.warn("VERSION file exists, but not readable") |
| 167 | else: |
| 168 | versionFile = ctx.path.make_node('VERSION') |
| 169 | |
| 170 | if versionFile is None: |
| 171 | return |
| 172 | |
| 173 | try: |
| 174 | versionFile.write(Context.g_module.VERSION) |
| 175 | except (OSError, IOError): |
| 176 | Logs.warn("VERSION file is not writeable") |
| 177 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 178 | def dist(ctx): |
| 179 | version(ctx) |
| 180 | |
| 181 | def distcheck(ctx): |
| 182 | version(ctx) |