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:
Thiago Macieira 2022-04-22 14:44:58 -07:00
parent 38d6f09d30
commit 949b3f731c

View File

@ -123,6 +123,7 @@ private:
QByteArray m_scannerName; QByteArray m_scannerName;
QByteArray m_headerPath; QByteArray m_headerPath;
QByteArray m_prefix; QByteArray m_prefix;
QByteArray m_buildMacro;
QList <QByteArray> m_includes; QList <QByteArray> m_includes;
QXmlStreamReader *m_xml = nullptr; QXmlStreamReader *m_xml = nullptr;
}; };
@ -156,6 +157,8 @@ bool Scanner::parseArguments(int argc, char **argv)
m_headerPath = option.mid(14); m_headerPath = option.mid(14);
} else if (option.startsWith("--prefix=")) { } else if (option.startsWith("--prefix=")) {
m_prefix = option.mid(10); m_prefix = option.mid(10);
} else if (option.startsWith("--build-macro=")) {
m_buildMacro = option.mid(14);
} else if (option.startsWith("--add-include=")) { } else if (option.startsWith("--add-include=")) {
auto include = option.mid(14); auto include = option.mid(14);
if (!include.isEmpty()) if (!include.isEmpty())
@ -473,6 +476,26 @@ bool Scanner::process()
for (auto b : qAsConst(m_includes)) for (auto b : qAsConst(m_includes))
printf("#include %s\n", b.constData()); 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) { if (m_option == ServerHeader) {
QByteArray inclusionGuard = QByteArray("QT_WAYLAND_SERVER_") + preProcessorProtocolName.constData(); QByteArray inclusionGuard = QByteArray("QT_WAYLAND_SERVER_") + preProcessorProtocolName.constData();
printf("#ifndef %s\n", inclusionGuard.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_GCC(\"-Wmissing-field-initializers\")\n");
printf("QT_WARNING_DISABLE_CLANG(\"-Wmissing-field-initializers\")\n"); printf("QT_WARNING_DISABLE_CLANG(\"-Wmissing-field-initializers\")\n");
QByteArray serverExport; QByteArray serverExport;
if (m_headerPath.size()) { if (m_headerPath.size())
serverExport = QByteArray("Q_WAYLAND_SERVER_") + preProcessorProtocolName + "_EXPORT"; serverExport = printExportMacro("Q_WAYLAND_SERVER_", preProcessorProtocolName);
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");
}
printf("\n"); printf("\n");
printf("namespace QtWaylandServer {\n"); printf("namespace QtWaylandServer {\n");
@ -996,18 +1010,9 @@ bool Scanner::process()
printf("QT_WARNING_DISABLE_GCC(\"-Wmissing-field-initializers\")\n"); printf("QT_WARNING_DISABLE_GCC(\"-Wmissing-field-initializers\")\n");
QByteArray clientExport; 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("\n");
printf("namespace QtWayland {\n"); printf("namespace QtWayland {\n");