Cmake: Fix autodetection of cmake on Windows

By using some of the infrastructure in Utils::Environment. Due to
wanting to find all cmake executables in PATH and not just the
first one, we need some custom code.

Change-Id: If3161d712b9f6e659450a3d0647f83344e68ba5d
Task-number: QTCREATORBUG-14740
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Benjamin Zeller <benjamin.zeller@canonical.com>
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
Daniel Teske
2015-07-15 14:21:45 +02:00
parent b927391e5b
commit ca8b43f6c8
3 changed files with 44 additions and 30 deletions

View File

@@ -233,6 +233,23 @@ FileName Environment::searchInDirectory(const QStringList &execs, QString direct
return FileName();
}
QStringList Environment::appendExeExtensions(const QString &executable) const
{
QFileInfo fi(executable);
QStringList execs(executable);
if (m_osType == OsTypeWindows) {
// Check all the executable extensions on windows:
// PATHEXT is only used if the executable has no extension
if (fi.suffix().isEmpty()) {
QStringList extensions = value(QLatin1String("PATHEXT")).split(QLatin1Char(';'));
foreach (const QString &ext, extensions)
execs << executable + ext.toLower();
}
}
return execs;
}
FileName Environment::searchInPath(const QString &executable,
const QStringList &additionalDirs) const
{
@@ -242,27 +259,14 @@ FileName Environment::searchInPath(const QString &executable,
QString exec = QDir::cleanPath(expandVariables(executable));
QFileInfo fi(exec);
QStringList execs(exec);
if (m_osType == OsTypeWindows) {
// Check all the executable extensions on windows:
// PATHEXT is only used if the executable has no extension
if (fi.suffix().isEmpty()) {
QStringList extensions = value(QLatin1String("PATHEXT")).split(QLatin1Char(';'));
QStringList execs = appendExeExtensions(exec);
foreach (const QString &ext, extensions) {
QString tmp = executable + ext.toLower();
if (fi.isAbsolute()) {
if (QFile::exists(tmp))
return FileName::fromString(tmp);
} else {
execs << tmp;
}
}
}
}
if (fi.isAbsolute())
if (fi.isAbsolute()) {
foreach (const QString &path, execs)
if (QFile::exists(path))
return FileName::fromString(path);
return FileName::fromString(exec);
}
QSet<QString> alreadyChecked;
foreach (const QString &dir, additionalDirs) {