summaryrefslogtreecommitdiffstats
path: root/tests/auto/tools/moc
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2015-08-21 17:08:19 -0700
committerThiago Macieira <thiago.macieira@intel.com>2016-07-20 02:54:03 +0000
commit36d524e6a3b64a8c35805c1b868d6d67ccae765c (patch)
tree56a864ba56b3426f17cb202d4d8bbc9e9912aa55 /tests/auto/tools/moc
parent23bf3da5a0767f0c54824b4db1ecf23edeb71e91 (diff)
moc: get the system #defines from the compiler itself
In order for moc to properly parse #ifdefs and family, we've had QMAKE_COMPILER_DEFINES as a list of pre-defined macros from the compiler. That list is woefully incomplete. Instead, let's simply ask the compiler for the list. With GCC and family, we use the -dM flag while preprocessing. With ICC on Windows, the flag gains an extra "Q" but is otherwise the same. For MSVC, it requires using some undocumented switches and parsing environment variables (I've tested MSVC 2012, 2013 and 2015). The new moc option is called --include to be similar to GCC's -include option. It does more than just parse a list of pre-defined macros and can be used to insert any sort of code that moc needs to parse prior to the main file. Change-Id: I7de033f80b0e4431b7f1ffff13fca02dbb60a0a6 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/tools/moc')
-rw-r--r--tests/auto/tools/moc/subdir/extradefines.h1
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp42
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/tools/moc/subdir/extradefines.h b/tests/auto/tools/moc/subdir/extradefines.h
new file mode 100644
index 0000000000..e7888ce80d
--- /dev/null
+++ b/tests/auto/tools/moc/subdir/extradefines.h
@@ -0,0 +1 @@
+#define FOO 1
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index 9fdd37ea9b..1cf6f94720 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -575,6 +575,8 @@ private slots:
void frameworkSearchPath();
void cstyleEnums();
void defineMacroViaCmdline();
+ void defineMacroViaForcedInclude();
+ void defineMacroViaForcedIncludeRelative();
void specifyMetaTagsFromCmdline();
void invokable();
void singleFunctionKeywordSignalAndSlot();
@@ -1253,6 +1255,46 @@ void tst_Moc::defineMacroViaCmdline()
#endif
}
+void tst_Moc::defineMacroViaForcedInclude()
+{
+#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
+ QProcess proc;
+
+ QStringList args;
+ args << "--include" << m_sourceDirectory + QLatin1String("/subdir/extradefines.h");
+ args << m_sourceDirectory + QStringLiteral("/macro-on-cmdline.h");
+
+ proc.start(m_moc, args);
+ QVERIFY(proc.waitForFinished());
+ QCOMPARE(proc.exitCode(), 0);
+ QCOMPARE(proc.readAllStandardError(), QByteArray());
+ QByteArray mocOut = proc.readAllStandardOutput();
+ QVERIFY(!mocOut.isEmpty());
+#else
+ QSKIP("Only tested on linux/gcc");
+#endif
+}
+
+void tst_Moc::defineMacroViaForcedIncludeRelative()
+{
+#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS)
+ QProcess proc;
+
+ QStringList args;
+ args << "--include" << QStringLiteral("extradefines.h") << "-I" + m_sourceDirectory + "/subdir";
+ args << m_sourceDirectory + QStringLiteral("/macro-on-cmdline.h");
+
+ proc.start(m_moc, args);
+ QVERIFY(proc.waitForFinished());
+ QCOMPARE(proc.exitCode(), 0);
+ QCOMPARE(proc.readAllStandardError(), QByteArray());
+ QByteArray mocOut = proc.readAllStandardOutput();
+ QVERIFY(!mocOut.isEmpty());
+#else
+ QSKIP("Only tested on linux/gcc");
+#endif
+}
+
// tst_Moc::specifyMetaTagsFromCmdline()
// plugin_metadata.h contains a plugin which we register here. Since we're not building this
// application as a plugin, we need top copy some of the initializer code found in qplugin.h: