blob: 0021e4118207a22671c0073b25368cadc8e0342d [file] [log] [blame]
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Zhenkai Zhub9f02082013-03-14 12:45:15 -07002VERSION='0.4'
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08003APPNAME='chronoshare'
4
Alexander Afanasyeve8496a32013-03-03 16:10:43 -08005from waflib import Build, Logs, Utils, Task, TaskGen, Configure
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08006
7def 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''')
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080010 opt.add_option('--yes',action='store_true',default=False) # for autoconf/automake/make compatibility
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080011 opt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx logging support''')
Alexander Afanasyev5f9d09e2012-12-28 19:43:08 -080012
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080013 if Utils.unversioned_sys_platform () == "darwin":
Zhenkai Zhubb170d42013-02-25 13:48:59 -080014 opt.add_option('--auto-update', action='store_true',default=False,dest='autoupdate',help='''(OSX) Download sparkle framework and enable autoupdate feature''')
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080015
Alexander Afanasyev0b38ad02013-03-19 13:42:22 -070016 opt.load('compiler_c compiler_cxx boost ccnx protoc qt4 gnu_dirs')
Zhenkai Zhu3457ed42013-03-12 15:15:21 -070017 opt.load('tinyxml', tooldir=['waf-tools'])
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080018
19def configure(conf):
Alexander Afanasyev0b38ad02013-03-19 13:42:22 -070020 conf.load("compiler_c compiler_cxx gnu_dirs")
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080021
Alexander Afanasyeve8496a32013-03-03 16:10:43 -080022 if conf.options.debug:
23 conf.define ('_DEBUG', 1)
24 conf.add_supported_cxxflags (cxxflags = ['-O0',
25 '-Wall',
26 '-Wno-unused-variable',
27 '-g3',
28 '-Wno-unused-private-field', # only clang supports
29 '-fcolor-diagnostics', # only clang supports
30 '-Qunused-arguments' # only clang supports
31 ])
32 else:
Alexander Afanasyevd985a852013-03-04 10:34:33 -080033 conf.add_supported_cxxflags (cxxflags = ['-O3', '-g'])
Alexander Afanasyeve8496a32013-03-03 16:10:43 -080034
Alexander Afanasyeva1b7bb52013-02-26 17:04:02 -080035 # I wish I could use it, but there is some weirdness with boost tests. Give up for now
36 # try:
37 # conf.check(features='cxx cxxprogram', cxxflags="-std=c++11")
38 # conf.env.append_value ('CXXFLAGS', ["-std=c++11"])
39 # except:
40 # try:
41 # conf.check(features='cxx cxxprogram', cxxflags="-std=c++0x")
42 # conf.env.append_value ('CXXFLAGS', ["-std=c++0x"])
43 # except:
44 # conf.fatal ("You compiler doesn't support C++11. You can try GCC >= 4.4 or recent version of Clang.")
45
Alexander Afanasyevf2890632013-01-02 13:40:02 -080046 conf.define ("CHRONOSHARE_VERSION", VERSION)
47
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080048 conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3', mandatory=True)
Zhenkai Zhubc2f6282013-01-08 16:40:58 -080049 conf.check_cfg(package='libevent', args=['--cflags', '--libs'], uselib_store='LIBEVENT', mandatory=True)
50 conf.check_cfg(package='libevent_pthreads', args=['--cflags', '--libs'], uselib_store='LIBEVENT_PTHREADS', mandatory=True)
Zhenkai Zhu3457ed42013-03-12 15:15:21 -070051 conf.load('tinyxml')
52 conf.check_tinyxml(path=conf.options.tinyxml_dir)
Zhenkai Zhubc2f6282013-01-08 16:40:58 -080053
Alexander Afanasyevcf771142013-03-19 11:15:27 -070054 conf.define ("TRAY_ICON", "chronoshare-big.png")
55 if Utils.unversioned_sys_platform () == "linux":
56 conf.define ("TRAY_ICON", "chronoshare-ubuntu.png")
57
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080058 if Utils.unversioned_sys_platform () == "darwin":
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080059 conf.check_cxx(framework_name='Foundation', uselib_store='OSX_FOUNDATION', mandatory=False, compile_filename='test.mm')
Alexander Afanasyeve8496a32013-03-03 16:10:43 -080060 conf.check_cxx(framework_name='AppKit', uselib_store='OSX_APPKIT', mandatory=False, compile_filename='test.mm')
61 conf.check_cxx(framework_name='CoreWLAN', uselib_store='OSX_COREWLAN', define_name='HAVE_COREWLAN',
62 use="OSX_FOUNDATION", mandatory=False, compile_filename='test.mm')
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080063
64 if conf.options.autoupdate:
Zhenkai Zhubb170d42013-02-25 13:48:59 -080065 def check_sparkle(**kwargs):
Alexander Afanasyeve8496a32013-03-03 16:10:43 -080066 conf.check_cxx (framework_name="Sparkle", header_name=["Foundation/Foundation.h", "AppKit/AppKit.h"],
Zhenkai Zhubb170d42013-02-25 13:48:59 -080067 uselib_store='OSX_SPARKLE', define_name='HAVE_SPARKLE', mandatory=True,
Alexander Afanasyeve8496a32013-03-03 16:10:43 -080068 compile_filename='test.mm', use="OSX_FOUNDATION OSX_APPKIT",
Zhenkai Zhubb170d42013-02-25 13:48:59 -080069 **kwargs
70 )
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080071 try:
72 # Try standard paths first
Zhenkai Zhubb170d42013-02-25 13:48:59 -080073 check_sparkle()
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080074 except:
75 try:
76 # Try local path
77 Logs.info ("Check local version of Sparkle framework")
Alexander Afanasyev7c85d572013-02-26 22:06:54 -080078 check_sparkle(cxxflags="-F%s/osx/Frameworks/" % conf.path.abspath(),
79 linkflags="-F%s/osx/Frameworks/" % conf.path.abspath())
80 conf.env.HAVE_LOCAL_SPARKLE = 1
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080081 except:
Alexander Afanasyeva1b7bb52013-02-26 17:04:02 -080082 import urllib, subprocess, os, shutil
Alexander Afanasyeve8496a32013-03-03 16:10:43 -080083 if not os.path.exists('osx/Frameworks/Sparkle.framework'):
84 # Download to local path and retry
85 Logs.info ("Sparkle framework not found, trying to download it to 'build/'")
Alexander Afanasyeva1b7bb52013-02-26 17:04:02 -080086
Alexander Afanasyeve8496a32013-03-03 16:10:43 -080087 urllib.urlretrieve ("http://sparkle.andymatuschak.org/files/Sparkle%201.5b6.zip", "build/Sparkle.zip")
88 if os.path.exists('build/Sparkle.zip'):
89 try:
90 subprocess.check_call (['unzip', '-qq', 'build/Sparkle.zip', '-d', 'build/Sparkle'])
91 os.remove ("build/Sparkle.zip")
92 if not os.path.exists("osx/Frameworks"):
93 os.mkdir ("osx/Frameworks")
94 os.rename ("build/Sparkle/Sparkle.framework", "osx/Frameworks/Sparkle.framework")
95 shutil.rmtree("build/Sparkle", ignore_errors=True)
96
97 check_sparkle(cxxflags="-F%s/osx/Frameworks/" % conf.path.abspath(),
98 linkflags="-F%s/osx/Frameworks/" % conf.path.abspath())
99 conf.env.HAVE_LOCAL_SPARKLE = 1
100 except subprocess.CalledProcessError as e:
101 conf.fatal("Cannot find Sparkle framework. Auto download failed: '%s' returned %s" % (' '.join(e.cmd), e.returncode))
102 except:
103 conf.fatal("Unknown Error happened when auto downloading Sparkle framework")
Alexander Afanasyev5a95a252013-02-25 12:55:48 -0800104
Alexander Afanasyev5a95a252013-02-25 12:55:48 -0800105 if conf.is_defined('HAVE_SPARKLE'):
106 conf.env.HAVE_SPARKLE = 1 # small cheat for wscript
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800107
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800108 if not conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='SSL', mandatory=False):
Alexander Afanasyev5f9d09e2012-12-28 19:43:08 -0800109 libcrypto = conf.check_cc(lib='crypto',
110 header_name='openssl/crypto.h',
111 define_name='HAVE_SSL',
112 uselib_store='SSL')
113 else:
114 conf.define ("HAVE_SSL", 1)
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800115 if not conf.get_define ("HAVE_SSL"):
116 conf.fatal ("Cannot find SSL libraries")
117
Alexander Afanasyevc507ac22013-01-21 16:01:58 -0800118 if conf.options.log4cxx:
119 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
120 conf.define ("HAVE_LOG4CXX", 1)
121
Zhenkai Zhu0a17aea2012-12-28 14:30:22 -0800122 conf.load ('ccnx')
Alexander Afanasyev33206982013-01-09 16:29:29 -0800123
124 conf.load('protoc')
Alexander Afanasyev33206982013-01-09 16:29:29 -0800125
126 conf.load('qt4')
127
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800128 conf.load('boost')
129
Alexander Afanasyeve1c95042013-02-27 01:02:36 -0800130 conf.check_boost(lib='system test iostreams filesystem regex thread date_time')
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800131
Alexander Afanasyev71b43e72012-12-27 01:03:43 -0800132 boost_version = conf.env.BOOST_VERSION.split('_')
133 if int(boost_version[0]) < 1 or int(boost_version[1]) < 46:
134 Logs.error ("Minumum required boost version is 1.46")
135 return
136
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800137 conf.check_ccnx (path=conf.options.ccnx_dir)
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800138 conf.define ('CCNX_PATH', conf.env.CCNX_ROOT)
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800139
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800140 if conf.options._test:
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -0800141 conf.define ('_TESTS', 1)
Alexander Afanasyev72ac2192013-01-03 19:33:43 -0800142 conf.env.TEST = 1
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800143
Alexander Afanasyev71b43e72012-12-27 01:03:43 -0800144 conf.write_config_header('src/config.h')
145
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800146def build (bld):
Zhenkai Zhue8409422013-01-28 12:52:17 -0800147 executor = bld.objects (
148 target = "executor",
149 features = ["cxx"],
150 source = bld.path.ant_glob(['executor/**/*.cc']),
151 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX',
152 includes = "executor src",
153 )
154
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800155 scheduler = bld.objects (
156 target = "scheduler",
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800157 features = ["cxx"],
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800158 source = bld.path.ant_glob(['scheduler/**/*.cc']),
Zhenkai Zhue8409422013-01-28 12:52:17 -0800159 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX executor',
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800160 includes = "scheduler executor src",
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800161 )
162
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800163 libccnx = bld (
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800164 target="ccnx",
165 features=['cxx'],
166 source = bld.path.ant_glob(['ccnx/**/*.cc', 'ccnx/**/*.cpp']),
Zhenkai Zhu3457ed42013-03-12 15:15:21 -0700167 use = 'TINYXML BOOST BOOST_THREAD SSL CCNX LOG4CXX scheduler executor',
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800168 includes = "ccnx src scheduler executor",
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800169 )
170
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800171 adhoc = bld (
172 target = "adhoc",
173 features=['cxx'],
174 includes = "ccnx src",
175 )
176 if Utils.unversioned_sys_platform () == "darwin":
177 adhoc.mac_app = True
178 adhoc.source = 'adhoc/adhoc-osx.mm'
Alexander Afanasyev02a86ec2013-03-04 13:09:31 -0800179 adhoc.use = "BOOST BOOST_THREAD BOOST_DATE_TIME LOG4CXX OSX_FOUNDATION OSX_COREWLAN"
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800180
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800181 chornoshare = bld (
182 target="chronoshare",
183 features=['cxx'],
184 source = bld.path.ant_glob(['src/**/*.cc', 'src/**/*.cpp', 'src/**/*.proto']),
Alexander Afanasyeve1c95042013-02-27 01:02:36 -0800185 use = "BOOST BOOST_FILESYSTEM BOOST_DATE_TIME SQLITE3 LOG4CXX scheduler ccnx",
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800186 includes = "ccnx scheduler src executor",
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800187 )
Alexander Afanasyevb2fe74e2013-01-20 16:06:43 -0800188
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800189 fs_watcher = bld (
190 target = "fs_watcher",
191 features = "qt4 cxx",
192 defines = "WAF",
193 source = bld.path.ant_glob(['fs-watcher/*.cc']),
194 use = "SQLITE3 LOG4CXX scheduler executor QTCORE",
Zhenkai Zhu9dd9adc2013-03-13 16:12:09 -0700195 includes = "fs-watcher scheduler executor src ccnx",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800196 )
197
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800198 # Unit tests
199 if bld.env['TEST']:
200 unittests = bld.program (
201 target="unit-tests",
Zhenkai Zhud1756272013-02-01 17:02:18 -0800202 features = "qt4 cxx cxxprogram",
203 defines = "WAF",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800204 source = bld.path.ant_glob(['test/*.cc']),
Alexander Afanasyeve1c95042013-02-27 01:02:36 -0800205 use = 'BOOST_TEST BOOST_FILESYSTEM BOOST_DATE_TIME LOG4CXX SQLITE3 QTCORE QTGUI ccnx database fs_watcher chronoshare',
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800206 includes = "ccnx scheduler src executor gui fs-watcher",
Alexander Afanasyev4f62f442013-02-07 22:36:08 -0800207 install_prefix = None,
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800208 )
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800209
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -0800210 http_server = bld (
211 target = "http_server",
Zhenkai Zhud9429222013-02-25 22:34:09 -0800212 features = "qt4 cxx",
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -0800213 source = bld.path.ant_glob(['server/*.cpp']),
Zhenkai Zhud9429222013-02-25 22:34:09 -0800214 includes = "server src .",
215 use = "BOOST QTCORE"
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -0800216 )
217
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800218 qt = bld (
219 target = "ChronoShare",
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800220 features = "qt4 cxx cxxprogram html_resources",
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800221 defines = "WAF",
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800222 source = bld.path.ant_glob(['gui/*.cpp', 'gui/*.cc', 'gui/images.qrc']),
Zhenkai Zhud9429222013-02-25 22:34:09 -0800223 includes = "ccnx scheduler executor fs-watcher gui src adhoc server . ",
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800224 use = "BOOST BOOST_FILESYSTEM BOOST_DATE_TIME SQLITE3 QTCORE QTGUI LOG4CXX fs_watcher ccnx database chronoshare http_server",
225
226 html_resources = bld.path.find_dir ("gui/html").ant_glob([
227 '**/*.js', '**/*.png', '**/*.css',
228 '**/*.html', '**/*.gif', '**/*.ico'
229 ]),
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800230 )
231
232 if Utils.unversioned_sys_platform () == "darwin":
233 app_plist = '''<?xml version="1.0" encoding="UTF-8"?>
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800234<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
235<plist version="0.9">
236<dict>
237 <key>CFBundlePackageType</key>
238 <string>APPL</string>
Zhenkai Zhud5d311a2013-03-04 15:12:46 -0800239 <key>CFBundleIconFile</key>
240 <string>chronoshare.icns</string>
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800241 <key>CFBundleGetInfoString</key>
242 <string>Created by Waf</string>
Zhenkai Zhu3857d712013-02-27 22:51:25 -0800243 <key>CFBundleIdentifier</key>
244 <string>edu.ucla.cs.irl.Chronoshare</string>
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800245 <key>CFBundleSignature</key>
246 <string>????</string>
247 <key>NOTE</key>
248 <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string>
249 <key>CFBundleExecutable</key>
250 <string>%s</string>
251 <key>LSUIElement</key>
252 <string>1</string>
Zhenkai Zhu8e3e9072013-02-28 15:40:51 -0800253 <key>SUPublicDSAKeyFile</key>
254 <string>dsa_pub.pem</string>
Zhenkai Zhud5d311a2013-03-04 15:12:46 -0800255 <key>CFBundleIconFile</key>
256 <string>chronoshare.icns</string>
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800257</dict>
258</plist>'''
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800259 qt.mac_app = "ChronoShare.app"
260 qt.mac_plist = app_plist % "ChronoShare"
Zhenkai Zhud5d311a2013-03-04 15:12:46 -0800261 qt.mac_resources = 'chronoshare.icns'
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800262 qt.use += " OSX_FOUNDATION OSX_COREWLAN adhoc"
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800263
Alexander Afanasyev5a95a252013-02-25 12:55:48 -0800264 if bld.env['HAVE_SPARKLE']:
265 qt.use += " OSX_SPARKLE"
266 qt.source += ["osx/auto-update/sparkle-auto-update.mm"]
267 qt.includes += " osx/auto-update"
Alexander Afanasyev7c85d572013-02-26 22:06:54 -0800268 if bld.env['HAVE_LOCAL_SPARKLE']:
269 qt.mac_frameworks = "osx/Frameworks/Sparkle.framework"
Alexander Afanasyev548d38d2013-01-26 16:36:06 -0800270
Alexander Afanasyev0b38ad02013-03-19 13:42:22 -0700271 if Utils.unversioned_sys_platform () == "linux":
272 bld (
273 features = "process_in",
274 target = "ChronoShare.desktop",
275 source = "ChronoShare.desktop.in",
276 install_prefix = "${DATADIR}/applications",
277 )
278 bld.install_files ("${DATADIR}/applications", "ChronoShare.desktop")
279 bld.install_files ("${DATADIR}/ChronoShare", "gui/images/chronoshare-big.png")
280
Alexander Afanasyev548d38d2013-01-26 16:36:06 -0800281 cmdline = bld (
282 target = "csd",
283 features = "qt4 cxx cxxprogram",
284 defines = "WAF",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800285 source = "cmd/csd.cc",
286 includes = "ccnx scheduler executor gui fs-watcher src . ",
Alexander Afanasyeve1c95042013-02-27 01:02:36 -0800287 use = "BOOST BOOST_FILESYSTEM BOOST_DATE_TIME SQLITE3 QTCORE QTGUI LOG4CXX fs_watcher ccnx database chronoshare"
Alexander Afanasyev548d38d2013-01-26 16:36:06 -0800288 )
289
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800290 dump_db = bld (
291 target = "dump-db",
292 features = "cxx cxxprogram",
293 source = "cmd/dump-db.cc",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800294 includes = "ccnx scheduler executor gui fs-watcher src . ",
Alexander Afanasyeve1c95042013-02-27 01:02:36 -0800295 use = "BOOST BOOST_FILESYSTEM BOOST_DATE_TIME SQLITE3 QTCORE LOG4CXX fs_watcher ccnx database chronoshare"
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800296 )
297
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800298from waflib import TaskGen
299@TaskGen.extension('.mm')
300def m_hook(self, node):
301 """Alias .mm files to be compiled the same as .cc files, gcc/clang will do the right thing."""
302 return self.create_compiled_task('cxx', node)
Zhenkai Zhu6b53f932013-03-02 20:46:02 -0800303
Alexander Afanasyev0b38ad02013-03-19 13:42:22 -0700304@TaskGen.extension('.js', '.png', '.css', '.html', '.gif', '.ico', '.in')
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800305def sig_hook(self, node):
306 node.sig=Utils.h_file (node.abspath())
Zhenkai Zhu6b53f932013-03-02 20:46:02 -0800307
Alexander Afanasyev0b38ad02013-03-19 13:42:22 -0700308@TaskGen.feature('process_in')
309@TaskGen.after_method('process_source')
310def create_process_in(self):
311 dst = self.bld.path.find_or_declare (self.target)
312 tsk = self.create_task ('process_in', self.source, dst)
313
314class process_in(Task.Task):
315 color='PINK'
316
317 def run (self):
318 self.outputs[0].write (Utils.subst_vars(self.inputs[0].read (), self.env))
319
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800320@TaskGen.feature('html_resources')
321@TaskGen.before_method('process_source')
322def create_qrc_task(self):
323 output = self.bld.path.find_or_declare ("gui/html.qrc")
324 tsk = self.create_task('html_resources', self.html_resources, output)
Alexander Afanasyev1cb641f2013-03-03 17:49:02 -0800325 tsk.base_path = output.parent.get_src ()
326 self.create_rcc_task (output.get_src ())
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800327
328class html_resources(Task.Task):
329 color='PINK'
330
331 def __str__ (self):
Alexander Afanasyev1cb641f2013-03-03 17:49:02 -0800332 return "%s: Generating %s\n" % (self.__class__.__name__.replace('_task',''), self.outputs[0].nice_path ())
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800333
334 def run (self):
335 out = self.outputs[0]
Alexander Afanasyev9cc6c212013-03-04 12:45:38 -0800336 bld_out = out.get_bld ()
337 src_out = out.get_src ()
338 bld_out.write('<RCC>\n <qresource prefix="/">\n')
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800339 for f in self.inputs:
Alexander Afanasyev9cc6c212013-03-04 12:45:38 -0800340 bld_out.write (' <file>%s</file>\n' % f.path_from (self.base_path), 'a')
341 bld_out.write(' </qresource>\n</RCC>', 'a')
Alexander Afanasyev1cb641f2013-03-03 17:49:02 -0800342
Alexander Afanasyev9cc6c212013-03-04 12:45:38 -0800343 src_out.write (bld_out.read(), 'w')
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800344 return 0
Alexander Afanasyeve8496a32013-03-03 16:10:43 -0800345
346@Configure.conf
347def add_supported_cxxflags(self, cxxflags):
348 """
349 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
350 """
351 self.start_msg('Checking allowed flags for c++ compiler')
352
353 supportedFlags = []
354 for flag in cxxflags:
355 if self.check_cxx (cxxflags=[flag], mandatory=False):
356 supportedFlags += [flag]
357
358 self.end_msg (' '.join (supportedFlags))
359 self.env.CXXFLAGS += supportedFlags