blob: b4328e72b11887ee8ea10422e69edade88ad4dc6 [file] [log] [blame]
akmhoquefa8ee9b2014-03-14 09:06:24 -05001#! /usr/bin/env python
2# encoding: utf-8
3# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
4
5try:
6 from xml.sax import make_parser
7 from xml.sax.handler import ContentHandler
8except ImportError:
9 has_xml=False
10 ContentHandler=object
11else:
12 has_xml=True
13import os,sys
14from waflib.Tools import c_preproc,cxx
15from waflib import Task,Utils,Options,Errors
16from waflib.TaskGen import feature,after_method,extension
17from waflib.Configure import conf
18from waflib import Logs
19MOC_H=['.h','.hpp','.hxx','.hh']
20EXT_RCC=['.qrc']
21EXT_UI=['.ui']
22EXT_QT4=['.cpp','.cc','.cxx','.C']
23QT4_LIBS="QtCore QtGui QtUiTools QtNetwork QtOpenGL QtSql QtSvg QtTest QtXml QtXmlPatterns QtWebKit Qt3Support QtHelp QtScript QtDeclarative QtDesigner"
24class qxx(Task.classes['cxx']):
25 def __init__(self,*k,**kw):
26 Task.Task.__init__(self,*k,**kw)
27 self.moc_done=0
28 def scan(self):
29 (nodes,names)=c_preproc.scan(self)
30 lst=[]
31 for x in nodes:
32 if x.name.endswith('.moc'):
33 s=x.path_from(self.inputs[0].parent.get_bld())
34 if s not in names:
35 names.append(s)
36 else:
37 lst.append(x)
38 return(lst,names)
39 def runnable_status(self):
40 if self.moc_done:
41 return Task.Task.runnable_status(self)
42 else:
43 for t in self.run_after:
44 if not t.hasrun:
45 return Task.ASK_LATER
46 self.add_moc_tasks()
47 return Task.Task.runnable_status(self)
48 def create_moc_task(self,h_node,m_node):
49 try:
50 moc_cache=self.generator.bld.moc_cache
51 except AttributeError:
52 moc_cache=self.generator.bld.moc_cache={}
53 try:
54 return moc_cache[h_node]
55 except KeyError:
56 tsk=moc_cache[h_node]=Task.classes['moc'](env=self.env,generator=self.generator)
57 tsk.set_inputs(h_node)
58 tsk.set_outputs(m_node)
59 gen=self.generator.bld.producer
60 gen.outstanding.insert(0,tsk)
61 gen.total+=1
62 return tsk
63 def add_moc_tasks(self):
64 node=self.inputs[0]
65 bld=self.generator.bld
66 try:
67 self.signature()
68 except KeyError:
69 pass
70 else:
71 delattr(self,'cache_sig')
72 moctasks=[]
73 mocfiles=[]
74 try:
75 tmp_lst=bld.raw_deps[self.uid()]
76 bld.raw_deps[self.uid()]=[]
77 except KeyError:
78 tmp_lst=[]
79 for d in tmp_lst:
80 if not d.endswith('.moc'):
81 continue
82 if d in mocfiles:
83 Logs.error("paranoia owns")
84 continue
85 mocfiles.append(d)
86 h_node=None
87 try:ext=Options.options.qt_header_ext.split()
88 except AttributeError:pass
89 if not ext:ext=MOC_H
90 base2=d[:-4]
91 for x in[node.parent]+self.generator.includes_nodes:
92 for e in ext:
93 h_node=x.find_node(base2+e)
94 if h_node:
95 break
96 if h_node:
97 m_node=h_node.change_ext('.moc')
98 break
99 else:
100 for k in EXT_QT4:
101 if base2.endswith(k):
102 for x in[node.parent]+self.generator.includes_nodes:
103 h_node=x.find_node(base2)
104 if h_node:
105 break
106 if h_node:
107 m_node=h_node.change_ext(k+'.moc')
108 break
109 if not h_node:
110 raise Errors.WafError('no header found for %r which is a moc file'%d)
111 bld.node_deps[(self.inputs[0].parent.abspath(),m_node.name)]=h_node
112 task=self.create_moc_task(h_node,m_node)
113 moctasks.append(task)
114 tmp_lst=bld.raw_deps[self.uid()]=mocfiles
115 lst=bld.node_deps.get(self.uid(),())
116 for d in lst:
117 name=d.name
118 if name.endswith('.moc'):
119 task=self.create_moc_task(bld.node_deps[(self.inputs[0].parent.abspath(),name)],d)
120 moctasks.append(task)
121 self.run_after.update(set(moctasks))
122 self.moc_done=1
123 run=Task.classes['cxx'].__dict__['run']
124class trans_update(Task.Task):
125 run_str='${QT_LUPDATE} ${SRC} -ts ${TGT}'
126 color='BLUE'
127Task.update_outputs(trans_update)
128class XMLHandler(ContentHandler):
129 def __init__(self):
130 self.buf=[]
131 self.files=[]
132 def startElement(self,name,attrs):
133 if name=='file':
134 self.buf=[]
135 def endElement(self,name):
136 if name=='file':
137 self.files.append(str(''.join(self.buf)))
138 def characters(self,cars):
139 self.buf.append(cars)
140@extension(*EXT_RCC)
141def create_rcc_task(self,node):
142 rcnode=node.change_ext('_rc.cpp')
143 rcctask=self.create_task('rcc',node,rcnode)
144 cpptask=self.create_task('cxx',rcnode,rcnode.change_ext('.o'))
145 try:
146 self.compiled_tasks.append(cpptask)
147 except AttributeError:
148 self.compiled_tasks=[cpptask]
149 return cpptask
150@extension(*EXT_UI)
151def create_uic_task(self,node):
152 uictask=self.create_task('ui4',node)
153 uictask.outputs=[self.path.find_or_declare(self.env['ui_PATTERN']%node.name[:-3])]
154@extension('.ts')
155def add_lang(self,node):
156 self.lang=self.to_list(getattr(self,'lang',[]))+[node]
157@feature('qt4')
158@after_method('apply_link')
159def apply_qt4(self):
160 if getattr(self,'lang',None):
161 qmtasks=[]
162 for x in self.to_list(self.lang):
163 if isinstance(x,str):
164 x=self.path.find_resource(x+'.ts')
165 qmtasks.append(self.create_task('ts2qm',x,x.change_ext('.qm')))
166 if getattr(self,'update',None)and Options.options.trans_qt4:
167 cxxnodes=[a.inputs[0]for a in self.compiled_tasks]+[a.inputs[0]for a in self.tasks if getattr(a,'inputs',None)and a.inputs[0].name.endswith('.ui')]
168 for x in qmtasks:
169 self.create_task('trans_update',cxxnodes,x.inputs)
170 if getattr(self,'langname',None):
171 qmnodes=[x.outputs[0]for x in qmtasks]
172 rcnode=self.langname
173 if isinstance(rcnode,str):
174 rcnode=self.path.find_or_declare(rcnode+'.qrc')
175 t=self.create_task('qm2rcc',qmnodes,rcnode)
176 k=create_rcc_task(self,t.outputs[0])
177 self.link_task.inputs.append(k.outputs[0])
178 lst=[]
179 for flag in self.to_list(self.env['CXXFLAGS']):
180 if len(flag)<2:continue
181 f=flag[0:2]
182 if f in['-D','-I','/D','/I']:
183 if(f[0]=='/'):
184 lst.append('-'+flag[1:])
185 else:
186 lst.append(flag)
187 self.env.append_value('MOC_FLAGS',lst)
188@extension(*EXT_QT4)
189def cxx_hook(self,node):
190 return self.create_compiled_task('qxx',node)
191class rcc(Task.Task):
192 color='BLUE'
193 run_str='${QT_RCC} -name ${SRC[0].name} ${SRC[0].abspath()} ${RCC_ST} -o ${TGT}'
194 ext_out=['.h']
195 def scan(self):
196 node=self.inputs[0]
197 if not has_xml:
198 Logs.error('no xml support was found, the rcc dependencies will be incomplete!')
199 return([],[])
200 parser=make_parser()
201 curHandler=XMLHandler()
202 parser.setContentHandler(curHandler)
203 fi=open(self.inputs[0].abspath(),'r')
204 try:
205 parser.parse(fi)
206 finally:
207 fi.close()
208 nodes=[]
209 names=[]
210 root=self.inputs[0].parent
211 for x in curHandler.files:
212 nd=root.find_resource(x)
213 if nd:nodes.append(nd)
214 else:names.append(x)
215 return(nodes,names)
216class moc(Task.Task):
217 color='BLUE'
218 run_str='${QT_MOC} ${MOC_FLAGS} ${MOCCPPPATH_ST:INCPATHS} ${MOCDEFINES_ST:DEFINES} ${SRC} ${MOC_ST} ${TGT}'
219class ui4(Task.Task):
220 color='BLUE'
221 run_str='${QT_UIC} ${SRC} -o ${TGT}'
222 ext_out=['.h']
223class ts2qm(Task.Task):
224 color='BLUE'
225 run_str='${QT_LRELEASE} ${QT_LRELEASE_FLAGS} ${SRC} -qm ${TGT}'
226class qm2rcc(Task.Task):
227 color='BLUE'
228 after='ts2qm'
229 def run(self):
230 txt='\n'.join(['<file>%s</file>'%k.path_from(self.outputs[0].parent)for k in self.inputs])
231 code='<!DOCTYPE RCC><RCC version="1.0">\n<qresource>\n%s\n</qresource>\n</RCC>'%txt
232 self.outputs[0].write(code)
233def configure(self):
234 self.find_qt4_binaries()
235 self.set_qt4_libs_to_check()
236 self.set_qt4_defines()
237 self.find_qt4_libraries()
238 self.add_qt4_rpath()
239 self.simplify_qt4_libs()
240@conf
241def find_qt4_binaries(self):
242 env=self.env
243 opt=Options.options
244 qtdir=getattr(opt,'qtdir','')
245 qtbin=getattr(opt,'qtbin','')
246 paths=[]
247 if qtdir:
248 qtbin=os.path.join(qtdir,'bin')
249 if not qtdir:
250 qtdir=os.environ.get('QT4_ROOT','')
251 qtbin=os.environ.get('QT4_BIN',None)or os.path.join(qtdir,'bin')
252 if qtbin:
253 paths=[qtbin]
254 if not qtdir:
255 paths=os.environ.get('PATH','').split(os.pathsep)
256 paths.append('/usr/share/qt4/bin/')
257 try:
258 lst=Utils.listdir('/usr/local/Trolltech/')
259 except OSError:
260 pass
261 else:
262 if lst:
263 lst.sort()
264 lst.reverse()
265 qtdir='/usr/local/Trolltech/%s/'%lst[0]
266 qtbin=os.path.join(qtdir,'bin')
267 paths.append(qtbin)
268 cand=None
269 prev_ver=['4','0','0']
270 for qmk in['qmake-qt4','qmake4','qmake']:
271 try:
272 qmake=self.find_program(qmk,path_list=paths)
273 except self.errors.ConfigurationError:
274 pass
275 else:
276 try:
277 version=self.cmd_and_log([qmake,'-query','QT_VERSION']).strip()
278 except self.errors.WafError:
279 pass
280 else:
281 if version:
282 new_ver=version.split('.')
283 if new_ver>prev_ver:
284 cand=qmake
285 prev_ver=new_ver
286 if cand:
287 self.env.QMAKE=cand
288 else:
289 self.fatal('Could not find qmake for qt4')
290 qtbin=self.cmd_and_log([self.env.QMAKE,'-query','QT_INSTALL_BINS']).strip()+os.sep
291 def find_bin(lst,var):
292 if var in env:
293 return
294 for f in lst:
295 try:
296 ret=self.find_program(f,path_list=paths)
297 except self.errors.ConfigurationError:
298 pass
299 else:
300 env[var]=ret
301 break
302 find_bin(['uic-qt3','uic3'],'QT_UIC3')
303 find_bin(['uic-qt4','uic'],'QT_UIC')
304 if not env['QT_UIC']:
305 self.fatal('cannot find the uic compiler for qt4')
306 try:
307 uicver=self.cmd_and_log(env['QT_UIC']+" -version 2>&1").strip()
308 except self.errors.ConfigurationError:
309 self.fatal('this uic compiler is for qt3, add uic for qt4 to your path')
310 uicver=uicver.replace('Qt User Interface Compiler ','').replace('User Interface Compiler for Qt','')
311 self.msg('Checking for uic version','%s'%uicver)
312 if uicver.find(' 3.')!=-1:
313 self.fatal('this uic compiler is for qt3, add uic for qt4 to your path')
314 find_bin(['moc-qt4','moc'],'QT_MOC')
315 find_bin(['rcc'],'QT_RCC')
316 find_bin(['lrelease-qt4','lrelease'],'QT_LRELEASE')
317 find_bin(['lupdate-qt4','lupdate'],'QT_LUPDATE')
318 env['UIC3_ST']='%s -o %s'
319 env['UIC_ST']='%s -o %s'
320 env['MOC_ST']='-o'
321 env['ui_PATTERN']='ui_%s.h'
322 env['QT_LRELEASE_FLAGS']=['-silent']
323 env.MOCCPPPATH_ST='-I%s'
324 env.MOCDEFINES_ST='-D%s'
325@conf
326def find_qt4_libraries(self):
327 qtlibs=getattr(Options.options,'qtlibs',None)or os.environ.get("QT4_LIBDIR",None)
328 if not qtlibs:
329 try:
330 qtlibs=self.cmd_and_log([self.env.QMAKE,'-query','QT_INSTALL_LIBS']).strip()
331 except Errors.WafError:
332 qtdir=self.cmd_and_log([self.env.QMAKE,'-query','QT_INSTALL_PREFIX']).strip()+os.sep
333 qtlibs=os.path.join(qtdir,'lib')
334 self.msg('Found the Qt4 libraries in',qtlibs)
335 qtincludes=os.environ.get("QT4_INCLUDES",None)or self.cmd_and_log([self.env.QMAKE,'-query','QT_INSTALL_HEADERS']).strip()
336 env=self.env
337 if not'PKG_CONFIG_PATH'in os.environ:
338 os.environ['PKG_CONFIG_PATH']='%s:%s/pkgconfig:/usr/lib/qt4/lib/pkgconfig:/opt/qt4/lib/pkgconfig:/usr/lib/qt4/lib:/opt/qt4/lib'%(qtlibs,qtlibs)
339 try:
340 if os.environ.get("QT4_XCOMPILE",None):
341 raise self.errors.ConfigurationError()
342 self.check_cfg(atleast_pkgconfig_version='0.1')
343 except self.errors.ConfigurationError:
344 for i in self.qt4_vars:
345 uselib=i.upper()
346 if Utils.unversioned_sys_platform()=="darwin":
347 frameworkName=i+".framework"
348 qtDynamicLib=os.path.join(qtlibs,frameworkName,i)
349 if os.path.exists(qtDynamicLib):
350 env.append_unique('FRAMEWORK_'+uselib,i)
351 self.msg('Checking for %s'%i,qtDynamicLib,'GREEN')
352 else:
353 self.msg('Checking for %s'%i,False,'YELLOW')
354 env.append_unique('INCLUDES_'+uselib,os.path.join(qtlibs,frameworkName,'Headers'))
355 elif env.DEST_OS!="win32":
356 qtDynamicLib=os.path.join(qtlibs,"lib"+i+".so")
357 qtStaticLib=os.path.join(qtlibs,"lib"+i+".a")
358 if os.path.exists(qtDynamicLib):
359 env.append_unique('LIB_'+uselib,i)
360 self.msg('Checking for %s'%i,qtDynamicLib,'GREEN')
361 elif os.path.exists(qtStaticLib):
362 env.append_unique('LIB_'+uselib,i)
363 self.msg('Checking for %s'%i,qtStaticLib,'GREEN')
364 else:
365 self.msg('Checking for %s'%i,False,'YELLOW')
366 env.append_unique('LIBPATH_'+uselib,qtlibs)
367 env.append_unique('INCLUDES_'+uselib,qtincludes)
368 env.append_unique('INCLUDES_'+uselib,os.path.join(qtincludes,i))
369 else:
370 for k in("lib%s.a","lib%s4.a","%s.lib","%s4.lib"):
371 lib=os.path.join(qtlibs,k%i)
372 if os.path.exists(lib):
373 env.append_unique('LIB_'+uselib,i+k[k.find("%s")+2:k.find('.')])
374 self.msg('Checking for %s'%i,lib,'GREEN')
375 break
376 else:
377 self.msg('Checking for %s'%i,False,'YELLOW')
378 env.append_unique('LIBPATH_'+uselib,qtlibs)
379 env.append_unique('INCLUDES_'+uselib,qtincludes)
380 env.append_unique('INCLUDES_'+uselib,os.path.join(qtincludes,i))
381 uselib=i.upper()+"_debug"
382 for k in("lib%sd.a","lib%sd4.a","%sd.lib","%sd4.lib"):
383 lib=os.path.join(qtlibs,k%i)
384 if os.path.exists(lib):
385 env.append_unique('LIB_'+uselib,i+k[k.find("%s")+2:k.find('.')])
386 self.msg('Checking for %s'%i,lib,'GREEN')
387 break
388 else:
389 self.msg('Checking for %s'%i,False,'YELLOW')
390 env.append_unique('LIBPATH_'+uselib,qtlibs)
391 env.append_unique('INCLUDES_'+uselib,qtincludes)
392 env.append_unique('INCLUDES_'+uselib,os.path.join(qtincludes,i))
393 else:
394 for i in self.qt4_vars_debug+self.qt4_vars:
395 self.check_cfg(package=i,args='--cflags --libs',mandatory=False)
396@conf
397def simplify_qt4_libs(self):
398 env=self.env
399 def process_lib(vars_,coreval):
400 for d in vars_:
401 var=d.upper()
402 if var=='QTCORE':
403 continue
404 value=env['LIBPATH_'+var]
405 if value:
406 core=env[coreval]
407 accu=[]
408 for lib in value:
409 if lib in core:
410 continue
411 accu.append(lib)
412 env['LIBPATH_'+var]=accu
413 process_lib(self.qt4_vars,'LIBPATH_QTCORE')
414 process_lib(self.qt4_vars_debug,'LIBPATH_QTCORE_DEBUG')
415@conf
416def add_qt4_rpath(self):
417 env=self.env
418 if getattr(Options.options,'want_rpath',False):
419 def process_rpath(vars_,coreval):
420 for d in vars_:
421 var=d.upper()
422 value=env['LIBPATH_'+var]
423 if value:
424 core=env[coreval]
425 accu=[]
426 for lib in value:
427 if var!='QTCORE':
428 if lib in core:
429 continue
430 accu.append('-Wl,--rpath='+lib)
431 env['RPATH_'+var]=accu
432 process_rpath(self.qt4_vars,'LIBPATH_QTCORE')
433 process_rpath(self.qt4_vars_debug,'LIBPATH_QTCORE_DEBUG')
434@conf
435def set_qt4_libs_to_check(self):
436 if not hasattr(self,'qt4_vars'):
437 self.qt4_vars=QT4_LIBS
438 self.qt4_vars=Utils.to_list(self.qt4_vars)
439 if not hasattr(self,'qt4_vars_debug'):
440 self.qt4_vars_debug=[a+'_debug'for a in self.qt4_vars]
441 self.qt4_vars_debug=Utils.to_list(self.qt4_vars_debug)
442@conf
443def set_qt4_defines(self):
444 if sys.platform!='win32':
445 return
446 for x in self.qt4_vars:
447 y=x[2:].upper()
448 self.env.append_unique('DEFINES_%s'%x.upper(),'QT_%s_LIB'%y)
449 self.env.append_unique('DEFINES_%s_DEBUG'%x.upper(),'QT_%s_LIB'%y)
450def options(opt):
451 opt.add_option('--want-rpath',action='store_true',default=False,dest='want_rpath',help='enable the rpath for qt libraries')
452 opt.add_option('--header-ext',type='string',default='',help='header extension for moc files',dest='qt_header_ext')
453 for i in'qtdir qtbin qtlibs'.split():
454 opt.add_option('--'+i,type='string',default='',dest=i)
455 opt.add_option('--translate',action="store_true",help="collect translation strings",dest="trans_qt4",default=False)