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