blob: a4c72b304f9bf23257ea193df280409bcbd9f842 [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 )
Mickey Sweattf91ced42016-04-20 13:30:37 -070062 # main
63 bld(
64 target='ntorrent',
65 features='cxx cxxprogram',
66 source='src/main.cpp',
67 use = 'BOOST nTorrent')
spirosmastorakisa99994c2016-01-24 15:26:53 -080068
69 if bld.env["WITH_TESTS"]:
70 feature_list += ' cxxstlib'
71 else:
72 feature_list += ' cxxprogram'
73
74 # Unit tests
75 if bld.env["WITH_TESTS"]:
76 unittests = bld.program (
77 target="unit-tests",
78 source = bld.path.ant_glob(['tests/**/*.cpp']),
79 features=['cxx', 'cxxprogram'],
80 use = 'BOOST nTorrent',
81 includes = "src .",
82 install_path = None
83 )
84
85# docs
86def docs(bld):
87 from waflib import Options
88 Options.commands = ['doxygen', 'sphinx'] + Options.commands
89
90def doxygen(bld):
91 version(bld)
92
93 if not bld.env.DOXYGEN:
94 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
95 else:
96 bld(features="subst",
97 name="doxygen-conf",
98 source=["docs/doxygen.conf.in",
99 "docs/named_data_theme/named_data_footer-with-analytics.html.in"],
100 target=["docs/doxygen.conf",
101 "docs/named_data_theme/named_data_footer-with-analytics.html"],
102 VERSION=VERSION,
103 HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \
104 if os.getenv('GOOGLE_ANALYTICS', None) \
105 else "../docs/named_data_theme/named_data_footer.html",
106 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""),
107 )
108
109 bld(features="doxygen",
110 doxyfile='docs/doxygen.conf',
111 use="doxygen-conf")
112
113def sphinx(bld):
114 version(bld)
115
116 if not bld.env.SPHINX_BUILD:
117 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
118 else:
119 bld(features="sphinx",
120 outdir="docs",
121 source=bld.path.ant_glob("docs/**/*.rst"),
122 config="docs/conf.py",
123 VERSION=VERSION)
124
125def version(ctx):
126 if getattr(Context.g_module, 'VERSION_BASE', None):
127 return
128
129 Context.g_module.VERSION_BASE = Context.g_module.VERSION
130 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
131
132 try:
133 cmd = ['git', 'describe', '--match', 'nTorrent-*']
134 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
135 stderr=None, stdin=None)
136 out = p.communicate()[0].strip()
137 if p.returncode == 0 and out != "":
138 Context.g_module.VERSION = out[11:]
139 except:
140 pass