aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/qbs-setup-toolchains/clangclprobe.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/qbs-setup-toolchains/clangclprobe.cpp')
-rw-r--r--src/app/qbs-setup-toolchains/clangclprobe.cpp46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/app/qbs-setup-toolchains/clangclprobe.cpp b/src/app/qbs-setup-toolchains/clangclprobe.cpp
index a54705510..816d28546 100644
--- a/src/app/qbs-setup-toolchains/clangclprobe.cpp
+++ b/src/app/qbs-setup-toolchains/clangclprobe.cpp
@@ -117,6 +117,46 @@ QString findCompatibleVcsarsallBat()
return {};
}
+QString wow6432Key()
+{
+#ifdef Q_OS_WIN64
+ return QStringLiteral("\\Wow6432Node");
+#else
+ return {};
+#endif
+}
+
+QString findClangCl()
+{
+ const auto compilerName = HostOsInfo::appendExecutableSuffix(QStringLiteral("clang-cl"));
+ const auto compilerFromPath = findExecutable(compilerName);
+ if (!compilerFromPath.isEmpty())
+ return compilerFromPath;
+
+ const QSettings registry(
+ QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE%1\\LLVM\\LLVM").arg(wow6432Key()),
+ QSettings::NativeFormat);
+ const auto key = QStringLiteral(".");
+ if (registry.contains(key)) {
+ const auto compilerPath = QDir::fromNativeSeparators(registry.value(key).toString())
+ + QStringLiteral("/bin/") + compilerName;
+ if (QFileInfo(compilerPath).exists())
+ return compilerPath;
+ }
+
+ // this branch can be useful in case user had two LLVM installations (e.g. 32bit & 64bit)
+ // but uninstalled one - in that case, registry will be empty
+ static const char * const envVarCandidates[] = {"ProgramFiles", "ProgramFiles(x86)"};
+ for (const auto &envVar : envVarCandidates) {
+ const auto value
+ = QDir::fromNativeSeparators(QString::fromLocal8Bit(qgetenv(envVar)));
+ const auto compilerPath = value + QStringLiteral("/LLVM/bin/") + compilerName;
+ if (QFileInfo(compilerPath).exists())
+ return compilerPath;
+ }
+ return {};
+}
+
} // namespace
void createClangClProfile(const QFileInfo &compiler, Settings *settings,
@@ -144,12 +184,12 @@ void clangClProbe(Settings *settings, QList<Profile> &profiles)
{
const auto compilerName = QStringLiteral("clang-cl");
qbsInfo() << Tr::tr("Trying to detect %1...").arg(compilerName);
- const QFileInfo compiler = findExecutable(HostOsInfo::appendExecutableSuffix(compilerName));
- if (!compiler.exists()) {
+ const QString compilerFilePath = findClangCl();
+ if (compilerFilePath.isEmpty()) {
qbsInfo() << Tr::tr("%1 was not found.").arg(compilerName);
return;
}
-
+ const QFileInfo compiler(compilerFilePath);
const auto vcvarsallPath = findCompatibleVcsarsallBat();
if (vcvarsallPath.isEmpty()) {
qbsWarning()