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