2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-10 20:29:10 +01:00

Update more examples

This commit is contained in:
Waf Project 2024-05-21 20:35:25 +02:00
parent 69049d83b8
commit b47fceb86a
9 changed files with 60 additions and 55 deletions

View File

@ -35,4 +35,3 @@ Bar_private::Bar_private() : QWidget(NULL) {
} }
#include "foo.moc" #include "foo.moc"

View File

@ -1,33 +0,0 @@
#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2005, 2011 (ita)
"""
Including the moc files *is* the best practice (KDE), not doing it is easy,
but makes the compilations about 30-40% slower on average.
This is the slow version that creates _moc.cpp files (a bad idea!)
"""
VERSION='0.0.2'
APPNAME='qt4_test2'
top = '.'
out = 'build'
def options(opt):
opt.load('compiler_cxx qt4')
def configure(conf):
conf.load('compiler_cxx qt4')
conf.load('slow_qt4')
def build(bld):
bld(
features = 'qt4 cxx cxxprogram',
uselib = 'QTCORE QTGUI QTOPENGL QTSVG',
source = 'main.cpp foo.cpp',
includes = '.',
target = 'window',
)

View File

@ -20,5 +20,4 @@ FooP::FooP() {
} }
#include "foo_cpp_moc.cpp" #include "foo_cpp_mywindow_moc.cpp"

View File

@ -0,0 +1,35 @@
#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2005, 2011 (ita)
"""
Process Q_OBJECT classes in source (foo.cpp) and header (foo.h) files.
The generated files can be included or they will be built as additional files.
The file slow_qt.py assumes that C++ files will include the generated code,
and that header files will not.
"""
VERSION='0.0.3'
APPNAME='slow_qt'
top = '.'
out = 'build'
def options(opt):
opt.load('compiler_cxx qt5')
def configure(conf):
conf.load('compiler_cxx qt5')
conf.load('slow_qt')
def build(bld):
bld(
features = 'qt5 cxx cxxprogram',
uselib = 'QT5CORE QT5GUI QT5OPENGL QT5SVG',
source = 'main.cpp foo.cpp',
deps = 'foo.h',
includes = '.',
target = 'window',
name = 'mywindow',
)

View File

@ -9,7 +9,6 @@ def configure(conf):
def build(bld): def build(bld):
bld.env.A = "test (change me) " bld.env.A = "test (change me) "
bld(rule="echo '${A}' > ${TGT}", target='foo.txt', name='foo') bld(rule="echo '${A}' > ${TGT}", target='foo.txt', name='foo', cls_keyword=lambda _: "step 1")
bld(rule='echo `cat ${SRC} ${SRC}` > ${SRC}', source='foo.txt', name='one') bld(rule='echo `cat ${SRC} ${SRC}` > ${SRC}', source='foo.txt', name='one', cls_keyword=lambda _:"step_2")
bld(rule='echo `cat ${SRC} ${SRC}` > ${SRC}', source='foo.txt', after=['one'], name='two') bld(rule='echo `cat ${SRC} ${SRC}` > ${SRC}', source='foo.txt', after=['one'], name='two', cls_keyword=lambda _:"step_3")

View File

@ -619,9 +619,13 @@ def process_rule(self):
cls = Task.task_factory(name, rule, _vars, shell=shell, color=color) cls = Task.task_factory(name, rule, _vars, shell=shell, color=color)
if cls_str: if cls_str:
if isinstance(cls_str, str):
raise ValueError('cls_str should be a function %r' % self)
setattr(cls, '__str__', self.cls_str) setattr(cls, '__str__', self.cls_str)
if cls_keyword: if cls_keyword:
if isinstance(cls_keyword, str):
raise ValueError('cls_keyword should be a function %r' % self)
setattr(cls, 'keyword', self.cls_keyword) setattr(cls, 'keyword', self.cls_keyword)
if deep_inputs: if deep_inputs:

View File

@ -4,23 +4,23 @@
""" """
Create _moc.cpp files Create _moc.cpp files
The builds are 30-40% faster when .moc files are included, The builds are 30-40% faster when .moc files are directly included,
you should NOT use this tool. If you really so the usage of this tool is discouraged.
really want it:
def configure(conf): def configure(conf):
conf.load('compiler_cxx qt4') conf.load('compiler_cxx qt5')
conf.load('slow_qt4') conf.load('slow_qt')
See playground/slow_qt/wscript for a complete example. See playground/slow_qt/wscript for a complete example,
and run with "waf --zones=slow_qt" to display the moc files that should be generated
""" """
from waflib.TaskGen import extension from waflib.TaskGen import extension
from waflib import Task from waflib import Task, Logs
import waflib.Tools.qt4 import waflib.Tools.qt5
import waflib.Tools.cxx import waflib.Tools.cxx
@extension(*waflib.Tools.qt4.EXT_QT4) @extension(*waflib.Tools.qt5.EXT_QT5)
def cxx_hook(self, node): def cxx_hook(self, node):
return self.create_compiled_task('cxx_qt', node) return self.create_compiled_task('cxx_qt', node)
@ -28,7 +28,6 @@ class cxx_qt(Task.classes['cxx']):
def runnable_status(self): def runnable_status(self):
ret = Task.classes['cxx'].runnable_status(self) ret = Task.classes['cxx'].runnable_status(self)
if ret != Task.ASK_LATER and not getattr(self, 'moc_done', None): if ret != Task.ASK_LATER and not getattr(self, 'moc_done', None):
try: try:
cache = self.generator.moc_cache cache = self.generator.moc_cache
except AttributeError: except AttributeError:
@ -49,19 +48,23 @@ class cxx_qt(Task.classes['cxx']):
# no corresponding file, continue # no corresponding file, continue
continue continue
# the file foo.cpp could be compiled for a static and a shared library - hence the %number in the name # the file foo.cpp could be compiled for a static and a shared library
cxx_node = x.parent.get_bld().make_node(x.name.replace('.', '_') + '_%d_moc.cpp' % self.generator.idx) # one workaround is to use a %number in the name
#cxx_node = x.parent.get_bld().make_node(x.name.replace('.', '_') + '_%d_moc.cpp' % self.generator.idx)
# another workaround is to add the target name
cxx_node = x.parent.get_bld().make_node(x.name.replace('.', '_') + '_%s_moc.cpp' % self.generator.name)
if cxx_node in cache: if cxx_node in cache:
continue continue
cache[cxx_node] = self cache[cxx_node] = self
Logs.debug('slow_qt: will create a file named %s', cxx_node.abspath())
tsk = Task.classes['moc'](env=self.env, generator=self.generator) tsk = Task.classes['moc'](env=self.env, generator=self.generator)
tsk.set_inputs(x) tsk.set_inputs(x)
tsk.set_outputs(cxx_node) tsk.set_outputs(cxx_node)
if x.name.endswith('.cpp'): if x.name.endswith('.cpp'):
# moc is trying to be too smart but it is too dumb:
# why forcing the #include when Q_OBJECT is in the cpp file?
gen = self.generator.bld.producer gen = self.generator.bld.producer
gen.outstanding.append(tsk) gen.outstanding.append(tsk)
gen.total += 1 gen.total += 1
@ -93,4 +96,3 @@ class cxx_qt(Task.classes['cxx']):
return Task.ASK_LATER return Task.ASK_LATER
return ret return ret