diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-04-22 14:44:58 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-05-19 23:00:29 -0700 |
commit | 7932b2acbb85b516114a4062715fc23651c9bdbf (patch) | |
tree | 05386ce998c4fb6518a1037e83663bdff0e3176a /src | |
parent | c9c7b77625738f97c3d4388c30c96e597b87e96b (diff) | |
download | qtwayland-7932b2acbb85b516114a4062715fc23651c9bdbf.tar.gz |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/qtwaylandscanner/qtwaylandscanner.cpp | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/src/qtwaylandscanner/qtwaylandscanner.cpp b/src/qtwaylandscanner/qtwaylandscanner.cpp index f84673d4..c3768a63 100644 --- a/src/qtwaylandscanner/qtwaylandscanner.cpp +++ b/src/qtwaylandscanner/qtwaylandscanner.cpp @@ -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"); |