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