forked from qt-creator/qt-creator
McuSupport: Identify MinGW toolchain
QtMCUs will support MinGW toolchain for Windows desktop platform, so MinGW toolchain needs to be identified. If the default toolchain or a user configured one is a correct MinGW toolchain, it would be selected. If not, a proper toolchain would be picked up from the registered toolchains in Qt Creator. Task-number: UL-6607 Change-Id: I82580d721d9ed916a6b32d35c124a638d7a3e68e Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -80,6 +80,7 @@ public:
|
||||
case McuToolChainPackage::ToolChainType::KEIL:
|
||||
case McuToolChainPackage::ToolChainType::MSVC:
|
||||
case McuToolChainPackage::ToolChainType::GCC:
|
||||
case McuToolChainPackage::ToolChainType::MinGW:
|
||||
case McuToolChainPackage::ToolChainType::ArmGcc:
|
||||
ToolChainKitAspect::setToolChain(k,
|
||||
tcPackage->toolChain(
|
||||
@@ -142,6 +143,7 @@ public:
|
||||
case McuToolChainPackage::ToolChainType::KEIL:
|
||||
case McuToolChainPackage::ToolChainType::MSVC:
|
||||
case McuToolChainPackage::ToolChainType::GCC:
|
||||
case McuToolChainPackage::ToolChainType::MinGW:
|
||||
case McuToolChainPackage::ToolChainType::ArmGcc: {
|
||||
const QVariant debuggerId = tcPackage->debuggerId();
|
||||
if (debuggerId.isValid()) {
|
||||
|
@@ -294,7 +294,8 @@ McuToolChainPackage::ToolChainType McuToolChainPackage::toolchainType() const
|
||||
|
||||
bool McuToolChainPackage::isDesktopToolchain() const
|
||||
{
|
||||
return m_type == ToolChainType::MSVC || m_type == ToolChainType::GCC;
|
||||
return m_type == ToolChainType::MSVC || m_type == ToolChainType::GCC
|
||||
|| m_type == ToolChainType::MinGW;
|
||||
}
|
||||
|
||||
ToolChain *McuToolChainPackage::msvcToolChain(Id language)
|
||||
@@ -320,6 +321,28 @@ ToolChain *McuToolChainPackage::gccToolChain(Id language)
|
||||
return toolChain;
|
||||
}
|
||||
|
||||
static ToolChain *mingwToolChain(const FilePath &path, Id language)
|
||||
{
|
||||
ToolChain *toolChain = ToolChainManager::toolChain([&path, language](const ToolChain *t) {
|
||||
// find a MinGW toolchain having the same path from registered toolchains
|
||||
const Abi abi = t->targetAbi();
|
||||
return t->typeId() == ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID
|
||||
&& abi.architecture() == Abi::X86Architecture && abi.wordWidth() == 64
|
||||
&& t->language() == language && t->compilerCommand() == path;
|
||||
});
|
||||
if (!toolChain) {
|
||||
// if there's no MinGW toolchain having the same path,
|
||||
// a proper MinGW would be selected from the registered toolchains.
|
||||
toolChain = ToolChainManager::toolChain([language](const ToolChain *t) {
|
||||
const Abi abi = t->targetAbi();
|
||||
return t->typeId() == ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID
|
||||
&& abi.architecture() == Abi::X86Architecture && abi.wordWidth() == 64
|
||||
&& t->language() == language;
|
||||
});
|
||||
}
|
||||
return toolChain;
|
||||
}
|
||||
|
||||
static ToolChain *armGccToolChain(const FilePath &path, Id language)
|
||||
{
|
||||
ToolChain *toolChain = ToolChainManager::toolChain([&path, language](const ToolChain *t) {
|
||||
@@ -384,6 +407,12 @@ ToolChain *McuToolChainPackage::toolChain(Id language) const
|
||||
return msvcToolChain(language);
|
||||
case ToolChainType::GCC:
|
||||
return gccToolChain(language);
|
||||
case ToolChainType::MinGW: {
|
||||
const QLatin1String compilerName(
|
||||
language == ProjectExplorer::Constants::C_LANGUAGE_ID ? "gcc" : "g++");
|
||||
const FilePath compilerPath = (path() / "bin" / compilerName).withExecutableSuffix();
|
||||
return mingwToolChain(compilerPath, language);
|
||||
}
|
||||
case ToolChainType::IAR: {
|
||||
const FilePath compiler = (path() / "/bin/iccarm").withExecutableSuffix();
|
||||
return iarToolChain(compiler, language);
|
||||
@@ -414,6 +443,8 @@ QString McuToolChainPackage::toolChainName() const
|
||||
return QLatin1String("msvc");
|
||||
case ToolChainType::GCC:
|
||||
return QLatin1String("gcc");
|
||||
case ToolChainType::MinGW:
|
||||
return QLatin1String("mingw");
|
||||
case ToolChainType::ArmGcc:
|
||||
return QLatin1String("armgcc");
|
||||
case ToolChainType::IAR:
|
||||
|
@@ -98,7 +98,7 @@ class McuToolChainPackage final : public McuPackage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class ToolChainType { IAR, KEIL, MSVC, GCC, ArmGcc, GHS, GHSArm, Unsupported };
|
||||
enum class ToolChainType { IAR, KEIL, MSVC, GCC, ArmGcc, GHS, GHSArm, MinGW, Unsupported };
|
||||
|
||||
McuToolChainPackage(const SettingsHandler::Ptr &settingsHandler,
|
||||
const QString &label,
|
||||
|
@@ -24,7 +24,8 @@ bool isToolchainDescriptionValid(const McuTargetDescription::Toolchain &t)
|
||||
bool isDesktopToolchain(McuToolChainPackage::ToolChainType type)
|
||||
{
|
||||
return type == McuToolChainPackage::ToolChainType::MSVC
|
||||
|| type == McuToolChainPackage::ToolChainType::GCC;
|
||||
|| type == McuToolChainPackage::ToolChainType::GCC
|
||||
|| type == McuToolChainPackage::ToolChainType::MinGW;
|
||||
}
|
||||
|
||||
McuPackageVersionDetector *createVersionDetection(const VersionDetection &versionDetection)
|
||||
@@ -152,6 +153,7 @@ McuToolChainPackage *McuTargetFactory::createToolchain(
|
||||
{"keil", McuToolChainPackage::ToolChainType::KEIL},
|
||||
{"msvc", McuToolChainPackage::ToolChainType::MSVC},
|
||||
{"gcc", McuToolChainPackage::ToolChainType::GCC},
|
||||
{"mingw", McuToolChainPackage::ToolChainType::MinGW},
|
||||
{"armgcc", McuToolChainPackage::ToolChainType::ArmGcc},
|
||||
{"greenhills", McuToolChainPackage::ToolChainType::GHS},
|
||||
{"arm-greenhills", McuToolChainPackage::ToolChainType::GHSArm},
|
||||
|
29
src/plugins/mcusupport/test/mingw_desktop_json.h
Normal file
29
src/plugins/mcusupport/test/mingw_desktop_json.h
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2022 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
constexpr auto mingw_desktop_json = R"(
|
||||
{
|
||||
"qulVersion": "2.3.0",
|
||||
"compatVersion": "1",
|
||||
"platform": {
|
||||
"id": "Qt",
|
||||
"platformName": "Desktop",
|
||||
"vendor": "Qt",
|
||||
"colorDepths": [
|
||||
32
|
||||
]
|
||||
},
|
||||
"toolchain": {
|
||||
"id": "mingw",
|
||||
"versions": [
|
||||
"11.2.0"
|
||||
],
|
||||
"compiler": {
|
||||
"label": "MinGW Toolchain",
|
||||
"defaultValue": "%{QT_TOOLS_DIR}/mingw1120_64"
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
@@ -16,6 +16,7 @@
|
||||
#include "iar_mimxrt1064_evk_freertos_json.h"
|
||||
#include "iar_stm32f469i_discovery_baremetal_json.h"
|
||||
#include "msvc_desktop_json.h"
|
||||
#include "mingw_desktop_json.h"
|
||||
|
||||
#include "mcuhelpers.h"
|
||||
#include "mcukitmanager.h"
|
||||
@@ -260,6 +261,17 @@ void verifyMsvcToolchain(const McuToolChainPackagePtr &msvcPackage, const QStrin
|
||||
QVERIFY(allOf(versions, [&](const QString &v) { return msvcPackage->versions().contains(v); }));
|
||||
}
|
||||
|
||||
void verifyMingwToolchain(const McuToolChainPackagePtr &mingwPackage, const QStringList &versions)
|
||||
{
|
||||
QVERIFY(mingwPackage != nullptr);
|
||||
QCOMPARE(mingwPackage->cmakeVariableName(), "");
|
||||
QCOMPARE(mingwPackage->environmentVariableName(), "");
|
||||
QCOMPARE(mingwPackage->toolchainType(), McuToolChainPackage::ToolChainType::MinGW);
|
||||
QCOMPARE(mingwPackage->isDesktopToolchain(), true);
|
||||
QCOMPARE(mingwPackage->toolChainName(), "mingw");
|
||||
QVERIFY(allOf(versions, [&](const QString &v) { return mingwPackage->versions().contains(v); }));
|
||||
}
|
||||
|
||||
void verifyTargetToolchains(const Targets &targets,
|
||||
const QString &toolchainFilePath,
|
||||
const QString &toolchainFileDefaultPath,
|
||||
@@ -551,6 +563,13 @@ void McuSupportTest::test_createDesktopMsvcToolchain()
|
||||
verifyMsvcToolchain(msvcPackage, {});
|
||||
}
|
||||
|
||||
void McuSupportTest::test_createDesktopMingwToolchain()
|
||||
{
|
||||
const auto description = parseDescriptionJson(mingw_desktop_json);
|
||||
McuToolChainPackagePtr mingwPackage{targetFactory.createToolchain(description.toolchain)};
|
||||
verifyMingwToolchain(mingwPackage, {"11.2.0"});
|
||||
}
|
||||
|
||||
void McuSupportTest::test_verifyManuallyCreatedArmGccToolchain()
|
||||
{
|
||||
verifyArmGccToolchain(armGccToolchainPackagePtr, {armGccVersion});
|
||||
|
@@ -51,6 +51,7 @@ private slots:
|
||||
void test_createDesktopGccToolchain();
|
||||
void test_legacy_createDesktopMsvcToolchain();
|
||||
void test_createDesktopMsvcToolchain();
|
||||
void test_createDesktopMingwToolchain();
|
||||
void test_verifyManuallyCreatedArmGccToolchain();
|
||||
void test_legacy_createArmGccToolchain();
|
||||
void test_createArmGccToolchain_data();
|
||||
|
Reference in New Issue
Block a user