From 51bc364a103a32f4474f77a0936d985a70292651 Mon Sep 17 00:00:00 2001 From: Markus Theil Date: Fri, 3 Nov 2017 18:16:51 +0100 Subject: [PATCH 1/5] Qt5-Module: add `name` option to rcc This patch sets the --name option for files processed with rcc. It generates an additional initialization function, which can be used with static linking. Signed-off-by: Markus Theil --- mesonbuild/modules/qt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 5800e5cfa..f873b187f 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -108,7 +108,7 @@ class QtBaseModule: name = 'qt' + str(self.qt_version) + '-' + basename.replace('.', '_') rcc_kwargs = {'input': rcc_files, 'output': name + '.cpp', - 'command': [self.rcc, '-o', '@OUTPUT@', '@INPUT@'], + 'command': [self.rcc, '--name', '@BASENAME@', '-o', '@OUTPUT@', '@INPUT@'], 'depend_files': qrc_deps} res_target = build.CustomTarget(name, state.subdir, state.subproject, rcc_kwargs) sources.append(res_target) From b36475ff44547d49f351ab87e6e024c48b368bbf Mon Sep 17 00:00:00 2001 From: Markus Theil Date: Fri, 3 Nov 2017 18:42:35 +0100 Subject: [PATCH 2/5] Qt-Module: fix rcc `name` with Qt4 Qt5's rcc knows --name and -name, Qt4's only -name. Signed-off-by: Markus Theil --- mesonbuild/modules/qt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index f873b187f..52dc978d6 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -108,7 +108,7 @@ class QtBaseModule: name = 'qt' + str(self.qt_version) + '-' + basename.replace('.', '_') rcc_kwargs = {'input': rcc_files, 'output': name + '.cpp', - 'command': [self.rcc, '--name', '@BASENAME@', '-o', '@OUTPUT@', '@INPUT@'], + 'command': [self.rcc, '-name', '@BASENAME@', '-o', '@OUTPUT@', '@INPUT@'], 'depend_files': qrc_deps} res_target = build.CustomTarget(name, state.subdir, state.subproject, rcc_kwargs) sources.append(res_target) From 3f8a082a680d9b844324e2082977766deba26b5f Mon Sep 17 00:00:00 2001 From: Markus Theil Date: Wed, 8 Nov 2017 23:08:53 +0100 Subject: [PATCH 3/5] Qt-Module: fix name option with multiple rcc files Signed-off-by: Markus Theil --- mesonbuild/modules/qt.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 52dc978d6..285169ba0 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -101,17 +101,25 @@ class QtBaseModule: qrc_deps = [] for i in rcc_files: qrc_deps += self.parse_qrc(state, i) + # custom output name set? -> one output file, multiple otherwise if len(args) > 0: name = args[0] + rcc_kwargs = {'input': rcc_files, + 'output': name + '.cpp', + 'command': [self.rcc, '-name', name, '-o', '@OUTPUT@', '@INPUT@'], + 'depend_files': qrc_deps} + res_target = build.CustomTarget(name, state.subdir, state.subproject, rcc_kwargs) + sources.append(res_target) else: - basename = os.path.split(rcc_files[0])[1] - name = 'qt' + str(self.qt_version) + '-' + basename.replace('.', '_') - rcc_kwargs = {'input': rcc_files, - 'output': name + '.cpp', - 'command': [self.rcc, '-name', '@BASENAME@', '-o', '@OUTPUT@', '@INPUT@'], - 'depend_files': qrc_deps} - res_target = build.CustomTarget(name, state.subdir, state.subproject, rcc_kwargs) - sources.append(res_target) + for rcc_file in rcc_files: + basename = os.path.split(rcc_file)[1] + name = 'qt' + str(self.qt_version) + '-' + basename.replace('.', '_') + rcc_kwargs = {'input': rcc_file, + 'output': name + '.cpp', + 'command': [self.rcc, '-name', '@BASENAME@', '-o', '@OUTPUT@', '@INPUT@'], + 'depend_files': qrc_deps} + res_target = build.CustomTarget(name, state.subdir, state.subproject, rcc_kwargs) + sources.append(res_target) if len(ui_files) > 0: if not self.uic.found(): raise MesonException(err_msg.format('UIC', 'uic-qt' + self.qt_version)) From 91c07aa301b90de80612c29b4980cc3a612698f6 Mon Sep 17 00:00:00 2001 From: Markus Theil Date: Wed, 8 Nov 2017 23:10:30 +0100 Subject: [PATCH 4/5] tests: adapted Qt test for multiple rcc files Signed-off-by: Markus Theil --- test cases/frameworks/4 qt/main.cpp | 17 ++++++++++++++++- test cases/frameworks/4 qt/mainWindow.ui | 24 ++++++++++++++++++++++-- test cases/frameworks/4 qt/meson.build | 2 +- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/test cases/frameworks/4 qt/main.cpp b/test cases/frameworks/4 qt/main.cpp index 4c257a4ba..cebe4551b 100644 --- a/test cases/frameworks/4 qt/main.cpp +++ b/test cases/frameworks/4 qt/main.cpp @@ -2,6 +2,8 @@ #include "mainWindow.h" int main(int argc, char **argv) { + Q_INIT_RESOURCE(stuff); + Q_INIT_RESOURCE(stuff2); QApplication app(argc, argv); MainWindow *win = new MainWindow(); QImage qi(":/thing.png"); @@ -13,7 +15,20 @@ int main(int argc, char **argv) { return 1; } win->setWindowTitle("Meson Qt5 build test"); - + QLabel *label_stuff = win->findChild("label_stuff"); + if(label_stuff == nullptr) { + return 1; + } + int w = label_stuff->width(); + int h = label_stuff->height(); + label_stuff->setPixmap(QPixmap::fromImage(qi).scaled(w,h,Qt::KeepAspectRatio)); + QLabel *label_stuff2 = win->findChild("label_stuff2"); + if(label_stuff2 == nullptr) { + return 1; + } + w = label_stuff2->width(); + h = label_stuff2->height(); + label_stuff2->setPixmap(QPixmap::fromImage(qi2).scaled(w,h,Qt::KeepAspectRatio)); win->show(); return app.exec(); return 0; diff --git a/test cases/frameworks/4 qt/mainWindow.ui b/test cases/frameworks/4 qt/mainWindow.ui index 2eb226a6e..c01b8bf9e 100644 --- a/test cases/frameworks/4 qt/mainWindow.ui +++ b/test cases/frameworks/4 qt/mainWindow.ui @@ -6,8 +6,8 @@ 0 0 - 270 - 115 + 260 + 313 @@ -27,6 +27,26 @@ I am a button + + + + 10 + 112 + 241 + 91 + + + + + + + 10 + 212 + 241 + 91 + + + diff --git a/test cases/frameworks/4 qt/meson.build b/test cases/frameworks/4 qt/meson.build index b8172288b..f2ac94ef8 100644 --- a/test cases/frameworks/4 qt/meson.build +++ b/test cases/frameworks/4 qt/meson.build @@ -40,7 +40,7 @@ foreach qt : ['qt4', 'qt5'] ) # Test that setting a unique name with a positional argument works - qtmodule.preprocess(qt + 'teststuff', qresources : ['stuff.qrc'], method : get_option('method')) + qtmodule.preprocess(qt + 'teststuff', qresources : ['stuff.qrc', 'stuff2.qrc'], method : get_option('method')) qexe = executable(qt + 'app', sources : ['main.cpp', 'mainWindow.cpp', # Sources that don't need preprocessing. From 875b3bbbe46bc9a04f95e305e22380dc8a60af39 Mon Sep 17 00:00:00 2001 From: Markus Theil Date: Thu, 9 Nov 2017 18:15:42 +0100 Subject: [PATCH 5/5] tests: fix qt unity build Signed-off-by: Markus Theil --- test cases/frameworks/4 qt/main.cpp | 2 ++ test cases/frameworks/4 qt/meson.build | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/test cases/frameworks/4 qt/main.cpp b/test cases/frameworks/4 qt/main.cpp index cebe4551b..388467e45 100644 --- a/test cases/frameworks/4 qt/main.cpp +++ b/test cases/frameworks/4 qt/main.cpp @@ -2,8 +2,10 @@ #include "mainWindow.h" int main(int argc, char **argv) { + #ifndef UNITY_BUILD Q_INIT_RESOURCE(stuff); Q_INIT_RESOURCE(stuff2); + #endif QApplication app(argc, argv); MainWindow *win = new MainWindow(); QImage qi(":/thing.png"); diff --git a/test cases/frameworks/4 qt/meson.build b/test cases/frameworks/4 qt/meson.build index f2ac94ef8..374707aac 100644 --- a/test cases/frameworks/4 qt/meson.build +++ b/test cases/frameworks/4 qt/meson.build @@ -35,17 +35,26 @@ foreach qt : ['qt4', 'qt5'] prep = qtmodule.preprocess( moc_headers : ['mainWindow.h'], # These need to be fed through the moc tool before use. ui_files : 'mainWindow.ui', # XML files that need to be compiled with the uic tol. - qresources : ['stuff.qrc', 'stuff2.qrc'], # Resource file for rcc compiler. method : get_option('method') ) + # Resource file(s) for rcc compiler + extra_cpp_args = [] + if meson.is_unity() + extra_cpp_args += '-DUNITY_BUILD' + prep_rcc = qtmodule.preprocess(qt + '_unity_ressource', qresources : ['stuff.qrc', 'stuff2.qrc'], method : get_option('method')) + else + prep_rcc = qtmodule.preprocess(qresources : ['stuff.qrc', 'stuff2.qrc'], method : get_option('method')) + endif + # Test that setting a unique name with a positional argument works qtmodule.preprocess(qt + 'teststuff', qresources : ['stuff.qrc', 'stuff2.qrc'], method : get_option('method')) qexe = executable(qt + 'app', sources : ['main.cpp', 'mainWindow.cpp', # Sources that don't need preprocessing. - prep], - dependencies : qtdep) + prep, prep_rcc], + dependencies : qtdep, + cpp_args: extra_cpp_args) # We need a console test application because some test environments # do not have an X server.