ProjectExplorer: Introduce ToolChainKitAspect::{c,cxx}ToolChain

Special accessors to the repeatedly used C and C++ cases to denoise
and slim down user code.  Plus some code cosmetics nearby.

Change-Id: Iba4662bd4731d8c4256e658529f39d5c995691ce
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2020-02-18 18:25:26 +01:00
parent 57662de841
commit 3f68292dbe
32 changed files with 97 additions and 103 deletions

View File

@@ -69,10 +69,10 @@ BuildDirParameters::BuildDirParameters(CMakeBuildConfiguration *bc)
cmakeToolId = CMakeKitAspect::cmakeToolId(k);
auto tc = ToolChainKitAspect::toolChain(k, Constants::CXX_LANGUAGE_ID);
auto tc = ToolChainKitAspect::cxxToolChain(k);
if (tc)
cxxToolChainId = tc->id();
tc = ToolChainKitAspect::toolChain(k, Constants::C_LANGUAGE_ID);
tc = ToolChainKitAspect::cToolChain(k);
if (tc)
cToolChainId = tc->id();
sysRoot = SysRootKitAspect::sysRoot(k);

View File

@@ -88,9 +88,7 @@ CMakeBuildConfiguration::CMakeBuildConfiguration(Target *target, Core::Id id)
const QString sysRoot = SysRootKitAspect::sysRoot(k).toString();
if (!sysRoot.isEmpty()) {
config.append(CMakeConfigItem("CMAKE_SYSROOT", sysRoot.toUtf8()));
ToolChain *tc = ToolChainKitAspect::toolChain(k,
ProjectExplorer::Constants::CXX_LANGUAGE_ID);
if (tc) {
if (ToolChain *tc = ToolChainKitAspect::cxxToolChain(k)) {
const QByteArray targetTriple = tc->originalTargetTriple().toUtf8();
config.append(CMakeConfigItem("CMAKE_C_COMPILER_TARGET", targetTriple));
config.append(CMakeConfigItem("CMAKE_CXX_COMPILER_TARGET ", targetTriple));

View File

@@ -621,7 +621,7 @@ QVariant CMakeGeneratorKitAspect::defaultValue(const Kit *k) const
if (Utils::HostOsInfo::isWindowsHost()) {
// *sigh* Windows with its zoo of incompatible stuff again...
ToolChain *tc = ToolChainKitAspect::toolChain(k, ProjectExplorer::Constants::CXX_LANGUAGE_ID);
ToolChain *tc = ToolChainKitAspect::cxxToolChain(k);
if (tc && tc->typeId() == ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID) {
it = std::find_if(known.constBegin(), known.constEnd(),
[extraGenerator](const CMakeTool::Generator &g) {
@@ -954,8 +954,8 @@ Tasks CMakeConfigurationKitAspect::validate(const Kit *k) const
QTC_ASSERT(k, return Tasks());
const QtSupport::BaseQtVersion *const version = QtSupport::QtKitAspect::qtVersion(k);
const ToolChain *const tcC = ToolChainKitAspect::toolChain(k, ProjectExplorer::Constants::C_LANGUAGE_ID);
const ToolChain *const tcCxx = ToolChainKitAspect::toolChain(k, ProjectExplorer::Constants::CXX_LANGUAGE_ID);
const ToolChain *const tcC = ToolChainKitAspect::cToolChain(k);
const ToolChain *const tcCxx = ToolChainKitAspect::cxxToolChain(k);
const CMakeConfig config = configuration(k);
const bool isQt4 = version && version->qtVersion() < QtSupport::QtVersionNumber(5, 0, 0);