From 050a56ad47fef8f8fbc66a6b3465bd49697bef94 Mon Sep 17 00:00:00 2001 From: Leif Middelschulte Date: Tue, 24 Oct 2017 10:05:26 +0200 Subject: Qt5-Module: Add `moc_extra_arguments` keyword support. This commit adds support for an additional `moc_extra_arguments` keyword. It becomes especially handy, when `moc`-ed sources conditionally provide `slots`, depending on compile time macros (i.e. defines). --- docs/markdown/Qt5-module.md | 10 +++++----- docs/markdown/snippets/qt5-moc_extra_arguments.md | 8 ++++++++ mesonbuild/modules/qt.py | 19 ++++++++++++++----- 3 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 docs/markdown/snippets/qt5-moc_extra_arguments.md diff --git a/docs/markdown/Qt5-module.md b/docs/markdown/Qt5-module.md index a8ad73d63..613e5c1f2 100644 --- a/docs/markdown/Qt5-module.md +++ b/docs/markdown/Qt5-module.md @@ -5,11 +5,11 @@ tools and steps required for Qt. The module has one method. ## preprocess -This method takes five keyword arguments, `moc_headers`, -`moc_sources`, `ui_files` and `qresources` which define the files that -require preprocessing with `moc`, `uic` and `rcc` and 'include_directories' which might be needed by moc. It returns an -opaque object that should be passed to a main build target. A simple -example would look like this: +This method takes six keyword arguments, `moc_headers`, `moc_sources`, `ui_files`, `qresources` +and `moc_extra_arguments` which define the files that require preprocessing with `moc`, `uic` +and `rcc` and 'include_directories' which might be needed by moc as well as (optional) +additional arguments. It returns an opaque object that should be passed to a main build target. +A simple example would look like this: ```meson qt5 = import('qt5') diff --git a/docs/markdown/snippets/qt5-moc_extra_arguments.md b/docs/markdown/snippets/qt5-moc_extra_arguments.md new file mode 100644 index 000000000..957c3c733 --- /dev/null +++ b/docs/markdown/snippets/qt5-moc_extra_arguments.md @@ -0,0 +1,8 @@ +# Adds support for additional Qt5-Module keyword `moc_extra_arguments` + +When `moc`-ing sources, the `moc` tool does not know about any +preprocessor macros. The generated code might not match the input +files when the linking with the moc input sources happens. + +This amendment allows to specify a a list of additional arguments +passed to the `moc` tool. They are called `moc_extra_arguments`. \ No newline at end of file diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 2f2474070..1ff30efe7 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -84,10 +84,10 @@ class QtBaseModule: except Exception: return [] - @permittedKwargs({'moc_headers', 'moc_sources', 'include_directories', 'ui_files', 'qresources', 'method'}) + @permittedKwargs({'moc_headers', 'moc_sources', 'moc_extra_arguments', 'include_directories', 'ui_files', 'qresources', 'method'}) def preprocess(self, state, args, kwargs): - rcc_files, ui_files, moc_headers, moc_sources, sources, include_directories \ - = extract_as_list(kwargs, 'qresources', 'ui_files', 'moc_headers', 'moc_sources', 'sources', 'include_directories', pop = True) + rcc_files, ui_files, moc_headers, moc_sources, moc_extra_arguments, sources, include_directories \ + = extract_as_list(kwargs, 'qresources', 'ui_files', 'moc_headers', 'moc_sources', 'moc_extra_arguments', 'sources', 'include_directories', pop = True) sources += args[1:] method = kwargs.get('method', 'auto') self._detect_tools(state.environment, method) @@ -122,14 +122,23 @@ class QtBaseModule: sources.append(ui_output) inc = get_include_args(include_dirs=include_directories) if len(moc_headers) > 0: + if len(moc_extra_arguments) > 0: + arguments = moc_extra_arguments + inc + ['@INPUT@', '-o', '@OUTPUT@'] + else: + arguments = inc + ['@INPUT@', '-o', '@OUTPUT@'] moc_kwargs = {'output': 'moc_@BASENAME@.cpp', - 'arguments': inc + ['@INPUT@', '-o', '@OUTPUT@']} + 'arguments': arguments} moc_gen = build.Generator([self.moc], moc_kwargs) moc_output = moc_gen.process_files('Qt{} moc header'.format(self.qt_version), moc_headers, state) sources.append(moc_output) if len(moc_sources) > 0: + if len(moc_extra_arguments) > 0: + concatinated_moc_extra_arguments = ' '.join(moc_extra_arguments) + arguments = [concatinated_moc_extra_arguments, '@INPUT@', '-o', '@OUTPUT@'] + else: + arguments = ['@INPUT@', '-o', '@OUTPUT@'] moc_kwargs = {'output': '@BASENAME@.moc', - 'arguments': ['@INPUT@', '-o', '@OUTPUT@']} + 'arguments': arguments} moc_gen = build.Generator([self.moc], moc_kwargs) moc_output = moc_gen.process_files('Qt{} moc source'.format(self.qt_version), moc_sources, state) sources.append(moc_output) -- cgit v1.2.3 From 98e095bd477e7eae14c133a5dfb2a138c4be2340 Mon Sep 17 00:00:00 2001 From: Leif Middelschulte Date: Wed, 25 Oct 2017 22:31:47 +0200 Subject: extends test case to fail if macro is undefined durcing preprocessing --- test cases/frameworks/4 qt/manualinclude.cpp | 5 +++++ test cases/frameworks/4 qt/manualinclude.h | 2 ++ test cases/frameworks/4 qt/meson.build | 1 + 3 files changed, 8 insertions(+) diff --git a/test cases/frameworks/4 qt/manualinclude.cpp b/test cases/frameworks/4 qt/manualinclude.cpp index 06028823f..60f30b0ae 100644 --- a/test cases/frameworks/4 qt/manualinclude.cpp +++ b/test cases/frameworks/4 qt/manualinclude.cpp @@ -10,9 +10,14 @@ class MocClass : public QObject { Q_OBJECT }; +void testSlot() { + ; +} + int main(int argc, char **argv) { ManualInclude mi; MocClass mc; + QObject::connect(&mi, &ManualInclude::mysignal, &testSlot); return 0; } diff --git a/test cases/frameworks/4 qt/manualinclude.h b/test cases/frameworks/4 qt/manualinclude.h index 4a00b6c28..15253ba8d 100644 --- a/test cases/frameworks/4 qt/manualinclude.h +++ b/test cases/frameworks/4 qt/manualinclude.h @@ -9,7 +9,9 @@ class ManualInclude : public QObject { public: ManualInclude(); +#if defined(MOC_EXTRA_FLAG) signals: +#endif int mysignal(); }; diff --git a/test cases/frameworks/4 qt/meson.build b/test cases/frameworks/4 qt/meson.build index 39be19f1e..b8172288b 100644 --- a/test cases/frameworks/4 qt/meson.build +++ b/test cases/frameworks/4 qt/meson.build @@ -61,6 +61,7 @@ foreach qt : ['qt4', 'qt5'] # headers but the user must manually include moc # files from sources. manpreprocessed = qtmodule.preprocess( + moc_extra_arguments : ['-DMOC_EXTRA_FLAG'], # This is just a random macro to test `moc_extra_arguments` moc_sources : 'manualinclude.cpp', moc_headers : 'manualinclude.h', method : get_option('method')) -- cgit v1.2.3 From 6fc3c0df0c212f0f51bbbb7a4006acfbf51d2d62 Mon Sep 17 00:00:00 2001 From: Leif Middelschulte Date: Thu, 26 Oct 2017 11:49:35 +0200 Subject: fixes the extended test suite to work with qt5 **and** qt4. --- test cases/frameworks/4 qt/manualinclude.cpp | 12 +++++++----- test cases/frameworks/4 qt/manualinclude.h | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/test cases/frameworks/4 qt/manualinclude.cpp b/test cases/frameworks/4 qt/manualinclude.cpp index 60f30b0ae..6c1ac2f1c 100644 --- a/test cases/frameworks/4 qt/manualinclude.cpp +++ b/test cases/frameworks/4 qt/manualinclude.cpp @@ -6,18 +6,20 @@ ManualInclude::ManualInclude() { } +void ManualInclude::myslot(void) { + ; +} + class MocClass : public QObject { Q_OBJECT }; -void testSlot() { - ; -} - int main(int argc, char **argv) { ManualInclude mi; MocClass mc; - QObject::connect(&mi, &ManualInclude::mysignal, &testSlot); + QObject::connect(&mi, SIGNAL(mysignal(void)), + &mi, SLOT(myslot(void))); + emit mi.mysignal(); return 0; } diff --git a/test cases/frameworks/4 qt/manualinclude.h b/test cases/frameworks/4 qt/manualinclude.h index 15253ba8d..44bb7a76b 100644 --- a/test cases/frameworks/4 qt/manualinclude.h +++ b/test cases/frameworks/4 qt/manualinclude.h @@ -8,6 +8,10 @@ class ManualInclude : public QObject { public: ManualInclude(); +#if defined(MOC_EXTRA_FLAG) +public slots: +#endif + void myslot(void); #if defined(MOC_EXTRA_FLAG) signals: -- cgit v1.2.3 From 32a8ab40c151b48987fcf9ec7c11c13e5c53f509 Mon Sep 17 00:00:00 2001 From: Leif Middelschulte Date: Thu, 26 Oct 2017 11:58:51 +0200 Subject: removes unnecessary if/else-statement as suggested by @jeandet Details: https://github.com/mesonbuild/meson/pull/2529#discussion_r146985692 --- mesonbuild/modules/qt.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 1ff30efe7..c55d50f1a 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -122,10 +122,7 @@ class QtBaseModule: sources.append(ui_output) inc = get_include_args(include_dirs=include_directories) if len(moc_headers) > 0: - if len(moc_extra_arguments) > 0: - arguments = moc_extra_arguments + inc + ['@INPUT@', '-o', '@OUTPUT@'] - else: - arguments = inc + ['@INPUT@', '-o', '@OUTPUT@'] + arguments = moc_extra_arguments + inc + ['@INPUT@', '-o', '@OUTPUT@'] moc_kwargs = {'output': 'moc_@BASENAME@.cpp', 'arguments': arguments} moc_gen = build.Generator([self.moc], moc_kwargs) -- cgit v1.2.3 From b919e0582178fc39b56efbbf0dc66eb949badc0c Mon Sep 17 00:00:00 2001 From: Leif Middelschulte Date: Thu, 26 Oct 2017 13:02:29 +0200 Subject: removes unnecessary code as suggested by @jeandet Details: https://github.com/mesonbuild/meson/pull/2529#discussion_r146985692 --- mesonbuild/modules/qt.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index c55d50f1a..a7b58dbfb 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -129,11 +129,7 @@ class QtBaseModule: moc_output = moc_gen.process_files('Qt{} moc header'.format(self.qt_version), moc_headers, state) sources.append(moc_output) if len(moc_sources) > 0: - if len(moc_extra_arguments) > 0: - concatinated_moc_extra_arguments = ' '.join(moc_extra_arguments) - arguments = [concatinated_moc_extra_arguments, '@INPUT@', '-o', '@OUTPUT@'] - else: - arguments = ['@INPUT@', '-o', '@OUTPUT@'] + arguments = [moc_extra_arguments, '@INPUT@', '-o', '@OUTPUT@'] moc_kwargs = {'output': '@BASENAME@.moc', 'arguments': arguments} moc_gen = build.Generator([self.moc], moc_kwargs) -- cgit v1.2.3 From a46d05acf9dda6f2e5f06254a6da6652646a820e Mon Sep 17 00:00:00 2001 From: Leif Middelschulte Date: Fri, 27 Oct 2017 08:38:15 +0200 Subject: updates the documentation to follow the list-style to explain arguments. As per to @jon-turney's and @jpakanne's suggestion [0], this commit changes the "prosa" documentation to a list-style one. [0] https://github.com/mesonbuild/meson/pull/2529#pullrequestreview-72265697 --- docs/markdown/Qt5-module.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/markdown/Qt5-module.md b/docs/markdown/Qt5-module.md index 613e5c1f2..e84b5fd3f 100644 --- a/docs/markdown/Qt5-module.md +++ b/docs/markdown/Qt5-module.md @@ -5,10 +5,13 @@ tools and steps required for Qt. The module has one method. ## preprocess -This method takes six keyword arguments, `moc_headers`, `moc_sources`, `ui_files`, `qresources` -and `moc_extra_arguments` which define the files that require preprocessing with `moc`, `uic` -and `rcc` and 'include_directories' which might be needed by moc as well as (optional) -additional arguments. It returns an opaque object that should be passed to a main build target. +This method takes the following keyword arguments: + - `moc_headers`, `moc_sources`, `ui_files`, `qresources`, which define the files that require preprocessing with `moc`, `uic` and `rcc` + - `include_directories`, the directories to add to header search path for `moc` (optional) + - `moc_extra_arguments`, any additional arguments to `moc` (optional). + +It returns an opaque object that should be passed to a main build target. + A simple example would look like this: ```meson -- cgit v1.2.3 From f720e590b1a6798fced6b2345cbb066788e79d90 Mon Sep 17 00:00:00 2001 From: Leif Middelschulte Date: Fri, 27 Oct 2017 08:43:26 +0200 Subject: adds "since"-note for the new keyword to the documentation --- docs/markdown/Qt5-module.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/markdown/Qt5-module.md b/docs/markdown/Qt5-module.md index e84b5fd3f..e5fc066c6 100644 --- a/docs/markdown/Qt5-module.md +++ b/docs/markdown/Qt5-module.md @@ -8,7 +8,7 @@ tools and steps required for Qt. The module has one method. This method takes the following keyword arguments: - `moc_headers`, `moc_sources`, `ui_files`, `qresources`, which define the files that require preprocessing with `moc`, `uic` and `rcc` - `include_directories`, the directories to add to header search path for `moc` (optional) - - `moc_extra_arguments`, any additional arguments to `moc` (optional). + - `moc_extra_arguments`, any additional arguments to `moc` (optional). Available since v0.44.0. It returns an opaque object that should be passed to a main build target. -- cgit v1.2.3 From a2478d4dab3df995a2d4e352e8467c39b3343f9c Mon Sep 17 00:00:00 2001 From: Leif Middelschulte Date: Fri, 27 Oct 2017 08:46:25 +0200 Subject: documentation: adds new keyword usage to the given example. --- docs/markdown/Qt5-module.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/markdown/Qt5-module.md b/docs/markdown/Qt5-module.md index e5fc066c6..aea2ae139 100644 --- a/docs/markdown/Qt5-module.md +++ b/docs/markdown/Qt5-module.md @@ -18,7 +18,9 @@ A simple example would look like this: qt5 = import('qt5') qt5_dep = dependency('qt5', modules: ['Core', 'Gui']) inc = include_directories('includes') -moc_files = qt5.preprocess(moc_headers : 'myclass.h', include_directories: inc) +moc_files = qt5.preprocess(moc_headers : 'myclass.h', + moc_extra_arguments: ['-DMAKES_MY_MOC_HEADER_COMPILE'], + include_directories: inc) executable('myprog', 'main.cpp', 'myclass.cpp', moc_files, include_directories: inc, dependencies : qt5_dep) -- cgit v1.2.3 From cf759e529c9753b30bd926a75f629d3562fca990 Mon Sep 17 00:00:00 2001 From: Leif Middelschulte Date: Sun, 29 Oct 2017 18:06:38 +0100 Subject: Fixes the `kwargs` handling. As suggested by @jeandet. Details: https://github.com/mesonbuild/meson/pull/2529#pullrequestreview-72703268 --- 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 a7b58dbfb..0b7354faf 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -129,7 +129,7 @@ class QtBaseModule: moc_output = moc_gen.process_files('Qt{} moc header'.format(self.qt_version), moc_headers, state) sources.append(moc_output) if len(moc_sources) > 0: - arguments = [moc_extra_arguments, '@INPUT@', '-o', '@OUTPUT@'] + arguments = moc_extra_arguments + ['@INPUT@', '-o', '@OUTPUT@'] moc_kwargs = {'output': '@BASENAME@.moc', 'arguments': arguments} moc_gen = build.Generator([self.moc], moc_kwargs) -- cgit v1.2.3