diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2016-04-13 17:25:37 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2016-07-20 02:54:09 +0000 |
commit | da04322b4c429de9a6f5aa06545c10284ec2e56d (patch) | |
tree | 772dd5a5fa5d93df2dfceec0c767c8b2d0f7eb6b /tests/auto/tools | |
parent | 36d524e6a3b64a8c35805c1b868d6d67ccae765c (diff) |
Make moc obey the preprocessor environment variable for include paths
C preprocessors augment their standard list of include paths from the
environment: Unix preprocessors use $C_INCLUDE_PATH (for C) and
$CPLUS_INCLUDE_PATH (for C++), plus CPATH for both, whereas MSVC uses
the an environment variable simply called "INCLUDE". Handling this for
MSVC is particularly important because the VCVARSALL.BAT script sets the
necessary #include paths in the environment for important things.
Without that being parsed, moc won't find some #defines, like
WINAPI_DESKTOP_FAMILY.
[ChangeLog][moc] qmake and moc now cooperate to use the Visual Studio
environment variables (set by the VCVARSALL.BAT script) to find system
include files. A possible consequence is that moc parses application
headers slightly differently, depending on #if conditions that depended
on macros that previous versions had not seen #define'd. Implementers of
other buildsystems are advised to pass the --compiler-flavor=msvc option
to moc.
Change-Id: I7e06274214d1939b0124e5b4bf169cceaef9ca46
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/tools')
-rw-r--r-- | tests/auto/tools/moc/tst_moc.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 1cf6f94720..ab15f81939 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -577,6 +577,8 @@ private slots: void defineMacroViaCmdline(); void defineMacroViaForcedInclude(); void defineMacroViaForcedIncludeRelative(); + void environmentIncludePaths_data(); + void environmentIncludePaths(); void specifyMetaTagsFromCmdline(); void invokable(); void singleFunctionKeywordSignalAndSlot(); @@ -1295,6 +1297,52 @@ void tst_Moc::defineMacroViaForcedIncludeRelative() #endif } + +void tst_Moc::environmentIncludePaths_data() +{ +#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) + QTest::addColumn<QString>("cmdline"); + QTest::addColumn<QString>("varname"); + + QTest::newRow("INCLUDE") << "--compiler-flavor=msvc" << "INCLUDE"; + QTest::newRow("CPATH1") << QString() << "CPATH"; + QTest::newRow("CPATH2") << "--compiler-flavor=unix" << "CPATH"; + QTest::newRow("CPLUS_INCLUDE_PATH1") << QString() << "CPLUS_INCLUDE_PATH"; + QTest::newRow("CPLUS_INCLUDE_PATH2") << "--compiler-flavor=unix" << "CPLUS_INCLUDE_PATH"; +#endif +} + +void tst_Moc::environmentIncludePaths() +{ +#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) + QFETCH(QString, cmdline); + QFETCH(QString, varname); + + QStringList args; + if (!cmdline.isEmpty()) + args << cmdline; + args << "--include" << QStringLiteral("extradefines.h") + << m_sourceDirectory + QStringLiteral("/macro-on-cmdline.h"); + + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + env.remove("INCLUDE"); + env.remove("CPATH"); + env.remove("CPLUS_INCLUDE_PATH"); + env.insert(varname, m_sourceDirectory + "/subdir"); + + QProcess proc; + proc.setProcessEnvironment(env); + 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: |