2020-03-12 14:25:49 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2020-07-02 16:04:31 +02:00
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2020-03-12 14:25:49 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "mcusupportconstants.h"
|
|
|
|
|
#include "mcusupportoptions.h"
|
|
|
|
|
#include "mcusupportsdk.h"
|
|
|
|
|
|
2020-05-07 12:38:28 +02:00
|
|
|
#include <utils/algorithm.h>
|
2020-03-12 14:25:49 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
|
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
|
|
|
|
|
#include <QDir>
|
2020-05-07 12:38:28 +02:00
|
|
|
#include <QDirIterator>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
#include <QVariant>
|
2020-03-12 14:25:49 +01:00
|
|
|
|
|
|
|
|
namespace McuSupport {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
namespace Sdk {
|
|
|
|
|
|
|
|
|
|
static QString findInProgramFiles(const QString &folder)
|
|
|
|
|
{
|
|
|
|
|
for (auto envVar : {"ProgramFiles", "ProgramFiles(x86)", "ProgramW6432"}) {
|
|
|
|
|
if (!qEnvironmentVariableIsSet(envVar))
|
|
|
|
|
continue;
|
|
|
|
|
const Utils::FilePath dir =
|
|
|
|
|
Utils::FilePath::fromUserInput(qEnvironmentVariable(envVar) + "/" + folder);
|
|
|
|
|
if (dir.exists())
|
|
|
|
|
return dir.toString();
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
McuPackage *createQtForMCUsPackage()
|
|
|
|
|
{
|
|
|
|
|
auto result = new McuPackage(
|
2020-06-30 17:09:03 +02:00
|
|
|
McuPackage::tr("Qt for MCUs %1+ SDK").arg(
|
|
|
|
|
McuSupportOptions::minimalQulVersion().toString()),
|
2020-03-12 14:25:49 +01:00
|
|
|
QDir::homePath(),
|
|
|
|
|
Utils::HostOsInfo::withExecutableSuffix("bin/qmltocpp"),
|
2020-03-24 18:58:29 +01:00
|
|
|
Constants::SETTINGS_KEY_PACKAGE_QT_FOR_MCUS_SDK);
|
2020-03-12 14:25:49 +01:00
|
|
|
result->setEnvironmentVariableName("Qul_DIR");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 11:16:37 +02:00
|
|
|
static McuToolChainPackage *createMsvcToolChainPackage()
|
2020-04-07 18:19:32 +02:00
|
|
|
{
|
2020-09-18 11:16:37 +02:00
|
|
|
return new McuToolChainPackage({}, {}, {}, {}, McuToolChainPackage::TypeMSVC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static McuToolChainPackage *createGccToolChainPackage()
|
|
|
|
|
{
|
|
|
|
|
return new McuToolChainPackage({}, {}, {}, {}, McuToolChainPackage::TypeGCC);
|
2020-04-07 18:19:32 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-12 14:25:49 +01:00
|
|
|
static McuToolChainPackage *createArmGccPackage()
|
|
|
|
|
{
|
|
|
|
|
const char envVar[] = "ARMGCC_DIR";
|
|
|
|
|
|
|
|
|
|
QString defaultPath;
|
|
|
|
|
if (qEnvironmentVariableIsSet(envVar))
|
|
|
|
|
defaultPath = qEnvironmentVariable(envVar);
|
|
|
|
|
if (defaultPath.isEmpty() && Utils::HostOsInfo::isWindowsHost()) {
|
|
|
|
|
const QDir installDir(findInProgramFiles("/GNU Tools ARM Embedded/"));
|
|
|
|
|
if (installDir.exists()) {
|
|
|
|
|
// If GNU Tools installation dir has only one sub dir,
|
|
|
|
|
// select the sub dir, otherwise the installation dir.
|
|
|
|
|
const QFileInfoList subDirs =
|
|
|
|
|
installDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
|
if (subDirs.count() == 1)
|
|
|
|
|
defaultPath = subDirs.first().filePath() + '/';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (defaultPath.isEmpty())
|
|
|
|
|
defaultPath = QDir::homePath();
|
|
|
|
|
|
|
|
|
|
auto result = new McuToolChainPackage(
|
|
|
|
|
McuPackage::tr("GNU Arm Embedded Toolchain"),
|
|
|
|
|
defaultPath,
|
|
|
|
|
Utils::HostOsInfo::withExecutableSuffix("bin/arm-none-eabi-g++"),
|
|
|
|
|
"GNUArmEmbeddedToolchain",
|
|
|
|
|
McuToolChainPackage::TypeArmGcc);
|
|
|
|
|
result->setEnvironmentVariableName(envVar);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 23:50:03 +02:00
|
|
|
static McuToolChainPackage *createGhsToolchainPackage()
|
|
|
|
|
{
|
|
|
|
|
const char envVar[] = "GHS_COMPILER_DIR";
|
|
|
|
|
|
|
|
|
|
const QString defaultPath =
|
|
|
|
|
qEnvironmentVariableIsSet(envVar) ? qEnvironmentVariable(envVar) : QDir::homePath();
|
|
|
|
|
|
|
|
|
|
auto result = new McuToolChainPackage(
|
|
|
|
|
"Green Hills Compiler",
|
|
|
|
|
defaultPath,
|
|
|
|
|
Utils::HostOsInfo::withExecutableSuffix("ccv850"),
|
|
|
|
|
"GHSToolchain",
|
|
|
|
|
McuToolChainPackage::TypeGHS);
|
|
|
|
|
result->setEnvironmentVariableName(envVar);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static McuPackage *createRGLPackage()
|
|
|
|
|
{
|
|
|
|
|
const char envVar[] = "RGL_DIR";
|
|
|
|
|
|
|
|
|
|
QString defaultPath;
|
|
|
|
|
if (qEnvironmentVariableIsSet(envVar)) {
|
|
|
|
|
defaultPath = qEnvironmentVariable(envVar);
|
|
|
|
|
} else if (Utils::HostOsInfo::isWindowsHost()) {
|
|
|
|
|
defaultPath = QDir::rootPath() + "Renesas_Electronics/D1x_RGL";
|
|
|
|
|
if (QFileInfo::exists(defaultPath)) {
|
|
|
|
|
const QFileInfoList subDirs =
|
|
|
|
|
QDir(defaultPath).entryInfoList({QLatin1String("rgl_ghs_D1Mx_*")},
|
|
|
|
|
QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
|
if (subDirs.count() == 1)
|
|
|
|
|
defaultPath = subDirs.first().filePath() + '/';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto result = new McuPackage(
|
|
|
|
|
"Renesas Graphics Library",
|
|
|
|
|
defaultPath,
|
|
|
|
|
{},
|
|
|
|
|
"RGL");
|
|
|
|
|
result->setEnvironmentVariableName(envVar);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 14:25:49 +01:00
|
|
|
static McuPackage *createStm32CubeProgrammerPackage()
|
|
|
|
|
{
|
|
|
|
|
QString defaultPath = QDir::homePath();
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost()) {
|
|
|
|
|
const QString programPath =
|
|
|
|
|
findInProgramFiles("/STMicroelectronics/STM32Cube/STM32CubeProgrammer/");
|
|
|
|
|
if (!programPath.isEmpty())
|
|
|
|
|
defaultPath = programPath;
|
|
|
|
|
}
|
|
|
|
|
auto result = new McuPackage(
|
|
|
|
|
McuPackage::tr("STM32CubeProgrammer"),
|
|
|
|
|
defaultPath,
|
|
|
|
|
QLatin1String(Utils::HostOsInfo::isWindowsHost() ? "/bin/STM32_Programmer_CLI.exe"
|
|
|
|
|
: "/bin/STM32_Programmer.sh"),
|
|
|
|
|
"Stm32CubeProgrammer");
|
|
|
|
|
result->setRelativePathModifier("/bin");
|
|
|
|
|
result->setDownloadUrl(
|
|
|
|
|
"https://www.st.com/en/development-tools/stm32cubeprog.html");
|
|
|
|
|
result->setAddToPath(true);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 23:59:52 +02:00
|
|
|
static McuPackage *createMcuXpressoIdePackage()
|
2020-03-12 14:25:49 +01:00
|
|
|
{
|
2020-04-08 23:59:52 +02:00
|
|
|
const char envVar[] = "MCUXpressoIDE_PATH";
|
|
|
|
|
|
|
|
|
|
QString defaultPath;
|
|
|
|
|
if (qEnvironmentVariableIsSet(envVar)) {
|
|
|
|
|
defaultPath = qEnvironmentVariable(envVar);
|
|
|
|
|
} else if (Utils::HostOsInfo::isWindowsHost()) {
|
|
|
|
|
defaultPath = QDir::rootPath() + "nxp";
|
|
|
|
|
if (QFileInfo::exists(defaultPath)) {
|
|
|
|
|
// If default dir has exactly one sub dir that could be the IDE path, pre-select that.
|
|
|
|
|
const QFileInfoList subDirs =
|
|
|
|
|
QDir(defaultPath).entryInfoList({QLatin1String("MCUXpressoIDE*")},
|
|
|
|
|
QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
|
if (subDirs.count() == 1)
|
|
|
|
|
defaultPath = subDirs.first().filePath() + '/';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
defaultPath = "/usr/local/mcuxpressoide/";
|
2020-03-12 14:25:49 +01:00
|
|
|
}
|
2020-04-08 23:59:52 +02:00
|
|
|
|
2020-03-12 14:25:49 +01:00
|
|
|
auto result = new McuPackage(
|
2020-04-08 23:59:52 +02:00
|
|
|
"MCUXpresso IDE",
|
2020-03-12 14:25:49 +01:00
|
|
|
defaultPath,
|
2020-04-08 23:59:52 +02:00
|
|
|
Utils::HostOsInfo::withExecutableSuffix("ide/binaries/crt_emu_cm_redlink"),
|
|
|
|
|
"MCUXpressoIDE");
|
|
|
|
|
result->setDownloadUrl("https://www.nxp.com/mcuxpresso/ide");
|
|
|
|
|
result->setEnvironmentVariableName(envVar);
|
2020-03-12 14:25:49 +01:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-17 11:25:59 +02:00
|
|
|
struct McuTargetDescription
|
2020-04-27 20:51:08 +02:00
|
|
|
{
|
2020-09-18 11:16:37 +02:00
|
|
|
enum class TargetType {
|
|
|
|
|
MCU,
|
|
|
|
|
Desktop
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-17 11:25:59 +02:00
|
|
|
QString qulVersion;
|
|
|
|
|
QString platform;
|
2020-09-18 11:16:37 +02:00
|
|
|
QString platformName;
|
2020-08-17 11:25:59 +02:00
|
|
|
QString platformVendor;
|
|
|
|
|
QVector<int> colorDepths;
|
|
|
|
|
QString toolchainId;
|
|
|
|
|
QString boardSdkEnvVar;
|
|
|
|
|
QString boardSdkName;
|
|
|
|
|
QString boardSdkDefaultPath;
|
|
|
|
|
QString freeRTOSEnvVar;
|
|
|
|
|
QString freeRTOSBoardSdkSubDir;
|
2020-09-18 11:16:37 +02:00
|
|
|
TargetType type;
|
2020-08-17 11:25:59 +02:00
|
|
|
};
|
2020-04-27 20:51:08 +02:00
|
|
|
|
2020-08-17 11:25:59 +02:00
|
|
|
static McuPackage *createBoardSdkPackage(const McuTargetDescription& desc)
|
|
|
|
|
{
|
|
|
|
|
const auto generateSdkName = [](const QString& envVar) {
|
|
|
|
|
auto postfixPos = envVar.indexOf("_SDK_PATH");
|
|
|
|
|
if (postfixPos < 0) {
|
|
|
|
|
postfixPos = envVar.indexOf("_DIR");
|
|
|
|
|
}
|
|
|
|
|
auto sdkName = postfixPos > 0 ? envVar.left(postfixPos) : envVar;
|
|
|
|
|
return QString::fromLatin1("MCU SDK (%1)").arg(sdkName);
|
|
|
|
|
};
|
|
|
|
|
const QString sdkName = desc.boardSdkName.isEmpty() ? generateSdkName(desc.boardSdkEnvVar) : desc.boardSdkName;
|
|
|
|
|
|
|
|
|
|
const QString defaultPath = [&] {
|
|
|
|
|
const auto envVar = desc.boardSdkEnvVar.toLatin1();
|
|
|
|
|
if (qEnvironmentVariableIsSet(envVar)) {
|
|
|
|
|
return qEnvironmentVariable(envVar);
|
|
|
|
|
}
|
|
|
|
|
if (!desc.boardSdkDefaultPath.isEmpty()) {
|
|
|
|
|
QString defaultPath = QDir::rootPath() + desc.boardSdkDefaultPath;
|
|
|
|
|
if (QFileInfo::exists(defaultPath)) {
|
|
|
|
|
return defaultPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QDir::homePath();
|
|
|
|
|
}();
|
2020-04-27 20:51:08 +02:00
|
|
|
|
2020-06-29 23:21:22 +02:00
|
|
|
auto result = new McuPackage(
|
2020-08-17 11:25:59 +02:00
|
|
|
sdkName,
|
2020-06-29 23:21:22 +02:00
|
|
|
defaultPath,
|
|
|
|
|
{},
|
2020-08-17 11:25:59 +02:00
|
|
|
desc.boardSdkEnvVar);
|
|
|
|
|
result->setEnvironmentVariableName(desc.boardSdkEnvVar);
|
2020-06-29 23:21:22 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-03 09:46:44 +02:00
|
|
|
static McuPackage *createFreeRTOSSourcesPackage(const QString &envVar, const QString &boardSdkDir,
|
|
|
|
|
const QString &freeRTOSBoardSdkSubDir)
|
2020-04-27 20:51:08 +02:00
|
|
|
{
|
2020-09-18 11:16:37 +02:00
|
|
|
const QString envVarPrefix = envVar.chopped(int(strlen("_FREERTOS_DIR")));
|
2020-04-27 20:51:08 +02:00
|
|
|
|
2020-07-03 09:46:44 +02:00
|
|
|
QString defaultPath;
|
|
|
|
|
if (qEnvironmentVariableIsSet(envVar.toLatin1()))
|
|
|
|
|
defaultPath = qEnvironmentVariable(envVar.toLatin1());
|
|
|
|
|
else if (!boardSdkDir.isEmpty() && !freeRTOSBoardSdkSubDir.isEmpty())
|
|
|
|
|
defaultPath = boardSdkDir + "/" + freeRTOSBoardSdkSubDir;
|
|
|
|
|
else
|
|
|
|
|
defaultPath = QDir::homePath();
|
2020-04-27 20:51:08 +02:00
|
|
|
|
|
|
|
|
auto result = new McuPackage(
|
|
|
|
|
QString::fromLatin1("FreeRTOS Sources (%1)").arg(envVarPrefix),
|
|
|
|
|
defaultPath,
|
|
|
|
|
{},
|
|
|
|
|
QString::fromLatin1("FreeRTOSSourcePackage_%1").arg(envVarPrefix));
|
|
|
|
|
result->setDownloadUrl("https://freertos.org");
|
|
|
|
|
result->setEnvironmentVariableName(envVar);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 13:10:52 +02:00
|
|
|
struct McuTargetFactory
|
2020-05-07 12:38:28 +02:00
|
|
|
{
|
2020-08-13 13:10:52 +02:00
|
|
|
McuTargetFactory(const QHash<QString, McuToolChainPackage *> &tcPkgs,
|
|
|
|
|
const QHash<QString, McuPackage *> &vendorPkgs)
|
|
|
|
|
: tcPkgs(tcPkgs)
|
|
|
|
|
, vendorPkgs(vendorPkgs)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
QVector<McuTarget *> createTargets(const McuTargetDescription& description)
|
|
|
|
|
{
|
|
|
|
|
auto qulVersion = QVersionNumber::fromString(description.qulVersion);
|
|
|
|
|
if (qulVersion <= QVersionNumber({1,3})) {
|
2020-09-18 11:16:37 +02:00
|
|
|
if (description.type == McuTargetDescription::TargetType::Desktop)
|
|
|
|
|
return createDesktopTargetsLegacy(description);
|
|
|
|
|
|
2020-08-13 13:10:52 +02:00
|
|
|
// There was a platform backends related refactoring in Qul 1.4
|
|
|
|
|
// This requires different processing of McuTargetDescriptions
|
|
|
|
|
return createMcuTargetsLegacy(description);
|
|
|
|
|
}
|
2020-09-18 11:16:37 +02:00
|
|
|
return createTargetsImpl(description);
|
2020-08-13 13:10:52 +02:00
|
|
|
}
|
2020-03-18 03:17:35 +01:00
|
|
|
|
2020-08-13 13:10:52 +02:00
|
|
|
QVector<McuPackage *> getMcuPackages() const
|
|
|
|
|
{
|
|
|
|
|
QVector<McuPackage *> packages;
|
|
|
|
|
packages.append(boardSdkPkgs.values().toVector());
|
|
|
|
|
packages.append(freeRTOSPkgs.values().toVector());
|
|
|
|
|
return packages;
|
|
|
|
|
}
|
2020-05-07 12:38:28 +02:00
|
|
|
|
2020-08-13 13:10:52 +02:00
|
|
|
protected:
|
|
|
|
|
// Implementation for Qul version <= 1.3
|
2020-09-18 11:16:37 +02:00
|
|
|
QVector<McuTarget *> createMcuTargetsLegacy(const McuTargetDescription &desc)
|
2020-08-13 13:10:52 +02:00
|
|
|
{
|
|
|
|
|
QVector<McuTarget *> mcuTargets;
|
2020-09-18 11:16:37 +02:00
|
|
|
McuToolChainPackage *tcPkg = tcPkgs.value(desc.toolchainId);
|
2020-05-07 12:38:28 +02:00
|
|
|
for (auto os : {McuTarget::OS::BareMetal, McuTarget::OS::FreeRTOS}) {
|
|
|
|
|
for (int colorDepth : desc.colorDepths) {
|
2020-08-17 11:25:59 +02:00
|
|
|
QVector<McuPackage*> required3rdPartyPkgs = { tcPkg };
|
2020-09-18 11:16:37 +02:00
|
|
|
if (vendorPkgs.contains(desc.platformVendor))
|
2020-08-17 11:25:59 +02:00
|
|
|
required3rdPartyPkgs.push_back(vendorPkgs.value(desc.platformVendor));
|
2020-09-18 11:16:37 +02:00
|
|
|
|
2020-07-03 09:46:44 +02:00
|
|
|
QString boardSdkDefaultPath;
|
2020-08-17 11:25:59 +02:00
|
|
|
if (!desc.boardSdkEnvVar.isEmpty()) {
|
2020-06-29 23:21:22 +02:00
|
|
|
if (!boardSdkPkgs.contains(desc.boardSdkEnvVar)) {
|
2020-08-17 11:25:59 +02:00
|
|
|
auto boardSdkPkg = desc.boardSdkEnvVar != "RGL_DIR"
|
|
|
|
|
? createBoardSdkPackage(desc)
|
|
|
|
|
: createRGLPackage();
|
2020-06-29 23:21:22 +02:00
|
|
|
boardSdkPkgs.insert(desc.boardSdkEnvVar, boardSdkPkg);
|
|
|
|
|
}
|
2020-07-03 09:46:44 +02:00
|
|
|
auto boardSdkPkg = boardSdkPkgs.value(desc.boardSdkEnvVar);
|
|
|
|
|
boardSdkDefaultPath = boardSdkPkg->defaultPath();
|
|
|
|
|
required3rdPartyPkgs.append(boardSdkPkg);
|
2020-06-29 23:21:22 +02:00
|
|
|
}
|
2020-05-05 06:48:26 +02:00
|
|
|
if (os == McuTarget::OS::FreeRTOS) {
|
2020-05-07 12:38:28 +02:00
|
|
|
if (desc.freeRTOSEnvVar.isEmpty()) {
|
2020-05-05 06:48:26 +02:00
|
|
|
continue;
|
2020-05-07 12:38:28 +02:00
|
|
|
} else {
|
|
|
|
|
if (!freeRTOSPkgs.contains(desc.freeRTOSEnvVar)) {
|
2020-07-03 09:46:44 +02:00
|
|
|
freeRTOSPkgs.insert(desc.freeRTOSEnvVar, createFreeRTOSSourcesPackage(
|
|
|
|
|
desc.freeRTOSEnvVar, boardSdkDefaultPath,
|
|
|
|
|
desc.freeRTOSBoardSdkSubDir));
|
2020-05-07 12:38:28 +02:00
|
|
|
}
|
|
|
|
|
required3rdPartyPkgs.append(freeRTOSPkgs.value(desc.freeRTOSEnvVar));
|
|
|
|
|
}
|
2020-05-05 06:48:26 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-18 11:16:37 +02:00
|
|
|
const auto platform = McuTarget::Platform{ desc.platform, desc.platformName, desc.platformVendor };
|
2020-06-30 17:09:03 +02:00
|
|
|
auto mcuTarget = new McuTarget(QVersionNumber::fromString(desc.qulVersion),
|
2020-09-18 11:16:37 +02:00
|
|
|
platform, os, required3rdPartyPkgs, tcPkg);
|
2020-05-07 12:38:28 +02:00
|
|
|
if (desc.colorDepths.count() > 1)
|
2020-05-05 06:48:26 +02:00
|
|
|
mcuTarget->setColorDepth(colorDepth);
|
2020-05-07 12:38:28 +02:00
|
|
|
mcuTargets.append(mcuTarget);
|
2020-05-05 06:48:26 +02:00
|
|
|
}
|
2020-03-18 03:17:35 +01:00
|
|
|
}
|
2020-08-13 13:10:52 +02:00
|
|
|
return mcuTargets;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 11:16:37 +02:00
|
|
|
QVector<McuTarget *> createDesktopTargetsLegacy(const McuTargetDescription& desc)
|
2020-08-13 13:10:52 +02:00
|
|
|
{
|
2020-09-18 11:16:37 +02:00
|
|
|
McuToolChainPackage *tcPkg = tcPkgs.value(desc.toolchainId);
|
|
|
|
|
const auto platform = McuTarget::Platform{ desc.platform, desc.platformName, desc.platformVendor };
|
|
|
|
|
auto desktopTarget = new McuTarget(QVersionNumber::fromString(desc.qulVersion),
|
|
|
|
|
platform, McuTarget::OS::Desktop, {}, tcPkg);
|
|
|
|
|
return { desktopTarget };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector<McuTarget *> createTargetsImpl(const McuTargetDescription& desc)
|
|
|
|
|
{
|
|
|
|
|
// OS deduction
|
|
|
|
|
const auto os = [&] {
|
|
|
|
|
if (desc.type == McuTargetDescription::TargetType::Desktop)
|
|
|
|
|
return McuTarget::OS::Desktop;
|
|
|
|
|
else if (!desc.freeRTOSEnvVar.isEmpty())
|
|
|
|
|
return McuTarget::OS::FreeRTOS;
|
|
|
|
|
return McuTarget::OS::BareMetal;
|
|
|
|
|
}();
|
|
|
|
|
|
2020-08-13 13:10:52 +02:00
|
|
|
QVector<McuTarget *> mcuTargets;
|
2020-09-18 11:16:37 +02:00
|
|
|
McuToolChainPackage *tcPkg = tcPkgs.value(desc.toolchainId);
|
2020-08-13 13:10:52 +02:00
|
|
|
for (int colorDepth : desc.colorDepths) {
|
2020-09-18 11:16:37 +02:00
|
|
|
QVector<McuPackage*> required3rdPartyPkgs;
|
|
|
|
|
// Desktop toolchains don't need any additional settings
|
|
|
|
|
if (tcPkg && !tcPkg->isDesktopToolchain())
|
|
|
|
|
required3rdPartyPkgs.append(tcPkg);
|
|
|
|
|
|
|
|
|
|
// Add setting specific to platform IDE
|
|
|
|
|
if (vendorPkgs.contains(desc.platformVendor))
|
2020-08-17 11:25:59 +02:00
|
|
|
required3rdPartyPkgs.push_back(vendorPkgs.value(desc.platformVendor));
|
2020-09-18 11:16:37 +02:00
|
|
|
|
|
|
|
|
// Board SDK specific settings
|
2020-08-13 13:10:52 +02:00
|
|
|
QString boardSdkDefaultPath;
|
2020-08-17 11:25:59 +02:00
|
|
|
if (!desc.boardSdkEnvVar.isEmpty()) {
|
2020-08-13 13:10:52 +02:00
|
|
|
if (!boardSdkPkgs.contains(desc.boardSdkEnvVar)) {
|
2020-08-17 11:25:59 +02:00
|
|
|
auto boardSdkPkg = createBoardSdkPackage(desc);
|
2020-08-13 13:10:52 +02:00
|
|
|
boardSdkPkgs.insert(desc.boardSdkEnvVar, boardSdkPkg);
|
|
|
|
|
}
|
|
|
|
|
auto boardSdkPkg = boardSdkPkgs.value(desc.boardSdkEnvVar);
|
|
|
|
|
boardSdkDefaultPath = boardSdkPkg->defaultPath();
|
|
|
|
|
required3rdPartyPkgs.append(boardSdkPkg);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 11:16:37 +02:00
|
|
|
// Free RTOS specific settings
|
2020-08-13 13:10:52 +02:00
|
|
|
if (!desc.freeRTOSEnvVar.isEmpty()) {
|
|
|
|
|
if (!freeRTOSPkgs.contains(desc.freeRTOSEnvVar)) {
|
|
|
|
|
freeRTOSPkgs.insert(desc.freeRTOSEnvVar, createFreeRTOSSourcesPackage(
|
|
|
|
|
desc.freeRTOSEnvVar, boardSdkDefaultPath,
|
|
|
|
|
desc.freeRTOSBoardSdkSubDir));
|
|
|
|
|
}
|
|
|
|
|
required3rdPartyPkgs.append(freeRTOSPkgs.value(desc.freeRTOSEnvVar));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 11:16:37 +02:00
|
|
|
const auto platform = McuTarget::Platform{ desc.platform, desc.platformName, desc.platformVendor };
|
2020-08-13 13:10:52 +02:00
|
|
|
auto mcuTarget = new McuTarget(QVersionNumber::fromString(desc.qulVersion),
|
2020-09-18 11:16:37 +02:00
|
|
|
platform, os, required3rdPartyPkgs, tcPkg);
|
2020-08-13 13:10:52 +02:00
|
|
|
mcuTarget->setColorDepth(colorDepth);
|
|
|
|
|
mcuTargets.append(mcuTarget);
|
|
|
|
|
}
|
|
|
|
|
return mcuTargets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const QHash<QString, McuToolChainPackage *> &tcPkgs;
|
|
|
|
|
const QHash<QString, McuPackage *> &vendorPkgs;
|
|
|
|
|
|
|
|
|
|
QHash<QString, McuPackage *> boardSdkPkgs;
|
|
|
|
|
QHash<QString, McuPackage *> freeRTOSPkgs;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static QVector<McuTarget *> targetsFromDescriptions(const QList<McuTargetDescription> &descriptions,
|
|
|
|
|
QVector<McuPackage *> *packages)
|
|
|
|
|
{
|
|
|
|
|
const QHash<QString, McuToolChainPackage *> tcPkgs = {
|
|
|
|
|
{{"armgcc"}, createArmGccPackage()},
|
|
|
|
|
{{"greenhills"}, createGhsToolchainPackage()},
|
2020-09-18 11:16:37 +02:00
|
|
|
{{"msvc"}, createMsvcToolChainPackage()},
|
|
|
|
|
{{"gcc"}, createGccToolChainPackage()},
|
2020-08-13 13:10:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const QHash<QString, McuPackage *> vendorPkgs = {
|
|
|
|
|
{{"ST"}, createStm32CubeProgrammerPackage()},
|
|
|
|
|
{{"NXP"}, createMcuXpressoIdePackage()},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
McuTargetFactory targetFactory(tcPkgs, vendorPkgs);
|
|
|
|
|
QVector<McuTarget *> mcuTargets;
|
|
|
|
|
|
|
|
|
|
for (const auto &desc : descriptions) {
|
|
|
|
|
auto newTargets = targetFactory.createTargets(desc);
|
|
|
|
|
mcuTargets.append(newTargets);
|
2020-03-18 03:17:35 +01:00
|
|
|
}
|
2020-05-07 12:38:28 +02:00
|
|
|
|
|
|
|
|
packages->append(Utils::transform<QVector<McuPackage *> >(
|
|
|
|
|
tcPkgs.values(), [&](McuToolChainPackage *tcPkg) { return tcPkg; }));
|
|
|
|
|
packages->append(vendorPkgs.values().toVector());
|
2020-08-13 13:10:52 +02:00
|
|
|
packages->append(targetFactory.getMcuPackages());
|
2020-05-07 12:38:28 +02:00
|
|
|
|
|
|
|
|
return mcuTargets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QFileInfoList targetDescriptionFiles(const Utils::FilePath &dir)
|
|
|
|
|
{
|
2020-05-15 16:17:15 +02:00
|
|
|
const QDir kitsDir(dir.toString() + "/kits/", "*.json");
|
|
|
|
|
return kitsDir.entryInfoList();
|
2020-05-07 12:38:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static McuTargetDescription parseDescriptionJson(const QByteArray &data)
|
|
|
|
|
{
|
|
|
|
|
const QJsonDocument document = QJsonDocument::fromJson(data);
|
|
|
|
|
const QJsonObject target = document.object();
|
|
|
|
|
const QJsonObject toolchain = target.value("toolchain").toObject();
|
|
|
|
|
const QJsonObject boardSdk = target.value("boardSdk").toObject();
|
2020-07-02 16:05:53 +02:00
|
|
|
const QJsonObject freeRTOS = target.value("freeRTOS").toObject();
|
2020-05-07 12:38:28 +02:00
|
|
|
|
|
|
|
|
const QVariantList colorDepths = target.value("colorDepths").toArray().toVariantList();
|
|
|
|
|
const auto colorDepthsVector = Utils::transform<QVector<int> >(
|
|
|
|
|
colorDepths, [&](const QVariant &colorDepth) { return colorDepth.toInt(); });
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
target.value("qulVersion").toString(),
|
2020-09-18 11:16:37 +02:00
|
|
|
target.value("platform").toString(),
|
|
|
|
|
target.value("platformName").toString(),
|
2020-05-07 12:38:28 +02:00
|
|
|
target.value("platformVendor").toString(),
|
|
|
|
|
colorDepthsVector,
|
|
|
|
|
toolchain.value("id").toString(),
|
2020-06-29 23:21:22 +02:00
|
|
|
boardSdk.value("envVar").toString(),
|
2020-08-17 11:25:59 +02:00
|
|
|
boardSdk.value("name").toString(),
|
|
|
|
|
boardSdk.value("defaultPath").toString(),
|
2020-07-02 16:05:53 +02:00
|
|
|
freeRTOS.value("envVar").toString(),
|
2020-09-18 11:16:37 +02:00
|
|
|
freeRTOS.value("boardSdkSubDir").toString(),
|
|
|
|
|
boardSdk.empty() ? McuTargetDescription::TargetType::Desktop : McuTargetDescription::TargetType::MCU
|
2020-05-07 12:38:28 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void targetsAndPackages(const Utils::FilePath &dir, QVector<McuPackage *> *packages,
|
|
|
|
|
QVector<McuTarget *> *mcuTargets)
|
|
|
|
|
{
|
|
|
|
|
QList<McuTargetDescription> descriptions;
|
|
|
|
|
|
|
|
|
|
for (const QFileInfo &fileInfo : targetDescriptionFiles(dir)) {
|
|
|
|
|
QFile file(fileInfo.absoluteFilePath());
|
|
|
|
|
if (!file.open(QFile::ReadOnly))
|
|
|
|
|
continue;
|
|
|
|
|
const McuTargetDescription desc = parseDescriptionJson(file.readAll());
|
2020-06-30 17:09:03 +02:00
|
|
|
if (QVersionNumber::fromString(desc.qulVersion) < McuSupportOptions::minimalQulVersion())
|
2020-06-18 19:03:44 +02:00
|
|
|
return; // Invalid version means invalid SDK installation.
|
2020-05-07 12:38:28 +02:00
|
|
|
descriptions.append(desc);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 11:16:37 +02:00
|
|
|
// Workaround for missing JSON file for Desktop target.
|
|
|
|
|
// Desktop JSON file is shipped starting from Qul 1.5.
|
|
|
|
|
// This whole section could be removed when minimalQulVersion will reach 1.5 or above
|
|
|
|
|
{
|
|
|
|
|
const bool hasDesktopDescription = Utils::contains(descriptions, [](const McuTargetDescription &desc) {
|
|
|
|
|
return desc.type == McuTargetDescription::TargetType::Desktop;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!hasDesktopDescription) {
|
|
|
|
|
Utils::FilePath desktopLib;
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost())
|
|
|
|
|
desktopLib = dir / "lib/QulQuickUltralite_QT_32bpp_Windows_Release.lib";
|
|
|
|
|
else
|
|
|
|
|
desktopLib = dir / "lib/libQulQuickUltralite_QT_32bpp_Linux_Debug.a";
|
|
|
|
|
|
|
|
|
|
if (desktopLib.exists()) {
|
|
|
|
|
McuTargetDescription desktopDescription;
|
|
|
|
|
desktopDescription.qulVersion = descriptions.empty() ?
|
|
|
|
|
McuSupportOptions::minimalQulVersion().toString()
|
|
|
|
|
: descriptions.first().qulVersion;
|
|
|
|
|
desktopDescription.platform = "Qt";
|
|
|
|
|
desktopDescription.platformName = "Desktop";
|
|
|
|
|
desktopDescription.platformVendor = "Qt";
|
|
|
|
|
desktopDescription.colorDepths = {32};
|
|
|
|
|
desktopDescription.toolchainId = Utils::HostOsInfo::isWindowsHost() ? QString("msvc") : QString("gcc");
|
|
|
|
|
desktopDescription.type = McuTargetDescription::TargetType::Desktop;
|
|
|
|
|
descriptions.prepend(desktopDescription);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-07 12:38:28 +02:00
|
|
|
}
|
2020-06-18 19:03:44 +02:00
|
|
|
|
|
|
|
|
mcuTargets->append(targetsFromDescriptions(descriptions, packages));
|
2020-09-18 11:16:37 +02:00
|
|
|
|
|
|
|
|
// Keep targets sorted lexicographically
|
|
|
|
|
std::sort(mcuTargets->begin(), mcuTargets->end(), [] (const McuTarget* lhs, const McuTarget* rhs) {
|
|
|
|
|
return McuSupportOptions::kitName(lhs) < McuSupportOptions::kitName(rhs);
|
|
|
|
|
});
|
2020-03-12 14:25:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Sdk
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace McuSupport
|