diff options
Diffstat (limited to 'src/tools/moc/main.cpp')
-rw-r--r-- | src/tools/moc/main.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/tools/moc/main.cpp b/src/tools/moc/main.cpp index 0c327a641f..0a10aef989 100644 --- a/src/tools/moc/main.cpp +++ b/src/tools/moc/main.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the tools applications of the Qt Toolkit. @@ -242,6 +243,11 @@ int runMoc(int argc, char **argv) metadataOption.setFlags(QCommandLineOption::ShortOptionStyle); parser.addOption(metadataOption); + QCommandLineOption compilerFlavorOption(QStringLiteral("compiler-flavor")); + compilerFlavorOption.setDescription(QStringLiteral("Set the compiler flavor: either \"msvc\" or \"unix\".")); + compilerFlavorOption.setValueName(QStringLiteral("flavor")); + parser.addOption(compilerFlavorOption); + QCommandLineOption noIncludeOption(QStringLiteral("i")); noIncludeOption.setDescription(QStringLiteral("Do not generate an #include statement.")); parser.addOption(noIncludeOption); @@ -263,6 +269,11 @@ int runMoc(int argc, char **argv) prependIncludeOption.setValueName(QStringLiteral("file")); parser.addOption(prependIncludeOption); + QCommandLineOption includeOption(QStringLiteral("include")); + includeOption.setDescription(QStringLiteral("Parse <file> as an #include before the main source(s).")); + includeOption.setValueName(QStringLiteral("file")); + parser.addOption(includeOption); + QCommandLineOption noNotesWarningsCompatOption(QStringLiteral("n")); noNotesWarningsCompatOption.setDescription(QStringLiteral("Do not display notes (-nn) or warnings (-nw). Compatibility option.")); noNotesWarningsCompatOption.setValueName(QStringLiteral("which")); @@ -323,9 +334,32 @@ int runMoc(int argc, char **argv) if (parser.isSet(pathPrefixOption)) moc.includePath = QFile::encodeName(parser.value(pathPrefixOption)); } + const auto includePaths = parser.values(includePathOption); for (const QString &path : includePaths) pp.includes += Preprocessor::IncludePath(QFile::encodeName(path)); + QString compilerFlavor = parser.value(compilerFlavorOption); + if (compilerFlavor.isEmpty() || compilerFlavor == QLatin1String("unix")) { + // traditional Unix compilers use both CPATH and CPLUS_INCLUDE_PATH + // $CPATH feeds to #include <...> and #include "...", whereas + // CPLUS_INCLUDE_PATH is equivalent to GCC's -isystem, so we parse later + const auto cpath = qgetenv("CPATH").split(QDir::listSeparator().toLatin1()); + for (const QByteArray &p : cpath) + pp.includes += Preprocessor::IncludePath(p); + const auto cplus_include_path = qgetenv("CPLUS_INCLUDE_PATH").split(QDir::listSeparator().toLatin1()); + for (const QByteArray &p : cplus_include_path) + pp.includes += Preprocessor::IncludePath(p); + } else if (compilerFlavor == QLatin1String("msvc")) { + // MSVC uses one environment variable: INCLUDE + const auto include = qgetenv("INCLUDE").split(QDir::listSeparator().toLatin1()); + for (const QByteArray &p : include) + pp.includes += Preprocessor::IncludePath(p); + } else { + error(qPrintable(QLatin1String("Unknown compiler flavor '") + compilerFlavor + + QLatin1String("'; valid values are: msvc, unix."))); + parser.showHelp(1); + } + const auto macFrameworks = parser.values(macFrameworkOption); for (const QString &path : macFrameworks) { // minimalistic framework support for the mac @@ -420,7 +454,17 @@ int runMoc(int argc, char **argv) moc.includes = pp.includes; // 1. preprocess - moc.symbols = pp.preprocessed(moc.filename, &in); + const auto includeFiles = parser.values(includeOption); + for (const QString &includeName : includeFiles) { + QByteArray rawName = pp.resolveInclude(QFile::encodeName(includeName), moc.filename); + QFile f(QFile::decodeName(rawName)); + if (f.open(QIODevice::ReadOnly)) { + moc.symbols += Symbol(0, MOC_INCLUDE_BEGIN, rawName); + moc.symbols += pp.preprocessed(rawName, &f); + moc.symbols += Symbol(0, MOC_INCLUDE_END, rawName); + } + } + moc.symbols += pp.preprocessed(moc.filename, &in); // We obviously do not support MS extensions pp.macros.remove("_MSC_EXTENSIONS"); |