blob: b5b392032c1580a92f0f51d17b7017dff5d84e41 [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
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -05003VERSION = '0.5.0'
Yingdi Yu06a678a2014-08-01 17:07:08 -07004APPNAME = 'ChronoSync'
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -05005GIT_TAG_PREFIX = ''
Davide Pesavento7ef57e22017-10-28 16:58:43 -04006
7from waflib import Logs, Utils, Context
8import os
Alexander Afanasyev6af3c152012-06-07 21:14:24 -07009
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080010def options(opt):
Yingdi Yu06a678a2014-08-01 17:07:08 -070011 opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs'])
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080012 opt.load(['default-compiler-flags', 'boost', 'doxygen', 'sphinx_build',
Davide Pesavento7ef57e22017-10-28 16:58:43 -040013 'coverage', 'sanitizers', 'pch'],
Yingdi Yu06a678a2014-08-01 17:07:08 -070014 tooldir=['.waf-tools'])
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070015
Davide Pesavento7ef57e22017-10-28 16:58:43 -040016 opt.add_option('--with-tests', action='store_true', default=False,
17 dest='with_tests', help='''Build unit tests''')
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080018
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080019def configure(conf):
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080020 conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs',
Ashlesh Gawande687cf922017-05-30 15:04:16 -050021 'default-compiler-flags', 'boost', 'pch', 'coverage',
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080022 'doxygen', 'sphinx_build'])
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070023
Davide Pesavento7ef57e22017-10-28 16:58:43 -040024 if 'PKG_CONFIG_PATH' not in os.environ:
25 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
Yingdi Yu06a678a2014-08-01 17:07:08 -070026 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
27 uselib_store='NDN_CXX', mandatory=True)
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070028
Alexander Afanasyev36eb3ed2017-01-11 12:35:58 -080029 boost_libs = 'system iostreams thread log log_setup'
Davide Pesavento7ef57e22017-10-28 16:58:43 -040030 if conf.options.with_tests:
Yingdi Yu9d5679a2015-02-01 00:17:58 -080031 conf.env['CHRONOSYNC_HAVE_TESTS'] = 1
32 conf.define('CHRONOSYNC_HAVE_TESTS', 1);
Yingdi Yu06a678a2014-08-01 17:07:08 -070033 boost_libs += ' unit_test_framework'
Alexander Afanasyev36eb3ed2017-01-11 12:35:58 -080034 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070035
Alexander Afanasyev12d5faa2017-09-21 19:04:22 -040036 conf.check_compiler_flags()
37
Davide Pesavento7ef57e22017-10-28 16:58:43 -040038 # Loading "late" to prevent tests from being compiled with profiling flags
39 conf.load('coverage')
40
Ashlesh Gawande687cf922017-05-30 15:04:16 -050041 conf.load('sanitizers')
42
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080043 # 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 Yub20ae812014-08-15 11:20:19 -070048 conf.write_config_header('config.hpp')
49
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070050def build(bld):
51 libsync = bld(
Alexander Afanasyevf46eac52013-07-26 11:27:39 -070052 target="ChronoSync",
Alexander Afanasyevf3192eb2016-12-19 17:11:20 -080053 vnum = VERSION,
54 cnum = VERSION,
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070055 features=['cxx', 'cxxshlib'],
Yingdi Yub20ae812014-08-15 11:20:19 -070056 source = bld.path.ant_glob(['src/**/*.cpp', 'src/**/*.proto']),
Alexander Afanasyev36eb3ed2017-01-11 12:35:58 -080057 use = 'BOOST NDN_CXX',
Yingdi Yub20ae812014-08-15 11:20:19 -070058 includes = ['src', '.'],
Yingdi Yudea99be2014-08-15 10:45:43 -070059 export_includes=['src', '.'],
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070060 )
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070061
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070062 # Unit tests
Yingdi Yu9d5679a2015-02-01 00:17:58 -080063 if bld.env["CHRONOSYNC_HAVE_TESTS"]:
Yingdi Yub20ae812014-08-15 11:20:19 -070064 bld.recurse('tests')
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070065
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070066 bld.install_files(
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070067 dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Yingdi Yuf7ede412014-08-30 20:37:52 -070068 files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']),
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070069 cwd = bld.path.find_dir("src"),
Yingdi Yuf7ede412014-08-30 20:37:52 -070070 relative_trick = False,
Alexander Afanasyevce001692013-07-14 11:34:41 -070071 )
72
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070073 bld.install_files(
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070074 dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Yingdi Yuf7ede412014-08-30 20:37:52 -070075 files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp', 'config.hpp']),
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070076 cwd = bld.path.get_bld().find_dir("src"),
Yingdi Yuf7ede412014-08-30 20:37:52 -070077 relative_trick = False,
Alexander Afanasyevce001692013-07-14 11:34:41 -070078 )
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080079
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070080 pc = bld(
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070081 features = "subst",
Alexander Afanasyev7804c232013-07-14 12:15:41 -070082 source='ChronoSync.pc.in',
83 target='ChronoSync.pc',
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070084 install_path = '${LIBDIR}/pkgconfig',
85 PREFIX = bld.env['PREFIX'],
Alexander Afanasyevce001692013-07-14 11:34:41 -070086 INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070087 VERSION = VERSION,
88 )
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070089
Yingdi Yu06a678a2014-08-01 17:07:08 -070090def docs(bld):
91 from waflib import Options
92 Options.commands = ['doxygen', 'sphinx'] + Options.commands
93
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070094def doxygen(bld):
Yingdi Yu06a678a2014-08-01 17:07:08 -070095 version(bld)
96
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080097 if not bld.env.DOXYGEN:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -050098 Logs.error("ERROR: cannot build documentation (`doxygen' not found in $PATH)")
Yingdi Yu06a678a2014-08-01 17:07:08 -070099 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 Afanasyevf5fca3a2018-02-22 10:50:04 -0500110 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""))
Yingdi Yu06a678a2014-08-01 17:07:08 -0700111
112 bld(features="doxygen",
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500113 doxyfile="docs/doxygen.conf",
Yingdi Yu06a678a2014-08-01 17:07:08 -0700114 use="doxygen-conf")
115
116def sphinx(bld):
117 version(bld)
118
119 if not bld.env.SPHINX_BUILD:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500120 bld.fatal("ERROR: cannot build documentation (`sphinx-build' not found in $PATH)")
Yingdi Yu06a678a2014-08-01 17:07:08 -0700121 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
128def 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 Afanasyevf5fca3a2018-02-22 10:50:04 -0500135 didGetVersion = False
Yingdi Yu06a678a2014-08-01 17:07:08 -0700136 try:
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500137 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Yingdi Yu06a678a2014-08-01 17:07:08 -0700138 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
139 stderr=None, stdin=None)
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500140 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 Yu06a678a2014-08-01 17:07:08 -0700148 pass
149
Alexander Afanasyevf5fca3a2018-02-22 10:50:04 -0500150 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 Yu06a678a2014-08-01 17:07:08 -0700178def dist(ctx):
179 version(ctx)
180
181def distcheck(ctx):
182 version(ctx)