blob: 01139df77e3d1aa9f6b269e4882eae54e0449e4e [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
Yingdi Yu06a678a2014-08-01 17:07:08 -07003from waflib import Logs, Utils, Context
4import os
Alexander Afanasyev182fdc22012-03-05 18:06:52 -08005
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -08006VERSION = '0.3.0'
Yingdi Yu06a678a2014-08-01 17:07:08 -07007APPNAME = 'ChronoSync'
Alexander Afanasyev6af3c152012-06-07 21:14:24 -07008
Alexander Afanasyeve76f2632012-03-05 00:18:42 -08009def options(opt):
Yingdi Yu06a678a2014-08-01 17:07:08 -070010 opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs'])
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080011 opt.load(['default-compiler-flags', 'boost', 'doxygen', 'sphinx_build',
12 'sanitizers', 'coverage', 'pch'],
Yingdi Yu06a678a2014-08-01 17:07:08 -070013 tooldir=['.waf-tools'])
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070014
15 syncopt = opt.add_option_group ("ChronoSync Options")
16
Yingdi Yu06a678a2014-08-01 17:07:08 -070017 syncopt.add_option('--debug', action='store_true', default=False, dest='debug',
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070018 help='''debugging mode''')
Yingdi Yu06a678a2014-08-01 17:07:08 -070019 syncopt.add_option('--with-tests', action='store_true', default=False, dest='_tests',
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070020 help='''build unit tests''')
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080021
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080022def configure(conf):
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080023 conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs',
Ashlesh Gawande687cf922017-05-30 15:04:16 -050024 'default-compiler-flags', 'boost', 'pch', 'coverage',
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080025 'doxygen', 'sphinx_build'])
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070026
Yingdi Yu06a678a2014-08-01 17:07:08 -070027 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
28 uselib_store='NDN_CXX', mandatory=True)
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070029
Alexander Afanasyev36eb3ed2017-01-11 12:35:58 -080030 boost_libs = 'system iostreams thread log log_setup'
Yingdi Yu06a678a2014-08-01 17:07:08 -070031 if conf.options._tests:
Yingdi Yu9d5679a2015-02-01 00:17:58 -080032 conf.env['CHRONOSYNC_HAVE_TESTS'] = 1
33 conf.define('CHRONOSYNC_HAVE_TESTS', 1);
Yingdi Yu06a678a2014-08-01 17:07:08 -070034 boost_libs += ' unit_test_framework'
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070035
Alexander Afanasyev36eb3ed2017-01-11 12:35:58 -080036 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070037
Ashlesh Gawande687cf922017-05-30 15:04:16 -050038 conf.load('sanitizers')
39
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080040 # 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 Yub20ae812014-08-15 11:20:19 -070045 conf.write_config_header('config.hpp')
46
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070047def build(bld):
48 libsync = bld(
Alexander Afanasyevf46eac52013-07-26 11:27:39 -070049 target="ChronoSync",
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080050 vnum = VERSION,
51 cnum = VERSION,
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070052 features=['cxx', 'cxxshlib'],
Yingdi Yub20ae812014-08-15 11:20:19 -070053 source = bld.path.ant_glob(['src/**/*.cpp', 'src/**/*.proto']),
Alexander Afanasyev36eb3ed2017-01-11 12:35:58 -080054 use = 'BOOST NDN_CXX',
Yingdi Yub20ae812014-08-15 11:20:19 -070055 includes = ['src', '.'],
Yingdi Yudea99be2014-08-15 10:45:43 -070056 export_includes=['src', '.'],
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070057 )
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070058
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070059 # Unit tests
Yingdi Yu9d5679a2015-02-01 00:17:58 -080060 if bld.env["CHRONOSYNC_HAVE_TESTS"]:
Yingdi Yub20ae812014-08-15 11:20:19 -070061 bld.recurse('tests')
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070062
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070063 bld.install_files(
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070064 dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Yingdi Yuf7ede412014-08-30 20:37:52 -070065 files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']),
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070066 cwd = bld.path.find_dir("src"),
Yingdi Yuf7ede412014-08-30 20:37:52 -070067 relative_trick = False,
Alexander Afanasyevce001692013-07-14 11:34:41 -070068 )
69
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070070 bld.install_files(
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070071 dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Yingdi Yuf7ede412014-08-30 20:37:52 -070072 files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp', 'config.hpp']),
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070073 cwd = bld.path.get_bld().find_dir("src"),
Yingdi Yuf7ede412014-08-30 20:37:52 -070074 relative_trick = False,
Alexander Afanasyevce001692013-07-14 11:34:41 -070075 )
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080076
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070077 pc = bld(
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070078 features = "subst",
Alexander Afanasyev7804c232013-07-14 12:15:41 -070079 source='ChronoSync.pc.in',
80 target='ChronoSync.pc',
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070081 install_path = '${LIBDIR}/pkgconfig',
82 PREFIX = bld.env['PREFIX'],
Alexander Afanasyevce001692013-07-14 11:34:41 -070083 INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070084 VERSION = VERSION,
85 )
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070086
Yingdi Yu06a678a2014-08-01 17:07:08 -070087# docs
88def docs(bld):
89 from waflib import Options
90 Options.commands = ['doxygen', 'sphinx'] + Options.commands
91
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070092def doxygen(bld):
Yingdi Yu06a678a2014-08-01 17:07:08 -070093 version(bld)
94
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080095 if not bld.env.DOXYGEN:
Yingdi Yu06a678a2014-08-01 17:07:08 -070096 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
115def 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
127def 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
144def dist(ctx):
145 version(ctx)
146
147def distcheck(ctx):
148 version(ctx)