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