diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2019-02-15 17:03:58 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2019-02-19 13:10:18 +0000 |
commit | 07e82d9b91f3fa52590db2849aef6d5b0062c3a9 (patch) | |
tree | fe2393b2f24b6e7e93fa8b3ed3bc36adb6af6a68 | |
parent | b7708daac26875aa251e5d7f8567f51f76450448 (diff) |
bare-metal: Add possibility to create the KEIL toolchain profile
... from the qbs console using the 'setup-toolchains' command.
To create the KEIL profile it is enougth to use the following
command:
qbs setup-toolchains --type keil <path/to/keil/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 KEIL toolchain from the
PATH environment using the following command:
qbs setup-toolchain --detect
At current time are supported the following KEIL toolchains:
* for 8051
* for ARM
Change-Id: I80241866c3ec49a4294d896c70b65b75a2341a2a
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r-- | doc/reference/cli/cli-options.qdocinc | 1 | ||||
-rw-r--r-- | src/app/qbs-setup-toolchains/probe.cpp | 66 |
2 files changed, 67 insertions, 0 deletions
diff --git a/doc/reference/cli/cli-options.qdocinc b/doc/reference/cli/cli-options.qdocinc index 7d2e36376..2d35bea61 100644 --- a/doc/reference/cli/cli-options.qdocinc +++ b/doc/reference/cli/cli-options.qdocinc @@ -495,6 +495,7 @@ \li \c mingw \li \c msvc \li \c iar + \li \c keil \endlist //! [type] diff --git a/src/app/qbs-setup-toolchains/probe.cpp b/src/app/qbs-setup-toolchains/probe.cpp index 97ba4e0cc..1f43014d3 100644 --- a/src/app/qbs-setup-toolchains/probe.cpp +++ b/src/app/qbs-setup-toolchains/probe.cpp @@ -120,6 +120,18 @@ static bool isIarCompiler(const QString &compilerName) }); } +static QStringList knownKeilCompilerNames() +{ + return { QStringLiteral("c51"), QStringLiteral("armcc") }; +} + +static bool isKeilCompiler(const QString &compilerName) +{ + return Internal::any_of(knownKeilCompilerNames(), [compilerName](const QString &knownName) { + return compilerName.contains(knownName); + }); +} + static QStringList toolchainTypeFromCompilerName(const QString &compilerName) { if (compilerName == QLatin1String("cl.exe")) @@ -134,6 +146,8 @@ static QStringList toolchainTypeFromCompilerName(const QString &compilerName) return canonicalToolchain(QLatin1String("gcc")); if (isIarCompiler(compilerName)) return canonicalToolchain(QLatin1String("iar")); + if (isKeilCompiler(compilerName)) + return canonicalToolchain(QLatin1String("keil")); return QStringList(); } @@ -284,6 +298,37 @@ static Profile createIarProfile(const QFileInfo &compiler, Settings *settings, return profile; } +static QString guessKeilArchitecture(const QFileInfo &compiler) +{ + const auto baseName = compiler.baseName(); + if (baseName == QLatin1String("c51")) + return QStringLiteral("mcs51"); + if (baseName == QLatin1String("armcc")) + return QStringLiteral("arm"); + return {}; +} + +static Profile createKeilProfile(const QFileInfo &compiler, Settings *settings, + QString profileName = QString()) +{ + const QString architecture = guessKeilArchitecture(compiler); + + // In case the profile is auto-detected. + if (profileName.isEmpty()) + profileName = QLatin1String("keil-") + architecture; + + Profile profile(profileName, settings); + profile.setValue(QStringLiteral("cpp.toolchainInstallPath"), compiler.absolutePath()); + profile.setValue(QStringLiteral("qbs.toolchainType"), QStringLiteral("keil")); + if (!architecture.isEmpty()) + profile.setValue(QStringLiteral("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; @@ -340,6 +385,24 @@ static void iarProbe(Settings *settings, QList<Profile> &profiles) qStdout << Tr::tr("No IAR toolchains found.") << endl; } +static void keilProbe(Settings *settings, QList<Profile> &profiles) +{ + qStdout << Tr::tr("Trying to detect KEIL toolchains...") << endl; + + bool isFound = false; + for (const QString &compilerName : knownKeilCompilerNames()) { + const QString keilPath = findExecutable(HostOsInfo::appendExecutableSuffix(compilerName)); + if (!keilPath.isEmpty()) { + const auto profile = createKeilProfile(keilPath, settings); + profiles.push_back(profile); + isFound = true; + } + } + + if (!isFound) + qStdout << Tr::tr("No KEIL toolchains found.") << endl; +} + void probe(Settings *settings) { QList<Profile> profiles; @@ -356,6 +419,7 @@ void probe(Settings *settings) mingwProbe(settings, profiles); iarProbe(settings, profiles); + keilProbe(settings, profiles); if (profiles.empty()) { qStderr << Tr::tr("Could not detect any toolchains. No profile created.") << endl; @@ -390,6 +454,8 @@ void createProfile(const QString &profileName, const QString &toolchainType, createGccProfile(compiler.absoluteFilePath(), settings, toolchainTypes, profileName); else if (toolchainTypes.contains(QLatin1String("iar"))) createIarProfile(compiler, settings, profileName); + else if (toolchainTypes.contains(QLatin1String("keil"))) + createKeilProfile(compiler, settings, profileName); else throw qbs::ErrorInfo(Tr::tr("Cannot create profile: Unknown toolchain type.")); } |