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