configure.exe: Write MSVC compiler version to qconfig.pri

Backport a feature of the new configure system setting the
variables QT_CL_MAJOR_VERSION, QT_CL_MINOR_VERSION,
QT_CL_PATCH_VERSION similarly to the existing variables for gcc.
This allows for disabling optimizations depending on the compiler
version.

Task-number: QTBUG-55238
Change-Id: If2349b008c1049e2ab98a5c1160b244a6e8937a8
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2016-09-01 10:48:06 +02:00 committed by Simon Hausmann
parent 8d8c7b31ba
commit 5971b88ecd
3 changed files with 35 additions and 0 deletions

View File

@ -314,6 +314,12 @@ Configure::Configure(int& argc, char** argv) : verbose(0)
dictionary["QT_GCC_MAJOR_VERSION"] = parts.value(0, zero); dictionary["QT_GCC_MAJOR_VERSION"] = parts.value(0, zero);
dictionary["QT_GCC_MINOR_VERSION"] = parts.value(1, zero); dictionary["QT_GCC_MINOR_VERSION"] = parts.value(1, zero);
dictionary["QT_GCC_PATCH_VERSION"] = parts.value(2, zero); dictionary["QT_GCC_PATCH_VERSION"] = parts.value(2, zero);
} else if (dictionary["QMAKESPEC"].contains(QString("msvc"))) {
const QString zero = QStringLiteral("0");
const QStringList parts = Environment::msvcVersion().split(QLatin1Char('.'));
dictionary["QT_CL_MAJOR_VERSION"] = parts.value(0, zero);
dictionary["QT_CL_MINOR_VERSION"] = parts.value(1, zero);
dictionary["QT_CL_PATCH_VERSION"] = parts.value(2, zero);
} }
} }
@ -3629,6 +3635,10 @@ void Configure::generateQConfigPri()
configStream << "QT_GCC_MAJOR_VERSION = " << dictionary["QT_GCC_MAJOR_VERSION"] << endl configStream << "QT_GCC_MAJOR_VERSION = " << dictionary["QT_GCC_MAJOR_VERSION"] << endl
<< "QT_GCC_MINOR_VERSION = " << dictionary["QT_GCC_MINOR_VERSION"] << endl << "QT_GCC_MINOR_VERSION = " << dictionary["QT_GCC_MINOR_VERSION"] << endl
<< "QT_GCC_PATCH_VERSION = " << dictionary["QT_GCC_PATCH_VERSION"] << endl; << "QT_GCC_PATCH_VERSION = " << dictionary["QT_GCC_PATCH_VERSION"] << endl;
} else if (!dictionary["QT_CL_MAJOR_VERSION"].isEmpty()) {
configStream << "QT_CL_MAJOR_VERSION = " << dictionary["QT_CL_MAJOR_VERSION"] << endl
<< "QT_CL_MINOR_VERSION = " << dictionary["QT_CL_MINOR_VERSION"] << endl
<< "QT_CL_PATCH_VERSION = " << dictionary["QT_CL_PATCH_VERSION"] << endl;
} }
if (dictionary.value("XQMAKESPEC").startsWith("wince")) { if (dictionary.value("XQMAKESPEC").startsWith("wince")) {

View File

@ -169,6 +169,30 @@ QString Environment::gccVersion()
return version; return version;
} }
QString Environment::msvcVersion()
{
int returnValue = 0;
// Extract version from standard error output of "cl /?"
const QString command = QFile::decodeName(qgetenv("ComSpec"))
+ QLatin1String(" /c ") + QLatin1String(compilerInfo(CC_MSVC2015)->executable)
+ QLatin1String(" /? 2>&1");
QString version = execute(command, &returnValue);
if (returnValue != 0) {
cout << "Could not get cl version" << returnValue << qPrintable(version) << '\n';;
version.clear();
} else {
QRegExp versionRegexp(QStringLiteral("^.*Compiler Version ([0-9.]+) for.*$"));
Q_ASSERT(versionRegexp.isValid());
if (versionRegexp.exactMatch(version)) {
version = versionRegexp.cap(1);
} else {
cout << "Unable to determine cl version from the output of \""
<< qPrintable(command) << "\"\n";
}
}
return version;
}
/*! /*!
Returns the enum of the compiler which was detected on the system. Returns the enum of the compiler which was detected on the system.
The compilers are detected in the order as entered into the The compilers are detected in the order as entered into the

View File

@ -57,6 +57,7 @@ public:
static QString detectQMakeSpec(); static QString detectQMakeSpec();
static Compiler compilerFromQMakeSpec(const QString &qmakeSpec); static Compiler compilerFromQMakeSpec(const QString &qmakeSpec);
static QString gccVersion(); static QString gccVersion();
static QString msvcVersion();
static int execute(QStringList arguments, const QStringList &additionalEnv, const QStringList &removeEnv); static int execute(QStringList arguments, const QStringList &additionalEnv, const QStringList &removeEnv);
static QString execute(const QString &command, int *returnCode = 0); static QString execute(const QString &command, int *returnCode = 0);