blob: fc24dedbb3716ac6e717c8d885860892c213e11f [file] [log] [blame]
spirosmastorakisa99994c2016-01-24 15:26:53 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2VERSION='0.1.0'
3APPNAME='nTorrent'
4
5from waflib import Configure, Utils, Logs, Context
6import os
7
8def options(opt):
9
10 opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs'])
11
spirosmastorakis15ebb1e2016-01-25 21:20:25 -080012 opt.load(['default-compiler-flags', 'coverage', 'boost',
spirosmastorakisa99994c2016-01-24 15:26:53 -080013 'doxygen', 'sphinx_build'],
14 tooldir=['.waf-tools'])
15
16 opt = opt.add_option_group('nTorrent Options')
17
18 opt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
19 help='''build unit tests''')
20
21def configure(conf):
22 conf.load(['compiler_c', 'compiler_cxx',
23 'default-compiler-flags', 'boost', 'gnu_dirs',
24 'doxygen', 'sphinx_build'])
25
26 if 'PKG_CONFIG_PATH' not in os.environ:
27 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
28
29 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
30 uselib_store='NDN_CXX', mandatory=True)
31
32 boost_libs = 'system random thread filesystem'
33 if conf.options.with_tests:
34 conf.env['WITH_TESTS'] = 1
35 conf.define('WITH_TESTS', 1);
36 boost_libs += ' unit_test_framework'
37
38 conf.check_boost(lib=boost_libs)
39 if conf.env.BOOST_VERSION_NUMBER < 104800:
40 Logs.error("Minimum required boost version is 1.48.0")
41 Logs.error("Please upgrade your distribution or install custom boost libraries" +
42 " (http://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)")
43 return
44
spirosmastorakis15ebb1e2016-01-25 21:20:25 -080045 # Loading "late" to prevent tests to be compiled with profiling flags
46 conf.load('coverage')
47
spirosmastorakisa99994c2016-01-24 15:26:53 -080048 conf.write_config_header('src/config.h')
49
50def build (bld):
51 feature_list = 'cxx'
52
53 bld(
54 features='cxx',
55 name='nTorrent',
56 source=bld.path.ant_glob(['src/**/*.cpp'],
57 excl=['src/main.cpp',]),
58 use='version NDN_CXX BOOST',
59 includes='src',
60 export_includes='src',
61 )
62
63 if bld.env["WITH_TESTS"]:
64 feature_list += ' cxxstlib'
65 else:
66 feature_list += ' cxxprogram'
67
68 # Unit tests
69 if bld.env["WITH_TESTS"]:
70 unittests = bld.program (
71 target="unit-tests",
72 source = bld.path.ant_glob(['tests/**/*.cpp']),
73 features=['cxx', 'cxxprogram'],
74 use = 'BOOST nTorrent',
75 includes = "src .",
76 install_path = None
77 )
78
79# docs
80def docs(bld):
81 from waflib import Options
82 Options.commands = ['doxygen', 'sphinx'] + Options.commands
83
84def doxygen(bld):
85 version(bld)
86
87 if not bld.env.DOXYGEN:
88 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
89 else:
90 bld(features="subst",
91 name="doxygen-conf",
92 source=["docs/doxygen.conf.in",
93 "docs/named_data_theme/named_data_footer-with-analytics.html.in"],
94 target=["docs/doxygen.conf",
95 "docs/named_data_theme/named_data_footer-with-analytics.html"],
96 VERSION=VERSION,
97 HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \
98 if os.getenv('GOOGLE_ANALYTICS', None) \
99 else "../docs/named_data_theme/named_data_footer.html",
100 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""),
101 )
102
103 bld(features="doxygen",
104 doxyfile='docs/doxygen.conf',
105 use="doxygen-conf")
106
107def sphinx(bld):
108 version(bld)
109
110 if not bld.env.SPHINX_BUILD:
111 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
112 else:
113 bld(features="sphinx",
114 outdir="docs",
115 source=bld.path.ant_glob("docs/**/*.rst"),
116 config="docs/conf.py",
117 VERSION=VERSION)
118
119def version(ctx):
120 if getattr(Context.g_module, 'VERSION_BASE', None):
121 return
122
123 Context.g_module.VERSION_BASE = Context.g_module.VERSION
124 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
125
126 try:
127 cmd = ['git', 'describe', '--match', 'nTorrent-*']
128 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
129 stderr=None, stdin=None)
130 out = p.communicate()[0].strip()
131 if p.returncode == 0 and out != "":
132 Context.g_module.VERSION = out[11:]
133 except:
134 pass