blob: 8a484b003ba8e181f6acbac036d202415c4e15f3 [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''')
19 syncopt.add_option('--with-log4cxx', action='store_true', default=False, dest='log4cxx',
20 help='''Compile with log4cxx''')
Yingdi Yu06a678a2014-08-01 17:07:08 -070021 syncopt.add_option('--with-tests', action='store_true', default=False, dest='_tests',
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070022 help='''build unit tests''')
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080023
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080024def configure(conf):
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080025 conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs',
26 'default-compiler-flags', 'boost', 'pch', 'sanitizers', 'coverage',
27 'doxygen', 'sphinx_build'])
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070028
Yingdi Yu06a678a2014-08-01 17:07:08 -070029 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
30 uselib_store='NDN_CXX', mandatory=True)
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070031
Yingdi Yu06a678a2014-08-01 17:07:08 -070032 boost_libs = 'system iostreams'
33 if conf.options._tests:
Yingdi Yu9d5679a2015-02-01 00:17:58 -080034 conf.env['CHRONOSYNC_HAVE_TESTS'] = 1
35 conf.define('CHRONOSYNC_HAVE_TESTS', 1);
Yingdi Yu06a678a2014-08-01 17:07:08 -070036 boost_libs += ' unit_test_framework'
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070037
Yingdi Yub20ae812014-08-15 11:20:19 -070038 conf.check_boost(lib=boost_libs)
39
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070040 if conf.options.log4cxx:
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070041 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX',
42 mandatory=True)
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070043
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080044 # 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 Yub20ae812014-08-15 11:20:19 -070049 conf.write_config_header('config.hpp')
50
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070051def build(bld):
52 libsync = bld(
Alexander Afanasyevf46eac52013-07-26 11:27:39 -070053 target="ChronoSync",
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080054 vnum = VERSION,
55 cnum = VERSION,
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070056 features=['cxx', 'cxxshlib'],
Yingdi Yub20ae812014-08-15 11:20:19 -070057 source = bld.path.ant_glob(['src/**/*.cpp', 'src/**/*.proto']),
Yingdi Yuf7ede412014-08-30 20:37:52 -070058 use = 'BOOST NDN_CXX LOG4CXX',
Yingdi Yub20ae812014-08-15 11:20:19 -070059 includes = ['src', '.'],
Yingdi Yudea99be2014-08-15 10:45:43 -070060 export_includes=['src', '.'],
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070061 )
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070062
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070063 # Unit tests
Yingdi Yu9d5679a2015-02-01 00:17:58 -080064 if bld.env["CHRONOSYNC_HAVE_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(
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070068 dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Yingdi Yuf7ede412014-08-30 20:37:52 -070069 files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']),
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070070 cwd = bld.path.find_dir("src"),
Yingdi Yuf7ede412014-08-30 20:37:52 -070071 relative_trick = False,
Alexander Afanasyevce001692013-07-14 11:34:41 -070072 )
73
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070074 bld.install_files(
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070075 dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Yingdi Yuf7ede412014-08-30 20:37:52 -070076 files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp', 'config.hpp']),
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070077 cwd = bld.path.get_bld().find_dir("src"),
Yingdi Yuf7ede412014-08-30 20:37:52 -070078 relative_trick = False,
Alexander Afanasyevce001692013-07-14 11:34:41 -070079 )
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080080
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070081 pc = bld(
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070082 features = "subst",
Alexander Afanasyev7804c232013-07-14 12:15:41 -070083 source='ChronoSync.pc.in',
84 target='ChronoSync.pc',
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070085 install_path = '${LIBDIR}/pkgconfig',
86 PREFIX = bld.env['PREFIX'],
Alexander Afanasyevce001692013-07-14 11:34:41 -070087 INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070088 VERSION = VERSION,
89 )
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070090
Yingdi Yu06a678a2014-08-01 17:07:08 -070091# docs
92def docs(bld):
93 from waflib import Options
94 Options.commands = ['doxygen', 'sphinx'] + Options.commands
95
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070096def doxygen(bld):
Yingdi Yu06a678a2014-08-01 17:07:08 -070097 version(bld)
98
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080099 if not bld.env.DOXYGEN:
Yingdi Yu06a678a2014-08-01 17:07:08 -0700100 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
119def 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
131def 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
148def dist(ctx):
149 version(ctx)
150
151def distcheck(ctx):
152 version(ctx)