qtwaylandscanner: add a way to use an build macro in the generated code
Change-Id: If05aeeb7176e4f13af9afffd16e85611ff7c42f2 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
parent
38d6f09d30
commit
949b3f731c
@ -123,6 +123,7 @@ private:
|
||||
QByteArray m_scannerName;
|
||||
QByteArray m_headerPath;
|
||||
QByteArray m_prefix;
|
||||
QByteArray m_buildMacro;
|
||||
QList <QByteArray> m_includes;
|
||||
QXmlStreamReader *m_xml = nullptr;
|
||||
};
|
||||
@ -156,6 +157,8 @@ bool Scanner::parseArguments(int argc, char **argv)
|
||||
m_headerPath = option.mid(14);
|
||||
} else if (option.startsWith("--prefix=")) {
|
||||
m_prefix = option.mid(10);
|
||||
} else if (option.startsWith("--build-macro=")) {
|
||||
m_buildMacro = option.mid(14);
|
||||
} else if (option.startsWith("--add-include=")) {
|
||||
auto include = option.mid(14);
|
||||
if (!include.isEmpty())
|
||||
@ -473,6 +476,26 @@ bool Scanner::process()
|
||||
for (auto b : qAsConst(m_includes))
|
||||
printf("#include %s\n", b.constData());
|
||||
|
||||
auto printExportMacro = [this](const char *prefix, const QByteArray &preProcessorProtocolName) {
|
||||
QByteArray exportMacro = prefix + preProcessorProtocolName + "_EXPORT";
|
||||
printf("#if !defined(%s)\n", exportMacro.constData());
|
||||
printf("# if defined(QT_SHARED) && !defined(QT_STATIC)\n");
|
||||
if (m_buildMacro.isEmpty()) {
|
||||
printf("# define %s Q_DECL_EXPORT\n", exportMacro.constData());
|
||||
} else {
|
||||
printf("# if defined(%s)\n", m_buildMacro.constData());
|
||||
printf("# define %s Q_DECL_EXPORT\n", exportMacro.constData());
|
||||
printf("# else\n");
|
||||
printf("# define %s Q_DECL_IMPORT\n", exportMacro.constData());
|
||||
printf("# endif\n");
|
||||
}
|
||||
printf("# else\n");
|
||||
printf("# define %s\n", exportMacro.constData());
|
||||
printf("# endif\n");
|
||||
printf("#endif\n");
|
||||
return exportMacro;
|
||||
};
|
||||
|
||||
if (m_option == ServerHeader) {
|
||||
QByteArray inclusionGuard = QByteArray("QT_WAYLAND_SERVER_") + preProcessorProtocolName.constData();
|
||||
printf("#ifndef %s\n", inclusionGuard.constData());
|
||||
@ -501,17 +524,8 @@ bool Scanner::process()
|
||||
printf("QT_WARNING_DISABLE_GCC(\"-Wmissing-field-initializers\")\n");
|
||||
printf("QT_WARNING_DISABLE_CLANG(\"-Wmissing-field-initializers\")\n");
|
||||
QByteArray serverExport;
|
||||
if (m_headerPath.size()) {
|
||||
serverExport = QByteArray("Q_WAYLAND_SERVER_") + preProcessorProtocolName + "_EXPORT";
|
||||
printf("\n");
|
||||
printf("#if !defined(%s)\n", serverExport.constData());
|
||||
printf("# if defined(QT_SHARED)\n");
|
||||
printf("# define %s Q_DECL_EXPORT\n", serverExport.constData());
|
||||
printf("# else\n");
|
||||
printf("# define %s\n", serverExport.constData());
|
||||
printf("# endif\n");
|
||||
printf("#endif\n");
|
||||
}
|
||||
if (m_headerPath.size())
|
||||
serverExport = printExportMacro("Q_WAYLAND_SERVER_", preProcessorProtocolName);
|
||||
printf("\n");
|
||||
printf("namespace QtWaylandServer {\n");
|
||||
|
||||
@ -996,18 +1010,9 @@ bool Scanner::process()
|
||||
printf("QT_WARNING_DISABLE_GCC(\"-Wmissing-field-initializers\")\n");
|
||||
|
||||
QByteArray clientExport;
|
||||
if (m_headerPath.size())
|
||||
clientExport = printExportMacro("Q_WAYLAND_CLIENT_", preProcessorProtocolName);
|
||||
|
||||
if (m_headerPath.size()) {
|
||||
clientExport = QByteArray("Q_WAYLAND_CLIENT_") + preProcessorProtocolName + "_EXPORT";
|
||||
printf("\n");
|
||||
printf("#if !defined(%s)\n", clientExport.constData());
|
||||
printf("# if defined(QT_SHARED)\n");
|
||||
printf("# define %s Q_DECL_EXPORT\n", clientExport.constData());
|
||||
printf("# else\n");
|
||||
printf("# define %s\n", clientExport.constData());
|
||||
printf("# endif\n");
|
||||
printf("#endif\n");
|
||||
}
|
||||
printf("\n");
|
||||
printf("namespace QtWayland {\n");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user