Commit ea1efad6 authored by Christian Kandeler's avatar Christian Kandeler

CppTools: Support MSVC in CompilerOptionsBuilder.

Needed for clang static analyzer.

Change-Id: I0221b7e87f7b52a4aa5ebf7f4b26c19e584d63e7
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent f5a3c7cf
...@@ -473,9 +473,11 @@ void ProjectPartBuilder::createProjectPart(const QStringList &theSources, ...@@ -473,9 +473,11 @@ void ProjectPartBuilder::createProjectPart(const QStringList &theSources,
QStringList CompilerOptionsBuilder::createHeaderPathOptions( QStringList CompilerOptionsBuilder::createHeaderPathOptions(
const ProjectPart::HeaderPaths &headerPaths, const ProjectPart::HeaderPaths &headerPaths,
IsBlackListed isBlackListed) IsBlackListed isBlackListed, const QString &toolchainType)
{ {
typedef ProjectPart::HeaderPath HeaderPath; typedef ProjectPart::HeaderPath HeaderPath;
const QString defaultPrefix
= QLatin1String(toolchainType == QLatin1String("msvc") ? "/I" : "-I");
QStringList result; QStringList result;
...@@ -494,7 +496,7 @@ QStringList CompilerOptionsBuilder::createHeaderPathOptions( ...@@ -494,7 +496,7 @@ QStringList CompilerOptionsBuilder::createHeaderPathOptions(
default: // This shouldn't happen, but let's be nice..: default: // This shouldn't happen, but let's be nice..:
// intentional fall-through: // intentional fall-through:
case HeaderPath::IncludePath: case HeaderPath::IncludePath:
prefix = QLatin1String("-I"); prefix = defaultPrefix;
break; break;
} }
...@@ -505,9 +507,11 @@ QStringList CompilerOptionsBuilder::createHeaderPathOptions( ...@@ -505,9 +507,11 @@ QStringList CompilerOptionsBuilder::createHeaderPathOptions(
} }
QStringList CompilerOptionsBuilder::createDefineOptions(const QByteArray &defines, QStringList CompilerOptionsBuilder::createDefineOptions(const QByteArray &defines,
bool toolchainDefines) bool toolchainDefines,
const QString &toolchainType)
{ {
QStringList result; QStringList result;
const QString option = QLatin1String(toolchainType == QLatin1String("msvc") ? "/D" : "-D");
foreach (QByteArray def, defines.split('\n')) { foreach (QByteArray def, defines.split('\n')) {
if (def.isEmpty()) if (def.isEmpty())
...@@ -533,9 +537,9 @@ QStringList CompilerOptionsBuilder::createDefineOptions(const QByteArray &define ...@@ -533,9 +537,9 @@ QStringList CompilerOptionsBuilder::createDefineOptions(const QByteArray &define
int spaceIdx = str.indexOf(' '); int spaceIdx = str.indexOf(' ');
QString arg; QString arg;
if (spaceIdx != -1) { if (spaceIdx != -1) {
arg = QLatin1String("-D" + str.left(spaceIdx) + "=" + str.mid(spaceIdx + 1)); arg = option + QLatin1String(str.left(spaceIdx) + "=" + str.mid(spaceIdx + 1));
} else { } else {
arg = QLatin1String("-D" + str); arg = option + QLatin1String(str);
} }
arg = arg.replace(QLatin1String("\\\""), QLatin1String("\"")); arg = arg.replace(QLatin1String("\\\""), QLatin1String("\""));
arg = arg.replace(QLatin1String("\""), QLatin1String("")); arg = arg.replace(QLatin1String("\""), QLatin1String(""));
...@@ -546,7 +550,7 @@ QStringList CompilerOptionsBuilder::createDefineOptions(const QByteArray &define ...@@ -546,7 +550,7 @@ QStringList CompilerOptionsBuilder::createDefineOptions(const QByteArray &define
return result; return result;
} }
QStringList CompilerOptionsBuilder::createLanguageOption(ProjectFile::Kind fileKind, bool objcExt) static QStringList createLanguageOptionGcc(ProjectFile::Kind fileKind, bool objcExt)
{ {
QStringList opts; QStringList opts;
opts += QLatin1String("-x"); opts += QLatin1String("-x");
...@@ -599,12 +603,40 @@ QStringList CompilerOptionsBuilder::createLanguageOption(ProjectFile::Kind fileK ...@@ -599,12 +603,40 @@ QStringList CompilerOptionsBuilder::createLanguageOption(ProjectFile::Kind fileK
return opts; return opts;
} }
static QStringList createLanguageOptionMsvc(ProjectFile::Kind fileKind)
{
QStringList opts;
switch (fileKind) {
case ProjectFile::CHeader:
case ProjectFile::CSource:
opts << QLatin1String("/TC");
break;
case ProjectFile::CXXHeader:
case ProjectFile::CXXSource:
opts << QLatin1String("/TP");
break;
default:
break;
}
return opts;
}
QStringList CompilerOptionsBuilder::createLanguageOption(ProjectFile::Kind fileKind, bool objcExt,
const QString &toolchainType)
{
return toolchainType == QLatin1String("msvc") ? createLanguageOptionMsvc(fileKind)
: createLanguageOptionGcc(fileKind, objcExt);
}
QStringList CompilerOptionsBuilder::createOptionsForLanguage( QStringList CompilerOptionsBuilder::createOptionsForLanguage(
ProjectPart::LanguageVersion languageVersion, ProjectPart::LanguageVersion languageVersion,
ProjectPart::LanguageExtensions languageExtensions, ProjectPart::LanguageExtensions languageExtensions,
bool checkForBorlandExtensions) bool checkForBorlandExtensions,
const QString &toolchainType)
{ {
QStringList opts; QStringList opts;
if (toolchainType == QLatin1String("msvc"))
return opts;
bool gnuExtensions = languageExtensions & ProjectPart::GnuExtensions; bool gnuExtensions = languageExtensions & ProjectPart::GnuExtensions;
switch (languageVersion) { switch (languageVersion) {
case ProjectPart::C89: case ProjectPart::C89:
......
...@@ -208,15 +208,19 @@ class CPPTOOLS_EXPORT CompilerOptionsBuilder ...@@ -208,15 +208,19 @@ class CPPTOOLS_EXPORT CompilerOptionsBuilder
public: public:
typedef std::function<bool (const QString &)> IsBlackListed; typedef std::function<bool (const QString &)> IsBlackListed;
static QStringList createHeaderPathOptions(const ProjectPart::HeaderPaths &headerPaths, static QStringList createHeaderPathOptions(const ProjectPart::HeaderPaths &headerPaths,
IsBlackListed isBlackListed = IsBlackListed()); IsBlackListed isBlackListed = IsBlackListed(),
const QString &toolchainType = QLatin1String("clang"));
static QStringList createDefineOptions(const QByteArray &defines, static QStringList createDefineOptions(const QByteArray &defines,
bool toolchainDefines = false); bool toolchainDefines = false,
const QString &toolchainType = QLatin1String("clang"));
static QStringList createLanguageOption(ProjectFile::Kind fileKind, bool objcExt); static QStringList createLanguageOption(ProjectFile::Kind fileKind, bool objcExt,
const QString &toolchainType = QLatin1String("clang"));
static QStringList createOptionsForLanguage(ProjectPart::LanguageVersion languageVersion, static QStringList createOptionsForLanguage(ProjectPart::LanguageVersion languageVersion,
ProjectPart::LanguageExtensions languageExtensions, ProjectPart::LanguageExtensions languageExtensions,
bool checkForBorlandExtensions = true); bool checkForBorlandExtensions = true,
const QString &toolchainType = QLatin1String("clang"));
}; };
} // namespace CppTools } // namespace CppTools
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment