diff --git a/src/plugins/qbsprojectmanager/defaultpropertyprovider.cpp b/src/plugins/qbsprojectmanager/defaultpropertyprovider.cpp index 1ce5b066d6b..634fd05b592 100644 --- a/src/plugins/qbsprojectmanager/defaultpropertyprovider.cpp +++ b/src/plugins/qbsprojectmanager/defaultpropertyprovider.cpp @@ -26,6 +26,7 @@ #include "defaultpropertyprovider.h" #include "qbsconstants.h" +#include #include #include #include @@ -179,12 +180,16 @@ QVariantMap DefaultPropertyProvider::autoGeneratedProperties(const ProjectExplor if (ProjectExplorer::SysRootKitInformation::hasSysRoot(k)) data.insert(QLatin1String(QBS_SYSROOT), sysroot); - ProjectExplorer::ToolChain *tc + ProjectExplorer::ToolChain *tcC + = ProjectExplorer::ToolChainKitInformation::toolChain(k, ProjectExplorer::ToolChain::Language::C); + ProjectExplorer::ToolChain *tcCxx = ProjectExplorer::ToolChainKitInformation::toolChain(k, ProjectExplorer::ToolChain::Language::Cxx); - if (!tc) + if (!tcC && !tcCxx) return data; - ProjectExplorer::Abi targetAbi = tc->targetAbi(); + ProjectExplorer::ToolChain *mainTc = tcCxx ? tcCxx : tcC; + + ProjectExplorer::Abi targetAbi = mainTc->targetAbi(); if (targetAbi.architecture() != ProjectExplorer::Abi::UnknownArchitecture) { QString architecture = ProjectExplorer::Abi::toString(targetAbi.architecture()); @@ -215,7 +220,7 @@ QVariantMap DefaultPropertyProvider::autoGeneratedProperties(const ProjectExplor if (!targetOS.isEmpty()) data.insert(QLatin1String(QBS_TARGETOS), targetOS); - QStringList toolchain = toolchainList(tc); + QStringList toolchain = toolchainList(mainTc); if (!toolchain.isEmpty()) data.insert(QLatin1String(QBS_TOOLCHAIN), toolchain); @@ -237,27 +242,58 @@ QVariantMap DefaultPropertyProvider::autoGeneratedProperties(const ProjectExplor } } - Utils::FileName cxx = tc->compilerCommand(); - const QFileInfo cxxFileInfo = cxx.toFileInfo(); - QString compilerName = cxxFileInfo.fileName(); - const QString toolchainPrefix = extractToolchainPrefix(&compilerName); - if (!toolchainPrefix.isEmpty()) - data.insert(QLatin1String(CPP_TOOLCHAINPREFIX), toolchainPrefix); + Utils::FileName cCompilerPath; + if (tcC) + cCompilerPath = tcC->compilerCommand(); + + Utils::FileName cxxCompilerPath; + if (tcCxx) + cxxCompilerPath = tcCxx->compilerCommand(); + + const QFileInfo cFileInfo = cCompilerPath.toFileInfo(); + const QFileInfo cxxFileInfo = cxxCompilerPath.toFileInfo(); + QString cCompilerName = cFileInfo.fileName(); + QString cxxCompilerName = cxxFileInfo.fileName(); + const QString cToolchainPrefix = extractToolchainPrefix(&cCompilerName); + const QString cxxToolchainPrefix = extractToolchainPrefix(&cCompilerName); + + QFileInfo mainFileInfo; + QString mainCompilerName; + QString mainToolchainPrefix; + if (tcCxx) { + mainFileInfo = cxxFileInfo; + mainCompilerName = cxxCompilerName; + mainToolchainPrefix = cxxToolchainPrefix; + } else { + mainFileInfo = cFileInfo; + mainCompilerName = cCompilerName; + mainToolchainPrefix = cToolchainPrefix; + } + + if (!mainToolchainPrefix.isEmpty()) + data.insert(QLatin1String(CPP_TOOLCHAINPREFIX), mainToolchainPrefix); + if (toolchain.contains(QLatin1String("msvc"))) { - data.insert(QLatin1String(CPP_COMPILERNAME), compilerName); + data.insert(QLatin1String(CPP_COMPILERNAME), mainCompilerName); const MSVCVersion v = msvcCompilerVersion(targetAbi); data.insert(QLatin1String(CPP_COMPILERVERSIONMAJOR), v.major); data.insert(QLatin1String(CPP_COMPILERVERSIONMINOR), v.minor); } else { - data.insert(QLatin1String(CPP_CXXCOMPILERNAME), compilerName); + data.insert(QLatin1String(CPP_COMPILERNAME), cCompilerName); + data.insert(QLatin1String(CPP_CXXCOMPILERNAME), cxxCompilerName); } if (targetAbi.os() != ProjectExplorer::Abi::WindowsOS || targetAbi.osFlavor() == ProjectExplorer::Abi::WindowsMSysFlavor) { - data.insert(QLatin1String(CPP_LINKERNAME), compilerName); + data.insert(QLatin1String(CPP_LINKERNAME), mainCompilerName); } - data.insert(QLatin1String(CPP_TOOLCHAINPATH), cxxFileInfo.absolutePath()); - if (ProjectExplorer::GccToolChain *gcc = dynamic_cast(tc)) { + if (tcC && tcCxx && cFileInfo.absolutePath() != cxxFileInfo.absolutePath()) { + Core::MessageManager::write(tr("C and C++ compiler paths differ. C compiler may not work."), + Core::MessageManager::ModeSwitch); + } + data.insert(QLatin1String(CPP_TOOLCHAINPATH), mainFileInfo.absolutePath()); + + if (ProjectExplorer::GccToolChain *gcc = dynamic_cast(mainTc)) { data.insert(QLatin1String(CPP_PLATFORMCOMMONCOMPILERFLAGS), gcc->platformCodeGenFlags()); data.insert(QLatin1String(CPP_PLATFORMLINKERFLAGS), gcc->platformLinkerFlags()); }