QBS DefaultPropertyProvider: Separate C and C++ compilers

Task-number: QBS-893
Change-Id: If811a34d6fecba8989b19089e8bac5df5621836f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Aaron Barany
2016-07-15 22:21:49 -07:00
parent 0598202d3d
commit 6d3497d4e2

View File

@@ -26,6 +26,7 @@
#include "defaultpropertyprovider.h"
#include "qbsconstants.h"
#include <coreplugin/messagemanager.h>
#include <projectexplorer/abi.h>
#include <projectexplorer/gcctoolchain.h>
#include <projectexplorer/kit.h>
@@ -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<ProjectExplorer::GccToolChain *>(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<ProjectExplorer::GccToolChain *>(mainTc)) {
data.insert(QLatin1String(CPP_PLATFORMCOMMONCOMPILERFLAGS), gcc->platformCodeGenFlags());
data.insert(QLatin1String(CPP_PLATFORMLINKERFLAGS), gcc->platformLinkerFlags());
}