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 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 3 | from waflib import Logs, Utils, Context |
| 4 | import os |
Alexander Afanasyev | 182fdc2 | 2012-03-05 18:06:52 -0800 | [diff] [blame] | 5 | |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 6 | VERSION = '0.3.0' |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 7 | APPNAME = 'ChronoSync' |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 8 | |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 9 | def options(opt): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 10 | opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 11 | opt.load(['default-compiler-flags', 'boost', 'doxygen', 'sphinx_build', |
| 12 | 'sanitizers', 'coverage', 'pch'], |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 13 | tooldir=['.waf-tools']) |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 14 | |
| 15 | syncopt = opt.add_option_group ("ChronoSync Options") |
| 16 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 17 | syncopt.add_option('--debug', action='store_true', default=False, dest='debug', |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 18 | help='''debugging mode''') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 19 | syncopt.add_option('--with-tests', action='store_true', default=False, dest='_tests', |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 20 | help='''build unit tests''') |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 21 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 22 | def configure(conf): |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 23 | conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', |
Ashlesh Gawande | 687cf92 | 2017-05-30 15:04:16 -0500 | [diff] [blame] | 24 | 'default-compiler-flags', 'boost', 'pch', 'coverage', |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 25 | 'doxygen', 'sphinx_build']) |
Alexander Afanasyev | 158ec0d | 2012-04-05 13:48:55 -0700 | [diff] [blame] | 26 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 27 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 28 | uselib_store='NDN_CXX', mandatory=True) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | 36eb3ed | 2017-01-11 12:35:58 -0800 | [diff] [blame] | 30 | boost_libs = 'system iostreams thread log log_setup' |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 31 | if conf.options._tests: |
Yingdi Yu | 9d5679a | 2015-02-01 00:17:58 -0800 | [diff] [blame] | 32 | conf.env['CHRONOSYNC_HAVE_TESTS'] = 1 |
| 33 | conf.define('CHRONOSYNC_HAVE_TESTS', 1); |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 34 | boost_libs += ' unit_test_framework' |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 36eb3ed | 2017-01-11 12:35:58 -0800 | [diff] [blame] | 36 | conf.check_boost(lib=boost_libs, mt=True) |
Alexander Afanasyev | 0ad7c21 | 2012-04-05 13:31:14 -0700 | [diff] [blame] | 37 | |
Ashlesh Gawande | 687cf92 | 2017-05-30 15:04:16 -0500 | [diff] [blame] | 38 | conf.load('sanitizers') |
| 39 | |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 40 | # If there happens to be a static library, waf will put the corresponding -L flags |
| 41 | # before dynamic library flags. This can result in compilation failure when the |
| 42 | # system has a different version of the ChronoSync library installed. |
| 43 | conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH'] |
| 44 | |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 45 | conf.write_config_header('config.hpp') |
| 46 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 47 | def build(bld): |
| 48 | libsync = bld( |
Alexander Afanasyev | f46eac5 | 2013-07-26 11:27:39 -0700 | [diff] [blame] | 49 | target="ChronoSync", |
Alexander Afanasyev | f3192eb | 2016-12-19 17:11:20 -0800 | [diff] [blame] | 50 | vnum = VERSION, |
| 51 | cnum = VERSION, |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 52 | features=['cxx', 'cxxshlib'], |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 53 | source = bld.path.ant_glob(['src/**/*.cpp', 'src/**/*.proto']), |
Alexander Afanasyev | 36eb3ed | 2017-01-11 12:35:58 -0800 | [diff] [blame] | 54 | use = 'BOOST NDN_CXX', |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 55 | includes = ['src', '.'], |
Yingdi Yu | dea99be | 2014-08-15 10:45:43 -0700 | [diff] [blame] | 56 | export_includes=['src', '.'], |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 57 | ) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 58 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 59 | # Unit tests |
Yingdi Yu | 9d5679a | 2015-02-01 00:17:58 -0800 | [diff] [blame] | 60 | if bld.env["CHRONOSYNC_HAVE_TESTS"]: |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 61 | bld.recurse('tests') |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 62 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 63 | bld.install_files( |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 64 | dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 65 | files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']), |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 66 | cwd = bld.path.find_dir("src"), |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 67 | relative_trick = False, |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 68 | ) |
| 69 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 70 | bld.install_files( |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 71 | dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 72 | 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] | 73 | cwd = bld.path.get_bld().find_dir("src"), |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 74 | relative_trick = False, |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 75 | ) |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 76 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 77 | pc = bld( |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 78 | features = "subst", |
Alexander Afanasyev | 7804c23 | 2013-07-14 12:15:41 -0700 | [diff] [blame] | 79 | source='ChronoSync.pc.in', |
| 80 | target='ChronoSync.pc', |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 81 | install_path = '${LIBDIR}/pkgconfig', |
| 82 | PREFIX = bld.env['PREFIX'], |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 83 | INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 84 | VERSION = VERSION, |
| 85 | ) |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 86 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 87 | # docs |
| 88 | def docs(bld): |
| 89 | from waflib import Options |
| 90 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 91 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 92 | def doxygen(bld): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 93 | version(bld) |
| 94 | |
Alexander Afanasyev | 34ebcb7 | 2012-03-08 15:54:55 -0800 | [diff] [blame] | 95 | if not bld.env.DOXYGEN: |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 96 | Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
| 97 | else: |
| 98 | bld(features="subst", |
| 99 | name="doxygen-conf", |
| 100 | source=["docs/doxygen.conf.in", |
| 101 | "docs/named_data_theme/named_data_footer-with-analytics.html.in"], |
| 102 | target=["docs/doxygen.conf", |
| 103 | "docs/named_data_theme/named_data_footer-with-analytics.html"], |
| 104 | VERSION=VERSION, |
| 105 | HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \ |
| 106 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 107 | else "../docs/named_data_theme/named_data_footer.html", |
| 108 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""), |
| 109 | ) |
| 110 | |
| 111 | bld(features="doxygen", |
| 112 | doxyfile='docs/doxygen.conf', |
| 113 | use="doxygen-conf") |
| 114 | |
| 115 | def sphinx(bld): |
| 116 | version(bld) |
| 117 | |
| 118 | if not bld.env.SPHINX_BUILD: |
| 119 | bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)") |
| 120 | else: |
| 121 | bld(features="sphinx", |
| 122 | outdir="docs", |
| 123 | source=bld.path.ant_glob("docs/**/*.rst"), |
| 124 | config="docs/conf.py", |
| 125 | VERSION=VERSION) |
| 126 | |
| 127 | def version(ctx): |
| 128 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 129 | return |
| 130 | |
| 131 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 132 | Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')] |
| 133 | |
| 134 | try: |
| 135 | cmd = ['git', 'describe', '--match', 'ChronoSync-*'] |
| 136 | p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE, |
| 137 | stderr=None, stdin=None) |
| 138 | out = p.communicate()[0].strip() |
| 139 | if p.returncode == 0 and out != "": |
| 140 | Context.g_module.VERSION = out[11:] |
| 141 | except: |
| 142 | pass |
| 143 | |
| 144 | def dist(ctx): |
| 145 | version(ctx) |
| 146 | |
| 147 | def distcheck(ctx): |
| 148 | version(ctx) |