C++ support: Consider project-specific target triple

... before creating project parts.
Otherwise we can get wrong includes and defines from the compiler.
Amends 9c86e6746f.
Also do not add -m32 or -m64 for non-x86 targets.

Task-number: QTCREATORBUG-25615
Change-Id: I02da9251c77d45fc8827990a2d59c3ae2c262591
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2022-10-07 18:00:36 +02:00
parent 183dfb48a7
commit 679a726330
11 changed files with 43 additions and 23 deletions

View File

@@ -78,9 +78,8 @@ static QStringList projectPartArguments(const ProjectPart &projectPart)
args << "-c";
if (projectPart.toolchainType != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
args << "--target=" + projectPart.toolChainTargetTriple;
args << (projectPart.toolChainWordWidth == ProjectPart::WordWidth64Bit
? QLatin1String("-m64")
: QLatin1String("-m32"));
if (projectPart.toolChainAbi.architecture() == Abi::X86Architecture)
args << QLatin1String(projectPart.toolChainAbi.wordWidth() == 64 ? "-m64" : "-m32");
}
args << projectPart.compilerFlags;
for (const ProjectExplorer::HeaderPath &headerPath : projectPart.headerPaths) {

View File

@@ -227,7 +227,9 @@ QStringList createLanguageOptionGcc(ProjectFile::Kind fileKind, bool objcExt)
void CompilerOptionsBuilder::addWordWidth()
{
const QString argument = m_projectPart.toolChainWordWidth == ProjectPart::WordWidth64Bit
if (m_projectPart.toolChainAbi.architecture() != Abi::X86Architecture)
return;
const QString argument = m_projectPart.toolChainAbi.wordWidth() == 64
? QLatin1String("-m64")
: QLatin1String("-m32");
add(argument);

View File

@@ -37,8 +37,12 @@ public:
rpp.setConfigFileName(projectConfigFile);
ToolChainInfo tcInfo;
tcInfo.type = toolchainType;
tcInfo.wordWidth = 64;
tcInfo.targetTriple = targetTriple;
tcInfo.abi = Abi::fromString(targetTriple);
if (!tcInfo.abi.isValid()) {
tcInfo.abi = Abi(Abi::X86Architecture, Abi::DarwinOS, Abi::FreeBsdFlavor,
Abi::MachOFormat, 64);
}
tcInfo.isMsvc2015ToolChain = isMsvc2015;
tcInfo.extraCodeModelFlags = extraFlags;
tcInfo.macroInspectionRunner = [this](const QStringList &) {

View File

@@ -1789,7 +1789,7 @@ void CppCodeModelInspectorDialog::updateProjectPartData(const ProjectPart::Const
{QString::fromLatin1("Build Target Type"), CMI::Utils::toString(part->buildTargetType)},
{QString::fromLatin1("ToolChain Type"), part->toolchainType.toString()},
{QString::fromLatin1("ToolChain Target Triple"), part->toolChainTargetTriple},
{QString::fromLatin1("ToolChain Word Width"), CMI::Utils::toString(part->toolChainWordWidth)},
{QString::fromLatin1("ToolChain Word Width"), CMI::Utils::toString(part->toolChainAbi.wordWidth())},
{QString::fromLatin1("ToolChain Install Dir"), part->toolChainInstallDir.toString()},
{QString::fromLatin1("Language Version"), CMI::Utils::toString(part->languageVersion)},
{QString::fromLatin1("Language Extensions"), CMI::Utils::toString(part->languageExtensions)},

View File

@@ -373,15 +373,15 @@ QString Utils::toString(CPlusPlus::Kind kind)
return QString();
}
QString Utils::toString(ProjectPart::ToolChainWordWidth width)
QString Utils::toString(const ProjectExplorer::Abi &abi)
{
switch (width) {
case ProjectPart::ToolChainWordWidth::WordWidth32Bit:
switch (abi.wordWidth()) {
case 32:
return QString("32");
case ProjectPart::ToolChainWordWidth::WordWidth64Bit:
case 64:
return QString("64");
}
return QString();
return QString("??");
}
QString Utils::partsForFile(const QString &fileName)
@@ -508,7 +508,7 @@ void Dumper::dumpProjectInfos(const QList<ProjectInfo::ConstPtr> &projectInfos)
m_out << i3 << "Project File : " << projectFilePath << "\n";
m_out << i3 << "ToolChain Type : " << part->toolchainType.toString() << "\n";
m_out << i3 << "ToolChain Target Triple: " << part->toolChainTargetTriple << "\n";
m_out << i3 << "ToolChain Word Width : " << part->toolChainWordWidth << "\n";
m_out << i3 << "ToolChain Word Width : " << part->toolChainAbi.wordWidth() << "\n";
m_out << i3 << "ToolChain Install Dir : " << part->toolChainInstallDir << "\n";
m_out << i3 << "Compiler Flags : " << part->compilerFlags.join(", ") << "\n";
m_out << i3 << "Selected For Building : " << part->selectedForBuilding << "\n";

View File

@@ -32,7 +32,7 @@ struct Utils
static QString toString(const QVector<ProjectFile> &projectFiles);
static QString toString(ProjectFile::Kind kind);
static QString toString(CPlusPlus::Kind kind);
static QString toString(ProjectPart::ToolChainWordWidth width);
static QString toString(const ProjectExplorer::Abi &abi);
static QString partsForFile(const QString &fileName);
static QString unresolvedFileNameWithDelimiters(const CPlusPlus::Document::Include &include);
static QString pathListToString(const QStringList &pathList);

View File

@@ -137,6 +137,27 @@ ProjectPart::ConstPtr ProjectInfoGenerator::createProjectPart(
tcInfo = m_projectUpdateInfo.cxxToolChainInfo;
}
QString explicitTarget;
if (!tcInfo.targetTripleIsAuthoritative) {
for (int i = 0; i < flags.commandLineFlags.size(); ++i) {
const QString &flag = flags.commandLineFlags.at(i);
if (flag == "-target") {
if (i + 1 < flags.commandLineFlags.size())
explicitTarget = flags.commandLineFlags.at(i + 1);
break;
} else if (flag.startsWith("--target=")) {
explicitTarget = flag.mid(9);
break;
}
}
}
if (!explicitTarget.isEmpty()) {
tcInfo.targetTriple = explicitTarget;
tcInfo.targetTripleIsAuthoritative = true;
if (const Abi abi = Abi::fromString(tcInfo.targetTriple); abi.isValid())
tcInfo.abi = abi;
}
return ProjectPart::create(projectFilePath, rawProjectPart, partName, projectFiles,
language, languageExtensions, flags, tcInfo);
}

View File

@@ -145,8 +145,7 @@ ProjectPart::ProjectPart(const Utils::FilePath &topLevelProject,
isMsvc2015Toolchain(tcInfo.isMsvc2015ToolChain),
toolChainTargetTriple(tcInfo.targetTriple),
targetTripleIsAuthoritative(tcInfo.targetTripleIsAuthoritative),
toolChainWordWidth(tcInfo.wordWidth == 64 ? ProjectPart::WordWidth64Bit
: ProjectPart::WordWidth32Bit),
toolChainAbi(tcInfo.abi),
toolChainInstallDir(tcInfo.installDir),
compilerFilePath(tcInfo.compilerFilePath),
warningFlags(flags.warningFlags),

View File

@@ -28,11 +28,6 @@ namespace CppEditor {
class CPPEDITOR_EXPORT ProjectPart
{
public:
enum ToolChainWordWidth {
WordWidth32Bit,
WordWidth64Bit,
};
using ConstPtr = QSharedPointer<const ProjectPart>;
public:
@@ -94,7 +89,7 @@ public:
const bool isMsvc2015Toolchain = false;
const QString toolChainTargetTriple;
const bool targetTripleIsAuthoritative;
const ToolChainWordWidth toolChainWordWidth = WordWidth32Bit;
const ProjectExplorer::Abi toolChainAbi = ProjectExplorer::Abi::hostAbi();
const Utils::FilePath toolChainInstallDir;
const Utils::FilePath compilerFilePath;
const Utils::WarningFlags warningFlags = Utils::WarningFlags::Default;

View File

@@ -160,7 +160,7 @@ ToolChainInfo::ToolChainInfo(const ToolChain *toolChain,
// Keep the following cheap/non-blocking for the ui thread...
type = toolChain->typeId();
isMsvc2015ToolChain = toolChain->targetAbi().osFlavor() == Abi::WindowsMsvc2015Flavor;
wordWidth = toolChain->targetAbi().wordWidth();
abi = toolChain->targetAbi();
targetTriple = toolChain->effectiveCodeModelTargetTriple();
targetTripleIsAuthoritative = !toolChain->explicitCodeModelTargetTriple().isEmpty();
extraCodeModelFlags = toolChain->extraCodeModelFlags();

View File

@@ -141,7 +141,7 @@ public:
Utils::Id type;
bool isMsvc2015ToolChain = false;
bool targetTripleIsAuthoritative = false;
unsigned wordWidth = 0;
Abi abi;
QString targetTriple;
Utils::FilePath compilerFilePath;
Utils::FilePath installDir;