2 # Thomas Nagy, 2011 (ita)
7 The builds are 30-40% faster when .moc files are included,
8 you should NOT use this tool. If you really
12 conf.load('compiler_cxx qt4')
15 See playground/slow_qt/wscript for a complete example.
18 from waflib.TaskGen import extension
19 from waflib import Task
20 import waflib.Tools.qt4
21 import waflib.Tools.cxx
23 @extension(*waflib.Tools.qt4.EXT_QT4)
24 def cxx_hook(self, node):
25 return self.create_compiled_task('cxx_qt', node)
27 class cxx_qt(Task.classes['cxx']):
28 def runnable_status(self):
29 ret = Task.classes['cxx'].runnable_status(self)
30 if ret != Task.ASK_LATER and not getattr(self, 'moc_done', None):
33 cache = self.generator.moc_cache
34 except AttributeError:
35 cache = self.generator.moc_cache = {}
37 deps = self.generator.bld.node_deps[self.uid()]
38 for x in [self.inputs[0]] + deps:
39 if x.read().find('Q_OBJECT') > 0:
41 # process "foo.h -> foo.moc" only if "foo.cpp" is in the sources for the current task generator
42 # this code will work because it is in the main thread (runnable_status)
43 if x.name.rfind('.') > -1: # a .h file...
44 name = x.name[:x.name.rfind('.')]
45 for tsk in self.generator.compiled_tasks:
46 if tsk.inputs and tsk.inputs[0].name.startswith(name):
49 # no corresponding file, continue
52 # the file foo.cpp could be compiled for a static and a shared library - hence the %number in the name
53 cxx_node = x.parent.get_bld().make_node(x.name.replace('.', '_') + '_%d_moc.cpp' % self.generator.idx)
56 cache[cxx_node] = self
58 tsk = Task.classes['moc'](env=self.env, generator=self.generator)
60 tsk.set_outputs(cxx_node)
62 if x.name.endswith('.cpp'):
63 # moc is trying to be too smart but it is too dumb:
64 # why forcing the #include when Q_OBJECT is in the cpp file?
65 gen = self.generator.bld.producer
66 gen.outstanding.append(tsk)
68 self.set_run_after(tsk)
70 cxxtsk = Task.classes['cxx'](env=self.env, generator=self.generator)
71 cxxtsk.set_inputs(tsk.outputs)
72 cxxtsk.set_outputs(cxx_node.change_ext('.o'))
73 cxxtsk.set_run_after(tsk)
76 self.more_tasks.extend([tsk, cxxtsk])
77 except AttributeError:
78 self.more_tasks = [tsk, cxxtsk]
81 link = self.generator.link_task
82 except AttributeError:
85 link.set_run_after(cxxtsk)
86 link.inputs.extend(cxxtsk.outputs)
87 link.inputs.sort(key=lambda x: x.abspath())
91 for t in self.run_after: