spirosmastorakis | a99994c | 2016-01-24 15:26:53 -0800 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | VERSION='0.1.0' |
| 3 | APPNAME='nTorrent' |
| 4 | |
| 5 | from waflib import Configure, Utils, Logs, Context |
| 6 | import os |
| 7 | |
| 8 | def options(opt): |
| 9 | |
| 10 | opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) |
| 11 | |
spirosmastorakis | 15ebb1e | 2016-01-25 21:20:25 -0800 | [diff] [blame] | 12 | opt.load(['default-compiler-flags', 'coverage', 'boost', |
spirosmastorakis | a99994c | 2016-01-24 15:26:53 -0800 | [diff] [blame] | 13 | '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 | |
| 21 | def 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 Sweatt | 617d2d4 | 2016-04-25 22:02:08 -0700 | [diff] [blame^] | 32 | boost_libs = 'system random thread filesystem log log_setup' |
spirosmastorakis | a99994c | 2016-01-24 15:26:53 -0800 | [diff] [blame] | 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 | |
Mickey Sweatt | 617d2d4 | 2016-04-25 22:02:08 -0700 | [diff] [blame^] | 38 | conf.check_boost(lib=boost_libs, mt=True) |
spirosmastorakis | a99994c | 2016-01-24 15:26:53 -0800 | [diff] [blame] | 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 | |
spirosmastorakis | 15ebb1e | 2016-01-25 21:20:25 -0800 | [diff] [blame] | 45 | # Loading "late" to prevent tests to be compiled with profiling flags |
| 46 | conf.load('coverage') |
| 47 | |
spirosmastorakis | a99994c | 2016-01-24 15:26:53 -0800 | [diff] [blame] | 48 | conf.write_config_header('src/config.h') |
| 49 | |
| 50 | def build (bld): |
spirosmastorakis | a99994c | 2016-01-24 15:26:53 -0800 | [diff] [blame] | 51 | 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 Sweatt | f91ced4 | 2016-04-20 13:30:37 -0700 | [diff] [blame] | 60 | # main |
| 61 | bld( |
| 62 | target='ntorrent', |
| 63 | features='cxx cxxprogram', |
| 64 | source='src/main.cpp', |
Mickey Sweatt | 617d2d4 | 2016-04-25 22:02:08 -0700 | [diff] [blame^] | 65 | use = 'nTorrent') |
spirosmastorakis | a99994c | 2016-01-24 15:26:53 -0800 | [diff] [blame] | 66 | |
| 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 Sweatt | 617d2d4 | 2016-04-25 22:02:08 -0700 | [diff] [blame^] | 73 | use = 'nTorrent', |
spirosmastorakis | a99994c | 2016-01-24 15:26:53 -0800 | [diff] [blame] | 74 | includes = "src .", |
| 75 | install_path = None |
| 76 | ) |
| 77 | |
| 78 | # docs |
| 79 | def docs(bld): |
| 80 | from waflib import Options |
| 81 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 82 | |
| 83 | def 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 | |
| 106 | def 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 | |
| 118 | def 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 |