forked from qt-creator/qt-creator
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.
(cherry picked from commit ca8b43f6c8)
Change-Id: If3161d712b9f6e659450a3d0647f83344e68ba5d
Task-number: QTCREATORBUG-14740
Reviewed-by: Robert Loehning <robert.loehning@theqtcompany.com>
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
@@ -233,6 +233,23 @@ FileName Environment::searchInDirectory(const QStringList &execs, QString direct
|
|||||||
return FileName();
|
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,
|
FileName Environment::searchInPath(const QString &executable,
|
||||||
const QStringList &additionalDirs) const
|
const QStringList &additionalDirs) const
|
||||||
{
|
{
|
||||||
@@ -242,27 +259,14 @@ FileName Environment::searchInPath(const QString &executable,
|
|||||||
QString exec = QDir::cleanPath(expandVariables(executable));
|
QString exec = QDir::cleanPath(expandVariables(executable));
|
||||||
QFileInfo fi(exec);
|
QFileInfo fi(exec);
|
||||||
|
|
||||||
QStringList execs(exec);
|
QStringList execs = appendExeExtensions(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(';'));
|
|
||||||
|
|
||||||
foreach (const QString &ext, extensions) {
|
|
||||||
QString tmp = executable + ext.toLower();
|
|
||||||
if (fi.isAbsolute()) {
|
if (fi.isAbsolute()) {
|
||||||
if (QFile::exists(tmp))
|
foreach (const QString &path, execs)
|
||||||
return FileName::fromString(tmp);
|
if (QFile::exists(path))
|
||||||
} else {
|
return FileName::fromString(path);
|
||||||
execs << tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fi.isAbsolute())
|
|
||||||
return FileName::fromString(exec);
|
return FileName::fromString(exec);
|
||||||
|
}
|
||||||
|
|
||||||
QSet<QString> alreadyChecked;
|
QSet<QString> alreadyChecked;
|
||||||
foreach (const QString &dir, additionalDirs) {
|
foreach (const QString &dir, additionalDirs) {
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ public:
|
|||||||
FileName searchInPath(const QString &executable,
|
FileName searchInPath(const QString &executable,
|
||||||
const QStringList &additionalDirs = QStringList()) const;
|
const QStringList &additionalDirs = QStringList()) const;
|
||||||
QStringList path() const;
|
QStringList path() const;
|
||||||
|
QStringList appendExeExtensions(const QString &executable) const;
|
||||||
|
|
||||||
QString expandVariables(const QString &input) const;
|
QString expandVariables(const QString &input) const;
|
||||||
QStringList expandVariables(const QStringList &input) const;
|
QStringList expandVariables(const QStringList &input) const;
|
||||||
|
|||||||
@@ -163,20 +163,29 @@ static void readAndDeleteLegacyCMakeSettings ()
|
|||||||
|
|
||||||
static QList<CMakeTool *> autoDetectCMakeTools()
|
static QList<CMakeTool *> autoDetectCMakeTools()
|
||||||
{
|
{
|
||||||
QStringList filters;
|
|
||||||
filters.append(QStringLiteral("cmake"));
|
|
||||||
|
|
||||||
QList<FileName> suspects;
|
QList<FileName> suspects;
|
||||||
|
|
||||||
QStringList path = Environment::systemEnvironment().path();
|
Utils::Environment env = Environment::systemEnvironment();
|
||||||
|
|
||||||
|
QStringList path = env.path();
|
||||||
path.removeDuplicates();
|
path.removeDuplicates();
|
||||||
QDir dir;
|
|
||||||
dir.setNameFilters(filters);
|
QStringList execs = env.appendExeExtensions(QLatin1String("cmake"));
|
||||||
dir.setFilter(QDir::Files | QDir::Executable);
|
|
||||||
foreach (const QString &base, path) {
|
foreach (QString base, path) {
|
||||||
dir.setPath(base);
|
const QChar slash = QLatin1Char('/');
|
||||||
foreach (const QString &entry, dir.entryList())
|
if (base.isEmpty())
|
||||||
suspects.append(FileName::fromString(dir.absoluteFilePath(entry)));
|
continue;
|
||||||
|
// Avoid turning '/' into '//' on Windows which triggers Windows to check
|
||||||
|
// for network drives!
|
||||||
|
if (!base.endsWith(slash))
|
||||||
|
base += slash;
|
||||||
|
|
||||||
|
foreach (const QString &exec, execs) {
|
||||||
|
QFileInfo fi(base + exec);
|
||||||
|
if (fi.exists() && fi.isFile() && fi.isExecutable())
|
||||||
|
suspects << FileName::fromString(fi.absoluteFilePath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<CMakeTool *> found;
|
QList<CMakeTool *> found;
|
||||||
|
|||||||
Reference in New Issue
Block a user