blob: 291d83ee20199a12627b84d75417e2d571a44a95 [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 Afanasyevba87ea32013-07-14 12:27:03 -070034 conf.check_cfg (package='ChronoSync',
35 args=['ChronoSync >= 0.1', '--cflags', '--libs'],
36 uselib_store='SYNC', mandatory=True)
Alexander Afanasyevb4b92292013-07-09 13:54:59 -070037
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 Afanasyev86d6fa82013-07-13 16:00:22 -0700100 conf.check_boost(lib='system random')
Alexander Afanasyevb4b92292013-07-09 13:54:59 -0700101
102 boost_version = conf.env.BOOST_VERSION.split('_')
Alexander Afanasyev86d6fa82013-07-13 16:00:22 -0700103 if int(boost_version[0]) < 1 or int(boost_version[1]) < 48:
104 Logs.error ("Minumum required boost version is 1.48")
Alexander Afanasyevb4b92292013-07-09 13:54:59 -0700105 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
113def 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 Afanasyev86d6fa82013-07-13 16:00:22 -0700132 use = "BOOST BOOST_THREAD QTCORE QTGUI SYNC",
Alexander Afanasyevb4b92292013-07-09 13:54:59 -0700133 )
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 Afanasyevd6d12f12013-07-13 15:07:08 -0700154 <key>LSUIElement</key>
155 <string>1</string>
Alexander Afanasyevb4b92292013-07-09 13:54:59 -0700156 <key>SUPublicDSAKeyFile</key>
157 <string>dsa_pub.pem</string>
158 <key>CFBundleIconFile</key>
159 <string>demo.icns</string>
160</dict>
161</plist>'''
162
Alexander Afanasyevb4b92292013-07-09 13:54:59 -0700163 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
175from waflib import TaskGen
176@TaskGen.extension('.mm')
177def 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
182def 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