Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 2 | |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 3 | from waflib import Context, Logs, Utils |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 4 | import os |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 5 | |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 6 | VERSION = '0.5' |
| 7 | APPNAME = 'ChronoChat' |
| 8 | |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 9 | def options(opt): |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 10 | opt.load(['compiler_cxx', 'gnu_dirs']) |
| 11 | opt.load(['default-compiler-flags', |
| 12 | 'boost', 'qt5_custom', |
| 13 | 'doxygen', 'sphinx_build'], |
| 14 | tooldir=['.waf-tools']) |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 15 | |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 16 | optgrp = opt.add_option_group('ChronoChat Options') |
| 17 | optgrp.add_option('--with-tests', action='store_true', default=False, |
| 18 | help='Build unit tests') |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 19 | |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 20 | def configure(conf): |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 21 | conf.load(['compiler_cxx', 'gnu_dirs', |
| 22 | 'default-compiler-flags', 'boost', 'qt5_custom', |
| 23 | 'doxygen', 'sphinx_build']) |
Yingdi Yu | e370a2a | 2013-11-10 17:39:36 -0800 | [diff] [blame] | 24 | |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 25 | conf.env.WITH_TESTS = conf.options.with_tests |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 26 | |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 27 | pkg_config_path = os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR) |
| 28 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX', |
| 29 | pkg_config_path=pkg_config_path) |
| 30 | conf.check_cfg(package='ChronoSync', args=['--cflags', '--libs'], uselib_store='SYNC', |
| 31 | pkg_config_path=pkg_config_path) |
Yingdi Yu | 4390ce5 | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 33 | boost_libs = ['system', 'random', 'thread', 'filesystem'] |
| 34 | if conf.env.WITH_TESTS: |
| 35 | boost_libs.append('unit_test_framework') |
| 36 | conf.define('WITH_TESTS', 1) |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 37 | |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 38 | conf.check_boost(lib=boost_libs, mt=True) |
| 39 | if conf.env.BOOST_VERSION_NUMBER < 105800: |
| 40 | conf.fatal('The minimum supported version of Boost is 1.65.1.\n' |
| 41 | 'Please upgrade your distribution or manually install a newer version of Boost.\n' |
| 42 | 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost') |
| 43 | elif conf.env.BOOST_VERSION_NUMBER < 106501: |
| 44 | Logs.warn('WARNING: Using a version of Boost older than 1.65.1 is not officially supported and may not work.\n' |
| 45 | 'If you encounter any problems, please upgrade your distribution or manually install a newer version of Boost.\n' |
| 46 | 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost') |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 47 | |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 48 | conf.check_compiler_flags() |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 49 | conf.write_config_header('src/config.h') |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 50 | |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 51 | def build (bld): |
Varun Patil | 3d85090 | 2020-11-23 12:19:14 +0530 | [diff] [blame] | 52 | feature_list = 'qt5 cxx' |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 53 | if bld.env.WITH_TESTS: |
Qiuhan Ding | 56c0be5 | 2015-03-11 17:21:26 -0700 | [diff] [blame] | 54 | feature_list += ' cxxstlib' |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 55 | else: |
| 56 | feature_list += ' cxxprogram' |
| 57 | |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 58 | qt = bld( |
Yingdi Yu | d681e21 | 2013-11-07 11:36:50 -0800 | [diff] [blame] | 59 | target = "ChronoChat", |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 60 | features = feature_list, |
Yingdi Yu | 4212586 | 2014-08-07 17:04:28 -0700 | [diff] [blame] | 61 | defines = "WAF=1", |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 62 | source = bld.path.ant_glob(['src/*.cpp', 'src/*.ui', '*.qrc']), |
Alexander Afanasyev | 4a97931 | 2013-11-07 15:30:05 -0800 | [diff] [blame] | 63 | includes = "src .", |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 64 | use = "QT5CORE QT5GUI QT5WIDGETS QT5SQL NDN_CXX BOOST SYNC", |
Yingdi Yu | 92e8e48 | 2013-10-17 21:13:03 -0700 | [diff] [blame] | 65 | ) |
| 66 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 67 | # Unit tests |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 68 | if bld.env.WITH_TESTS: |
| 69 | unittests = bld.program( |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 70 | target="unit-tests", |
| 71 | source = bld.path.ant_glob(['test/**/*.cpp']), |
| 72 | features=['cxx', 'cxxprogram'], |
| 73 | use = 'BOOST ChronoChat', |
| 74 | includes = "src .", |
| 75 | install_path = None, |
| 76 | ) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 77 | |
| 78 | # Debug tools |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 79 | if "_DEBUG" in bld.env["DEFINES"]: |
| 80 | for app in bld.path.ant_glob('debug-tools/*.cpp'): |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 81 | bld(features=['cxx', 'cxxprogram'], |
Varun Patil | a24bd3e | 2020-11-24 10:08:33 +0530 | [diff] [blame] | 82 | target = '%s' % (str(app.change_ext('','.cpp'))), |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 83 | source = app, |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 84 | use = 'NDN_CXX', |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 85 | includes = "src .", |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 86 | install_path = None, |
| 87 | ) |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 88 | |
Davide Pesavento | 7676b56 | 2020-12-14 00:41:26 -0500 | [diff] [blame^] | 89 | if not bld.env.WITH_TESTS: |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 90 | if Utils.unversioned_sys_platform () == "darwin": |
| 91 | app_plist = '''<?xml version="1.0" encoding="UTF-8"?> |
Yingdi Yu | b6fb030 | 2014-01-21 11:05:11 -0800 | [diff] [blame] | 92 | <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> |
| 93 | <plist version="0.9"> |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 94 | <dict> |
| 95 | <key>CFBundlePackageType</key> |
| 96 | <string>APPL</string> |
| 97 | <key>CFBundleIconFile</key> |
| 98 | <string>demo.icns</string> |
| 99 | <key>CFBundleGetInfoString</key> |
| 100 | <string>Created by Waf</string> |
| 101 | <key>CFBundleIdentifier</key> |
| 102 | <string>edu.ucla.cs.irl.ChronoChat</string> |
| 103 | <key>CFBundleSignature</key> |
| 104 | <string>????</string> |
| 105 | <key>NOTE</key> |
| 106 | <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string> |
| 107 | <key>CFBundleExecutable</key> |
| 108 | <string>%s</string> |
| 109 | <key>SUPublicDSAKeyFile</key> |
| 110 | <string>dsa_pub.pem</string> |
| 111 | <key>CFBundleIconFile</key> |
| 112 | <string>demo.icns</string> |
| 113 | </dict> |
Yingdi Yu | b6fb030 | 2014-01-21 11:05:11 -0800 | [diff] [blame] | 114 | </plist>''' |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 115 | |
Yingdi Yu | b6fb030 | 2014-01-21 11:05:11 -0800 | [diff] [blame] | 116 | # <key>LSUIElement</key> |
| 117 | # <string>1</string> |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 118 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 119 | qt.mac_app = "ChronoChat.app" |
| 120 | qt.mac_plist = app_plist % "ChronoChat" |
| 121 | qt.mac_resources = 'demo.icns' |
| 122 | else: |
| 123 | bld(features = "subst", |
| 124 | source = 'linux/chronochat.desktop.in', |
| 125 | target = 'linux/chronochat.desktop', |
| 126 | BINARY = "ChronoChat", |
| 127 | install_path = "${DATAROOTDIR}/applications" |
| 128 | ) |
| 129 | bld.install_files("${DATAROOTDIR}/chronochat", |
| 130 | bld.path.ant_glob(['linux/Resources/*'])) |
| 131 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 132 | def docs(bld): |
| 133 | from waflib import Options |
| 134 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 135 | |
| 136 | def doxygen(bld): |
| 137 | version(bld) |
| 138 | |
| 139 | if not bld.env.DOXYGEN: |
| 140 | Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
Yingdi Yu | b6fb030 | 2014-01-21 11:05:11 -0800 | [diff] [blame] | 141 | else: |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 142 | bld(features="subst", |
| 143 | name="doxygen-conf", |
| 144 | source=["docs/doxygen.conf.in", |
| 145 | "docs/named_data_theme/named_data_footer-with-analytics.html.in"], |
| 146 | target=["docs/doxygen.conf", |
| 147 | "docs/named_data_theme/named_data_footer-with-analytics.html"], |
| 148 | VERSION=VERSION, |
| 149 | HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \ |
| 150 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 151 | else "../docs/named_data_theme/named_data_footer.html", |
| 152 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""), |
Yingdi Yu | b6fb030 | 2014-01-21 11:05:11 -0800 | [diff] [blame] | 153 | ) |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 154 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 155 | bld(features="doxygen", |
| 156 | doxyfile='docs/doxygen.conf', |
| 157 | use="doxygen-conf") |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 158 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 159 | def sphinx(bld): |
| 160 | version(bld) |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 161 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 162 | if not bld.env.SPHINX_BUILD: |
| 163 | bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)") |
| 164 | else: |
| 165 | bld(features="sphinx", |
| 166 | outdir="docs", |
| 167 | source=bld.path.ant_glob("docs/**/*.rst"), |
| 168 | config="docs/conf.py", |
| 169 | VERSION=VERSION) |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 170 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 171 | def version(ctx): |
| 172 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 173 | return |
| 174 | |
| 175 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 176 | Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')] |
| 177 | |
| 178 | try: |
| 179 | cmd = ['git', 'describe', '--match', 'ChronoChat-*'] |
| 180 | p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE, |
| 181 | stderr=None, stdin=None) |
| 182 | out = p.communicate()[0].strip() |
| 183 | if p.returncode == 0 and out != "": |
| 184 | Context.g_module.VERSION = out[11:] |
| 185 | except: |
| 186 | pass |