aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2019-02-15 16:13:45 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2019-02-18 12:58:54 +0000
commit75e0c58ab43c60c2881ed827fabf1de51be02ec8 (patch)
tree550f22b1c19e7a52480b49c98f1f00d494ecc604
parentcdd62709b06def6bd78f7a3c4b5dff8173bc6130 (diff)
bare-metal: Add possibility to create the IAR toolchain profile
... from the qbs console using the 'setup-toolchains' command. To create the IAR profile it is enougth to use the following command: qbs setup-toolchains --type iar <path/to/iar/compiler/binary> <profile name> A toolchain type can be omitted; in this case the QBS will tries to detect the toolchain type from the specified compiler name. Also it is possible to auto-detect the IAR toolchain from the PATH environment using the following command: qbs setup-toolchain --detect At current time are supported the following IAR toolchains: * for 8051 * for ARM * for AVR Change-Id: I5cdc406e475da7c6649427138b8852239012dbea Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--doc/reference/cli/cli-options.qdocinc1
-rw-r--r--src/app/qbs-setup-toolchains/probe.cpp67
2 files changed, 68 insertions, 0 deletions
diff --git a/doc/reference/cli/cli-options.qdocinc b/doc/reference/cli/cli-options.qdocinc
index 2111d8a2d..7d2e36376 100644
--- a/doc/reference/cli/cli-options.qdocinc
+++ b/doc/reference/cli/cli-options.qdocinc
@@ -494,6 +494,7 @@
\li \c gcc
\li \c mingw
\li \c msvc
+ \li \c iar
\endlist
//! [type]
diff --git a/src/app/qbs-setup-toolchains/probe.cpp b/src/app/qbs-setup-toolchains/probe.cpp
index 4ca146853..2195106a1 100644
--- a/src/app/qbs-setup-toolchains/probe.cpp
+++ b/src/app/qbs-setup-toolchains/probe.cpp
@@ -108,6 +108,18 @@ static QStringList validMinGWMachines()
<< QLatin1String("i586-mingw32msvc") << QLatin1String("amd64-mingw32msvc");
}
+static QStringList knownIarCompilerNames()
+{
+ return { QLatin1String("icc8051"), QLatin1String("iccarm"), QLatin1String("iccavr") };
+}
+
+static bool isIarCompiler(const QString &compilerName)
+{
+ return Internal::any_of(knownIarCompilerNames(), [compilerName](const QString &knownName) {
+ return compilerName.contains(knownName);
+ });
+}
+
static QStringList toolchainTypeFromCompilerName(const QString &compilerName)
{
if (compilerName == QLatin1String("cl.exe"))
@@ -120,6 +132,8 @@ static QStringList toolchainTypeFromCompilerName(const QString &compilerName)
}
if (compilerName == QLatin1String("g++"))
return canonicalToolchain(QLatin1String("gcc"));
+ if (isIarCompiler(compilerName))
+ return canonicalToolchain(QLatin1String("iar"));
return QStringList();
}
@@ -237,6 +251,38 @@ static Profile createGccProfile(const QString &compilerFilePath, Settings *setti
return profile;
}
+static QString guessIarArchitecture(const QFileInfo &compiler)
+{
+ const auto baseName = compiler.baseName();
+ if (baseName == QLatin1String("icc8051"))
+ return QLatin1String("mcs51");
+ if (baseName == QLatin1String("iccarm"))
+ return QLatin1String("arm");
+ if (baseName == QLatin1String("iccavr"))
+ return QLatin1String("avr");
+ return {};
+}
+
+static Profile createIarProfile(const QFileInfo &compiler, Settings *settings,
+ QString profileName = QString())
+{
+ const QString architecture = guessIarArchitecture(compiler);
+
+ // In case the profile is auto-detected.
+ if (profileName.isEmpty())
+ profileName = QLatin1String("iar-") + architecture;
+
+ Profile profile(profileName, settings);
+ profile.setValue(QLatin1String("cpp.toolchainInstallPath"), compiler.absolutePath());
+ profile.setValue(QLatin1String("qbs.toolchainType"), QLatin1String("iar"));
+ profile.setValue(QLatin1String("qbs.architecture"), architecture);
+
+ qStdout << Tr::tr("Profile '%1' created for '%2'.").arg(
+ profile.name(), compiler.absoluteFilePath())
+ << endl;
+ return profile;
+}
+
static void gccProbe(Settings *settings, QList<Profile> &profiles, const QString &compilerName)
{
qStdout << Tr::tr("Trying to detect %1...").arg(compilerName) << endl;
@@ -275,6 +321,24 @@ static void mingwProbe(Settings *settings, QList<Profile> &profiles)
}
}
+static void iarProbe(Settings *settings, QList<Profile> &profiles)
+{
+ qStdout << Tr::tr("Trying to detect IAR toolchains...") << endl;
+
+ bool isFound = false;
+ for (const QString &compilerName : knownIarCompilerNames()) {
+ const QString iarPath = findExecutable(HostOsInfo::appendExecutableSuffix(compilerName));
+ if (!iarPath.isEmpty()) {
+ const auto profile = createIarProfile(iarPath, settings);
+ profiles.push_back(profile);
+ isFound = true;
+ }
+ }
+
+ if (!isFound)
+ qStdout << Tr::tr("No IAR toolchains found.") << endl;
+}
+
void probe(Settings *settings)
{
QList<Profile> profiles;
@@ -290,6 +354,7 @@ void probe(Settings *settings)
}
mingwProbe(settings, profiles);
+ iarProbe(settings, profiles);
if (profiles.empty()) {
qStderr << Tr::tr("Could not detect any toolchains. No profile created.") << endl;
@@ -322,6 +387,8 @@ void createProfile(const QString &profileName, const QString &toolchainType,
createMsvcProfile(profileName, compiler.absoluteFilePath(), settings);
else if (toolchainTypes.contains(QLatin1String("gcc")))
createGccProfile(compiler.absoluteFilePath(), settings, toolchainTypes, profileName);
+ else if (toolchainTypes.contains(QLatin1String("iar")))
+ createIarProfile(compiler, settings, profileName);
else
throw qbs::ErrorInfo(Tr::tr("Cannot create profile: Unknown toolchain type."));
}