Added include directory argument for Qt's Moc which is needed to build plugins.

Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
pull/2414/head
Alexis Jeandet 7 years ago committed by Jussi Pakkanen
parent ae532c807c
commit a9258923fa
  1. 8
      docs/markdown/Qt5-module.md
  2. 10
      mesonbuild/modules/qt4.py
  3. 10
      mesonbuild/modules/qt5.py
  4. 10
      test cases/frameworks/4 qt/meson.build
  5. 7
      test cases/frameworks/4 qt/plugin/plugin.cpp
  6. 11
      test cases/frameworks/4 qt/plugin/plugin.h
  7. 3
      test cases/frameworks/4 qt/plugin/plugin.json
  8. 21
      test cases/frameworks/4 qt/pluginInterface/plugin_if.h

@ -5,17 +5,19 @@ tools and steps required for Qt. The module has one method.
## preprocess
This method takes four keyword arguments, `moc_headers`,
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`. It returns an
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:
```meson
qt5 = import('qt5')
qt5_dep = dependency('qt5', modules: ['Core', 'Gui'])
moc_files = qt5.preprocess(moc_headers : 'myclass.h')
inc = include_directories('includes')
moc_files = qt5.preprocess(moc_headers : 'myclass.h', include_directories: inc)
executable('myprog', 'main.cpp', 'myclass.cpp', moc_files,
include_directories: inc,
dependencies : qt5_dep)
```

@ -21,6 +21,7 @@ from . import ExtensionModule
import xml.etree.ElementTree as ET
from . import ModuleReturnValue
from ..interpreterbase import permittedKwargs
from . import get_include_args
class Qt4Module(ExtensionModule):
tools_detected = False
@ -97,10 +98,10 @@ class Qt4Module(ExtensionModule):
except Exception:
return []
@permittedKwargs({'moc_headers', 'moc_sources', 'ui_files', 'qresources', 'method'})
@permittedKwargs({'moc_headers', 'moc_sources', 'include_directories', 'ui_files', 'qresources', 'method'})
def preprocess(self, state, args, kwargs):
rcc_files, ui_files, moc_headers, moc_sources, sources \
= extract_as_list(kwargs, 'qresources', 'ui_files', 'moc_headers', 'moc_sources', 'sources', pop = True)
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)
sources += args[1:]
method = kwargs.get('method', 'auto')
self._detect_tools(state.environment, method)
@ -133,9 +134,10 @@ class Qt4Module(ExtensionModule):
ui_gen = build.Generator([self.uic], ui_kwargs)
ui_output = ui_gen.process_files('Qt4 ui', ui_files, state)
sources.append(ui_output)
inc = get_include_args(include_dirs=include_directories)
if len(moc_headers) > 0:
moc_kwargs = {'output': 'moc_@BASENAME@.cpp',
'arguments': ['@INPUT@', '-o', '@OUTPUT@']}
'arguments': inc + ['@INPUT@', '-o', '@OUTPUT@']}
moc_gen = build.Generator([self.moc], moc_kwargs)
moc_output = moc_gen.process_files('Qt4 moc header', moc_headers, state)
sources.append(moc_output)

@ -21,6 +21,7 @@ from . import ExtensionModule
import xml.etree.ElementTree as ET
from . import ModuleReturnValue
from ..interpreterbase import permittedKwargs
from . import get_include_args
class Qt5Module(ExtensionModule):
tools_detected = False
@ -103,10 +104,10 @@ class Qt5Module(ExtensionModule):
except Exception:
return []
@permittedKwargs({'moc_headers', 'moc_sources', 'ui_files', 'qresources', 'method'})
@permittedKwargs({'moc_headers', 'moc_sources', 'include_directories', 'ui_files', 'qresources', 'method'})
def preprocess(self, state, args, kwargs):
rcc_files, ui_files, moc_headers, moc_sources, sources \
= extract_as_list(kwargs, 'qresources', 'ui_files', 'moc_headers', 'moc_sources', 'sources', pop = True)
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)
sources += args[1:]
method = kwargs.get('method', 'auto')
self._detect_tools(state.environment, method)
@ -139,9 +140,10 @@ class Qt5Module(ExtensionModule):
ui_gen = build.Generator([self.uic], ui_kwargs)
ui_output = ui_gen.process_files('Qt5 ui', ui_files, state)
sources.append(ui_output)
inc = get_include_args(include_dirs=include_directories)
if len(moc_headers) > 0:
moc_kwargs = {'output': 'moc_@BASENAME@.cpp',
'arguments': ['@INPUT@', '-o', '@OUTPUT@']}
'arguments': inc + ['@INPUT@', '-o', '@OUTPUT@']}
moc_gen = build.Generator([self.moc], moc_kwargs)
moc_output = moc_gen.process_files('Qt5 moc header', moc_headers, state)
sources.append(moc_output)

@ -70,5 +70,15 @@ foreach qt : ['qt4', 'qt5']
dependencies : qtcore)
test(qt + 'maninclude', qtmaninclude)
# building Qt plugins implies to give include path to moc
plugin_includes = include_directories('pluginInterface', 'plugin')
pluginpreprocess = qtmodule.preprocess(
moc_headers : 'plugin/plugin.h',
include_directories : plugin_includes
)
plugin = library('plugin', 'plugin/plugin.cpp', pluginpreprocess,
include_directories : plugin_includes,
dependencies : qtcore)
endif
endforeach

@ -0,0 +1,7 @@
#include "plugin.h"
#include <QFile>
QString plugin1::getResource()
{
return "hello world";
}

@ -0,0 +1,11 @@
#pragma once
#include <plugin_if.h>
class plugin1:public QObject,public PluginInterface
{
Q_OBJECT
Q_INTERFACES(PluginInterface)
Q_PLUGIN_METADATA(IID "demo.PluginInterface" FILE "plugin.json")
public:
QString getResource() override;
};

@ -0,0 +1,21 @@
#ifndef PLUGIN_IF_H
#define PLUGIN_IF_H
#include <QString>
#include <QtPlugin>
/**
* @brief Interface for a plugin
*/
class PluginInterface
{
public:
virtual ~PluginInterface() = default;
/// Initializes the plugin
virtual QString getResource() = 0;
};
Q_DECLARE_INTERFACE(PluginInterface, "demo.PluginInterface")
#endif
Loading…
Cancel
Save