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; -*- |
| 2 | VERSION='0.3' |
| 3 | APPNAME='ChronoChat' |
| 4 | |
| 5 | from waflib import Build, Logs, Utils, Task, TaskGen, Configure |
| 6 | |
| 7 | def options(opt): |
Alexander Afanasyev | 69b0d20 | 2013-07-14 11:47:23 -0700 | [diff] [blame] | 8 | grp = opt.add_option_group ("ChronoChat Options") |
| 9 | grp.add_option('--debug',action='store_true',default=False,dest='debug',help='''debugging mode''') |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 10 | # opt.add_option('--test', action='store_true',default=False,dest='_test',help='''build unit tests''') |
| 11 | # opt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx logging support''') |
| 12 | |
| 13 | # if Utils.unversioned_sys_platform () == "darwin": |
| 14 | # opt.add_option('--auto-update', action='store_true',default=False,dest='autoupdate',help='''(OSX) Download sparkle framework and enable autoupdate feature''') |
| 15 | |
| 16 | opt.load('compiler_c compiler_cxx boost protoc qt4') |
| 17 | |
| 18 | def configure(conf): |
| 19 | conf.load("compiler_c compiler_cxx") |
| 20 | |
| 21 | if conf.options.debug: |
| 22 | conf.define ('_DEBUG', 1) |
| 23 | conf.add_supported_cxxflags (cxxflags = ['-O0', |
| 24 | '-Wall', |
| 25 | '-Wno-unused-variable', |
| 26 | '-g3', |
| 27 | '-Wno-unused-private-field', # only clang supports |
| 28 | '-fcolor-diagnostics', # only clang supports |
| 29 | '-Qunused-arguments' # only clang supports |
| 30 | ]) |
| 31 | else: |
| 32 | conf.add_supported_cxxflags (cxxflags = ['-O3', '-g']) |
| 33 | |
Alexander Afanasyev | ba87ea3 | 2013-07-14 12:27:03 -0700 | [diff] [blame^] | 34 | conf.check_cfg (package='ChronoSync', |
| 35 | args=['ChronoSync >= 0.1', '--cflags', '--libs'], |
| 36 | uselib_store='SYNC', mandatory=True) |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 37 | |
| 38 | conf.define ("CHRONOCHAT_VERSION", VERSION) |
| 39 | |
| 40 | # if Utils.unversioned_sys_platform () == "darwin": |
| 41 | # conf.check_cxx(framework_name='Foundation', uselib_store='OSX_FOUNDATION', mandatory=False, compile_filename='test.mm') |
| 42 | # conf.check_cxx(framework_name='AppKit', uselib_store='OSX_APPKIT', mandatory=False, compile_filename='test.mm') |
| 43 | # conf.check_cxx(framework_name='CoreWLAN', uselib_store='OSX_COREWLAN', define_name='HAVE_COREWLAN', |
| 44 | # use="OSX_FOUNDATION", mandatory=False, compile_filename='test.mm') |
| 45 | |
| 46 | # if conf.options.autoupdate: |
| 47 | # def check_sparkle(**kwargs): |
| 48 | # conf.check_cxx (framework_name="Sparkle", header_name=["Foundation/Foundation.h", "AppKit/AppKit.h"], |
| 49 | # uselib_store='OSX_SPARKLE', define_name='HAVE_SPARKLE', mandatory=True, |
| 50 | # compile_filename='test.mm', use="OSX_FOUNDATION OSX_APPKIT", |
| 51 | # **kwargs |
| 52 | # ) |
| 53 | # try: |
| 54 | # # Try standard paths first |
| 55 | # check_sparkle() |
| 56 | # except: |
| 57 | # try: |
| 58 | # # Try local path |
| 59 | # Logs.info ("Check local version of Sparkle framework") |
| 60 | # check_sparkle(cxxflags="-F%s/osx/Frameworks/" % conf.path.abspath(), |
| 61 | # linkflags="-F%s/osx/Frameworks/" % conf.path.abspath()) |
| 62 | # conf.env.HAVE_LOCAL_SPARKLE = 1 |
| 63 | # except: |
| 64 | # import urllib, subprocess, os, shutil |
| 65 | # if not os.path.exists('osx/Frameworks/Sparkle.framework'): |
| 66 | # # Download to local path and retry |
| 67 | # Logs.info ("Sparkle framework not found, trying to download it to 'build/'") |
| 68 | |
| 69 | # urllib.urlretrieve ("http://sparkle.andymatuschak.org/files/Sparkle%201.5b6.zip", "build/Sparkle.zip") |
| 70 | # if os.path.exists('build/Sparkle.zip'): |
| 71 | # try: |
| 72 | # subprocess.check_call (['unzip', '-qq', 'build/Sparkle.zip', '-d', 'build/Sparkle']) |
| 73 | # os.remove ("build/Sparkle.zip") |
| 74 | # if not os.path.exists("osx/Frameworks"): |
| 75 | # os.mkdir ("osx/Frameworks") |
| 76 | # os.rename ("build/Sparkle/Sparkle.framework", "osx/Frameworks/Sparkle.framework") |
| 77 | # shutil.rmtree("build/Sparkle", ignore_errors=True) |
| 78 | |
| 79 | # check_sparkle(cxxflags="-F%s/osx/Frameworks/" % conf.path.abspath(), |
| 80 | # linkflags="-F%s/osx/Frameworks/" % conf.path.abspath()) |
| 81 | # conf.env.HAVE_LOCAL_SPARKLE = 1 |
| 82 | # except subprocess.CalledProcessError as e: |
| 83 | # conf.fatal("Cannot find Sparkle framework. Auto download failed: '%s' returned %s" % (' '.join(e.cmd), e.returncode)) |
| 84 | # except: |
| 85 | # conf.fatal("Unknown Error happened when auto downloading Sparkle framework") |
| 86 | |
| 87 | # if conf.is_defined('HAVE_SPARKLE'): |
| 88 | # conf.env.HAVE_SPARKLE = 1 # small cheat for wscript |
| 89 | |
| 90 | # if conf.options.log4cxx: |
| 91 | # conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True) |
| 92 | # conf.define ("HAVE_LOG4CXX", 1) |
| 93 | |
| 94 | conf.load('protoc') |
| 95 | |
| 96 | conf.load('qt4') |
| 97 | |
| 98 | conf.load('boost') |
| 99 | |
Alexander Afanasyev | 86d6fa8 | 2013-07-13 16:00:22 -0700 | [diff] [blame] | 100 | conf.check_boost(lib='system random') |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 101 | |
| 102 | boost_version = conf.env.BOOST_VERSION.split('_') |
Alexander Afanasyev | 86d6fa8 | 2013-07-13 16:00:22 -0700 | [diff] [blame] | 103 | if int(boost_version[0]) < 1 or int(boost_version[1]) < 48: |
| 104 | Logs.error ("Minumum required boost version is 1.48") |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 105 | return |
| 106 | |
| 107 | # if conf.options._test: |
| 108 | # conf.define ('_TESTS', 1) |
| 109 | # conf.env.TEST = 1 |
| 110 | |
| 111 | conf.write_config_header('config.h') |
| 112 | |
| 113 | def build (bld): |
| 114 | # # Unit tests |
| 115 | # if bld.env['TEST']: |
| 116 | # unittests = bld.program ( |
| 117 | # target="unit-tests", |
| 118 | # features = "qt4 cxx cxxprogram", |
| 119 | # defines = "WAF", |
| 120 | # source = bld.path.ant_glob(['test/*.cc']), |
| 121 | # use = 'BOOST_TEST BOOST_FILESYSTEM BOOST_DATE_TIME LOG4CXX SQLITE3 QTCORE QTGUI ccnx database fs_watcher chronoshare', |
| 122 | # includes = "ccnx scheduler src executor gui fs-watcher", |
| 123 | # install_prefix = None, |
| 124 | # ) |
| 125 | |
| 126 | qt = bld ( |
| 127 | target = "ChronoChat", |
| 128 | features = "qt4 cxx cxxprogram", |
| 129 | defines = "WAF", |
| 130 | source = bld.path.ant_glob(['*.cpp', '*.ui', 'demo.qrc', '*.proto']), |
| 131 | includes = " . ", |
Alexander Afanasyev | 86d6fa8 | 2013-07-13 16:00:22 -0700 | [diff] [blame] | 132 | use = "BOOST BOOST_THREAD QTCORE QTGUI SYNC", |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 133 | ) |
| 134 | |
| 135 | if Utils.unversioned_sys_platform () == "darwin": |
| 136 | app_plist = '''<?xml version="1.0" encoding="UTF-8"?> |
| 137 | <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> |
| 138 | <plist version="0.9"> |
| 139 | <dict> |
| 140 | <key>CFBundlePackageType</key> |
| 141 | <string>APPL</string> |
| 142 | <key>CFBundleIconFile</key> |
| 143 | <string>demo.icns</string> |
| 144 | <key>CFBundleGetInfoString</key> |
| 145 | <string>Created by Waf</string> |
| 146 | <key>CFBundleIdentifier</key> |
| 147 | <string>edu.ucla.cs.irl.ChronoChat</string> |
| 148 | <key>CFBundleSignature</key> |
| 149 | <string>????</string> |
| 150 | <key>NOTE</key> |
| 151 | <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string> |
| 152 | <key>CFBundleExecutable</key> |
| 153 | <string>%s</string> |
Alexander Afanasyev | d6d12f1 | 2013-07-13 15:07:08 -0700 | [diff] [blame] | 154 | <key>LSUIElement</key> |
| 155 | <string>1</string> |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 156 | <key>SUPublicDSAKeyFile</key> |
| 157 | <string>dsa_pub.pem</string> |
| 158 | <key>CFBundleIconFile</key> |
| 159 | <string>demo.icns</string> |
| 160 | </dict> |
| 161 | </plist>''' |
| 162 | |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 163 | qt.mac_app = "ChronoChat.app" |
| 164 | qt.mac_plist = app_plist % "ChronoChat" |
| 165 | qt.mac_resources = 'demo.icns' |
| 166 | # qt.use += " OSX_FOUNDATION OSX_COREWLAN adhoc" |
| 167 | |
| 168 | # if bld.env['HAVE_SPARKLE']: |
| 169 | # qt.use += " OSX_SPARKLE" |
| 170 | # qt.source += ["osx/auto-update/sparkle-auto-update.mm"] |
| 171 | # qt.includes += " osx/auto-update" |
| 172 | # if bld.env['HAVE_LOCAL_SPARKLE']: |
| 173 | # qt.mac_frameworks = "osx/Frameworks/Sparkle.framework" |
| 174 | |
| 175 | from waflib import TaskGen |
| 176 | @TaskGen.extension('.mm') |
| 177 | def m_hook(self, node): |
| 178 | """Alias .mm files to be compiled the same as .cc files, gcc/clang will do the right thing.""" |
| 179 | return self.create_compiled_task('cxx', node) |
| 180 | |
| 181 | @Configure.conf |
| 182 | def add_supported_cxxflags(self, cxxflags): |
| 183 | """ |
| 184 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 185 | """ |
| 186 | self.start_msg('Checking allowed flags for c++ compiler') |
| 187 | |
| 188 | supportedFlags = [] |
| 189 | for flag in cxxflags: |
| 190 | if self.check_cxx (cxxflags=[flag], mandatory=False): |
| 191 | supportedFlags += [flag] |
| 192 | |
| 193 | self.end_msg (' '.join (supportedFlags)) |
| 194 | self.env.CXXFLAGS += supportedFlags |