blob: ba4a4f61618b228f7929738699003a26846bc0cc [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
Mickey Sweatt617d2d42016-04-25 22:02:08 -070032 boost_libs = 'system random thread filesystem log log_setup'
spirosmastorakisa99994c2016-01-24 15:26:53 -080033 if conf.options.with_tests:
34 conf.env['WITH_TESTS'] = 1
35 conf.define('WITH_TESTS', 1);
36 boost_libs += ' unit_test_framework'
37
Mickey Sweatt617d2d42016-04-25 22:02:08 -070038 conf.check_boost(lib=boost_libs, mt=True)
spirosmastorakisa99994c2016-01-24 15:26:53 -080039 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):
spirosmastorakisa99994c2016-01-24 15:26:53 -080051 bld(
52 features='cxx',
53 name='nTorrent',
54 source=bld.path.ant_glob(['src/**/*.cpp'],
55 excl=['src/main.cpp',]),
56 use='version NDN_CXX BOOST',
57 includes='src',
58 export_includes='src',
59 )
Mickey Sweattf91ced42016-04-20 13:30:37 -070060 # main
61 bld(
62 target='ntorrent',
63 features='cxx cxxprogram',
64 source='src/main.cpp',
Mickey Sweatt617d2d42016-04-25 22:02:08 -070065 use = 'nTorrent')
spirosmastorakisa99994c2016-01-24 15:26:53 -080066
67 # Unit tests
68 if bld.env["WITH_TESTS"]:
69 unittests = bld.program (
70 target="unit-tests",
71 source = bld.path.ant_glob(['tests/**/*.cpp']),
72 features=['cxx', 'cxxprogram'],
Mickey Sweatt617d2d42016-04-25 22:02:08 -070073 use = 'nTorrent',
spirosmastorakisa99994c2016-01-24 15:26:53 -080074 includes = "src .",
75 install_path = None
76 )
77
78# docs
79def docs(bld):
80 from waflib import Options
81 Options.commands = ['doxygen', 'sphinx'] + Options.commands
82
83def doxygen(bld):
84 version(bld)
85
86 if not bld.env.DOXYGEN:
87 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
88 else:
89 bld(features="subst",
90 name="doxygen-conf",
91 source=["docs/doxygen.conf.in",
92 "docs/named_data_theme/named_data_footer-with-analytics.html.in"],
93 target=["docs/doxygen.conf",
94 "docs/named_data_theme/named_data_footer-with-analytics.html"],
95 VERSION=VERSION,
96 HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \
97 if os.getenv('GOOGLE_ANALYTICS', None) \
98 else "../docs/named_data_theme/named_data_footer.html",
99 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""),
100 )
101
102 bld(features="doxygen",
103 doxyfile='docs/doxygen.conf',
104 use="doxygen-conf")
105
106def sphinx(bld):
107 version(bld)
108
109 if not bld.env.SPHINX_BUILD:
110 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
111 else:
112 bld(features="sphinx",
113 outdir="docs",
114 source=bld.path.ant_glob("docs/**/*.rst"),
115 config="docs/conf.py",
116 VERSION=VERSION)
117
118def version(ctx):
119 if getattr(Context.g_module, 'VERSION_BASE', None):
120 return
121
122 Context.g_module.VERSION_BASE = Context.g_module.VERSION
123 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
124
125 try:
126 cmd = ['git', 'describe', '--match', 'nTorrent-*']
127 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
128 stderr=None, stdin=None)
129 out = p.communicate()[0].strip()
130 if p.returncode == 0 and out != "":
131 Context.g_module.VERSION = out[11:]
132 except:
133 pass