Commit 902db4fa authored by Daniel Teske's avatar Daniel Teske
Browse files

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 ca8b43f6

Change-Id: If3161d712b9f6e659450a3d0647f83344e68ba5d
Task-number: QTCREATORBUG-14740
Reviewed-by: default avatarRobert Loehning <>
Reviewed-by: default avatarDaniel Teske <>
parent e5f76153
......@@ -233,36 +233,40 @@ FileName Environment::searchInDirectory(const QStringList &execs, QString direct
return FileName();
FileName Environment::searchInPath(const QString &executable,
const QStringList &additionalDirs) const
QStringList Environment::appendExeExtensions(const QString &executable) const
if (executable.isEmpty())
return FileName();
QString exec = QDir::cleanPath(expandVariables(executable));
QFileInfo fi(exec);
QStringList execs(exec);
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) {
QString tmp = executable + ext.toLower();
if (fi.isAbsolute()) {
if (QFile::exists(tmp))
return FileName::fromString(tmp);
} else {
execs << tmp;
foreach (const QString &ext, extensions)
execs << executable + ext.toLower();
return execs;
if (fi.isAbsolute())
FileName Environment::searchInPath(const QString &executable,
const QStringList &additionalDirs) const
if (executable.isEmpty())
return FileName();
QString exec = QDir::cleanPath(expandVariables(executable));
QFileInfo fi(exec);
QStringList execs = appendExeExtensions(exec);
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) {
......@@ -105,6 +105,7 @@ public:
FileName searchInPath(const QString &executable,
const QStringList &additionalDirs = QStringList()) const;
QStringList path() const;
QStringList appendExeExtensions(const QString &executable) const;
QString expandVariables(const QString &input) const;
QStringList expandVariables(const QStringList &input) const;
......@@ -163,20 +163,29 @@ static void readAndDeleteLegacyCMakeSettings ()
static QList<CMakeTool *> autoDetectCMakeTools()
QStringList filters;
QList<FileName> suspects;
QStringList path = Environment::systemEnvironment().path();
Utils::Environment env = Environment::systemEnvironment();
QStringList path = env.path();
QDir dir;
dir.setFilter(QDir::Files | QDir::Executable);
foreach (const QString &base, path) {
foreach (const QString &entry, dir.entryList())
QStringList execs = env.appendExeExtensions(QLatin1String("cmake"));
foreach (QString base, path) {
const QChar slash = QLatin1Char('/');
if (base.isEmpty())
// 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;
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