diff --git a/src/plugins/projectexplorer/kitinformation.cpp b/src/plugins/projectexplorer/kitinformation.cpp index 3c4c4b76d2f..f340f086dc2 100644 --- a/src/plugins/projectexplorer/kitinformation.cpp +++ b/src/plugins/projectexplorer/kitinformation.cpp @@ -410,6 +410,54 @@ void ToolChainKitInformation::setToolChain(Kit *k, ToolChain *tc) k->setValue(id(), result); } +/** + * @brief ToolChainKitInformation::setAllToolChainsToMatch + * + * Set up all toolchains to be similar to the one toolchain provided. Similar ideally means + * that all toolchains use the "same" compiler from the same installation, but we will + * settle for a toolchain with a matching API instead. + * + * @param k The kit to set up + * @param tc The toolchain to match other languages for. + */ +void ToolChainKitInformation::setAllToolChainsToMatch(Kit *k, ToolChain *tc) +{ + QTC_ASSERT(tc, return); + + const QList allTcList = ToolChainManager::toolChains(); + QTC_ASSERT(allTcList.contains(tc), return); + + QVariantMap result = k->value(ToolChainKitInformation::id()).toMap(); + result.insert(tc->language().toString(), tc->id()); + + for (Core::Id l : ToolChainManager::allLanguages()) { + if (l == tc->language()) + continue; + + ToolChain *match = nullptr; + ToolChain *bestMatch = nullptr; + for (ToolChain *other : allTcList) { + if (!other->isValid() || other->language() != l) + continue; + if (other->targetAbi() == tc->targetAbi()) + match = other; + if (match == other + && other->compilerCommand().parentDir() == tc->compilerCommand().parentDir()) { + bestMatch = other; + break; + } + } + if (bestMatch) + result.insert(l.toString(), bestMatch->id()); + else if (match) + result.insert(l.toString(), match->id()); + else + result.insert(l.toString(), QByteArray()); + } + + k->setValue(id(), result); +} + void ToolChainKitInformation::clearToolChain(Kit *k, Core::Id language) { QTC_ASSERT(language.isValid(), return); diff --git a/src/plugins/projectexplorer/kitinformation.h b/src/plugins/projectexplorer/kitinformation.h index febd91ec58f..d4defd96d46 100644 --- a/src/plugins/projectexplorer/kitinformation.h +++ b/src/plugins/projectexplorer/kitinformation.h @@ -98,6 +98,7 @@ public: static ToolChain *toolChain(const Kit *k, Core::Id language); static QList toolChains(const Kit *k); static void setToolChain(Kit *k, ToolChain *tc); + static void setAllToolChainsToMatch(Kit *k, ToolChain *tc); static void clearToolChain(Kit *k, Core::Id language); static Abi targetAbi(const Kit *k); diff --git a/src/plugins/qmakeprojectmanager/qmakekitinformation.cpp b/src/plugins/qmakeprojectmanager/qmakekitinformation.cpp index 3420fca5109..268b01dbc20 100644 --- a/src/plugins/qmakeprojectmanager/qmakekitinformation.cpp +++ b/src/plugins/qmakeprojectmanager/qmakekitinformation.cpp @@ -95,7 +95,7 @@ void QmakeKitInformation::setup(Kit *k) = Utils::findOr(possibleTcs, possibleTcs.last(), [&spec](const ToolChain *t) { return t->suggestedMkspecList().contains(spec); }); if (possibleTc) - ToolChainKitInformation::setToolChain(k, possibleTc); + ToolChainKitInformation::setAllToolChainsToMatch(k, possibleTc); } } }