blob: 0b431e0e0a1f106a47b0d10b7aa8dc3f04f82dec [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 Afanasyev9e500212017-10-19 10:28:07 -04003VERSION = '0.4.0'
Yingdi Yu06a678a2014-08-01 17:07:08 -07004APPNAME = 'ChronoSync'
Davide Pesavento7ef57e22017-10-28 16:58:43 -04005GIT_TAG_PREFIX = 'ChronoSync-'
6
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 -070090# docs
91def docs(bld):
92 from waflib import Options
93 Options.commands = ['doxygen', 'sphinx'] + Options.commands
94
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070095def doxygen(bld):
Yingdi Yu06a678a2014-08-01 17:07:08 -070096 version(bld)
97
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080098 if not bld.env.DOXYGEN:
Yingdi Yu06a678a2014-08-01 17:07:08 -070099 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
100 else:
101 bld(features="subst",
102 name="doxygen-conf",
103 source=["docs/doxygen.conf.in",
104 "docs/named_data_theme/named_data_footer-with-analytics.html.in"],
105 target=["docs/doxygen.conf",
106 "docs/named_data_theme/named_data_footer-with-analytics.html"],
107 VERSION=VERSION,
108 HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \
109 if os.getenv('GOOGLE_ANALYTICS', None) \
110 else "../docs/named_data_theme/named_data_footer.html",
111 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""),
112 )
113
114 bld(features="doxygen",
115 doxyfile='docs/doxygen.conf',
116 use="doxygen-conf")
117
118def sphinx(bld):
119 version(bld)
120
121 if not bld.env.SPHINX_BUILD:
122 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
123 else:
124 bld(features="sphinx",
125 outdir="docs",
126 source=bld.path.ant_glob("docs/**/*.rst"),
127 config="docs/conf.py",
128 VERSION=VERSION)
129
130def version(ctx):
131 if getattr(Context.g_module, 'VERSION_BASE', None):
132 return
133
134 Context.g_module.VERSION_BASE = Context.g_module.VERSION
135 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
136
137 try:
Davide Pesavento7ef57e22017-10-28 16:58:43 -0400138 cmd = ['git', 'describe', '--match', '%s*' % GIT_TAG_PREFIX]
Yingdi Yu06a678a2014-08-01 17:07:08 -0700139 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
140 stderr=None, stdin=None)
141 out = p.communicate()[0].strip()
142 if p.returncode == 0 and out != "":
143 Context.g_module.VERSION = out[11:]
144 except:
145 pass
146
147def dist(ctx):
148 version(ctx)
149
150def distcheck(ctx):
151 version(ctx)