2018-07-02 13:55:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** 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 "cmaketoolsettingsaccessor.h"
|
|
|
|
|
|
|
|
|
|
#include "cmaketool.h"
|
|
|
|
|
#include "cmaketoolmanager.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
#include <app/app_version.h>
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <utils/environment.h>
|
2018-07-02 13:55:58 +02:00
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace CMakeProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// CMakeToolSettingsUpgraders:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2021-05-17 13:11:42 +02:00
|
|
|
class CMakeToolSettingsUpgraderV0 : public VersionUpgrader
|
2018-07-02 13:55:58 +02:00
|
|
|
{
|
|
|
|
|
// Necessary to make Version 1 supported.
|
|
|
|
|
public:
|
2021-05-17 13:11:42 +02:00
|
|
|
CMakeToolSettingsUpgraderV0() : VersionUpgrader(0, "4.6") { }
|
2018-07-02 13:55:58 +02:00
|
|
|
|
|
|
|
|
// NOOP
|
|
|
|
|
QVariantMap upgrade(const QVariantMap &data) final { return data; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// Helpers:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2021-05-17 13:11:42 +02:00
|
|
|
const char CMAKE_TOOL_COUNT_KEY[] = "CMakeTools.Count";
|
|
|
|
|
const char CMAKE_TOOL_DATA_KEY[] = "CMakeTools.";
|
|
|
|
|
const char CMAKE_TOOL_DEFAULT_KEY[] = "CMakeTools.Default";
|
|
|
|
|
const char CMAKE_TOOL_FILENAME[] = "cmaketools.xml";
|
2018-07-02 13:55:58 +02:00
|
|
|
|
|
|
|
|
static std::vector<std::unique_ptr<CMakeTool>> autoDetectCMakeTools()
|
|
|
|
|
{
|
2021-05-17 13:11:42 +02:00
|
|
|
Environment env = Environment::systemEnvironment();
|
2018-07-02 13:55:58 +02:00
|
|
|
|
2021-05-17 13:11:42 +02:00
|
|
|
FilePaths path = env.path();
|
2018-07-02 13:55:58 +02:00
|
|
|
path = Utils::filteredUnique(path);
|
|
|
|
|
|
|
|
|
|
if (HostOsInfo::isWindowsHost()) {
|
2019-11-27 18:03:52 +01:00
|
|
|
for (auto envVar : {"ProgramFiles", "ProgramFiles(x86)", "ProgramW6432"}) {
|
|
|
|
|
if (qEnvironmentVariableIsSet(envVar)) {
|
|
|
|
|
const QString progFiles = qEnvironmentVariable(envVar);
|
2021-09-23 17:38:58 +02:00
|
|
|
path.append(FilePath::fromUserInput(progFiles + "/CMake"));
|
|
|
|
|
path.append(FilePath::fromUserInput(progFiles + "/CMake/bin"));
|
2019-11-27 18:03:52 +01:00
|
|
|
}
|
2018-07-02 13:55:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (HostOsInfo::isMacHost()) {
|
2021-08-10 16:19:02 +02:00
|
|
|
path.append("/Applications/CMake.app/Contents/bin");
|
|
|
|
|
path.append("/usr/local/bin");
|
|
|
|
|
path.append("/opt/local/bin");
|
2018-07-02 13:55:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList execs = env.appendExeExtensions(QLatin1String("cmake"));
|
|
|
|
|
|
2019-12-17 14:07:53 +01:00
|
|
|
FilePaths suspects;
|
2021-05-17 13:11:42 +02:00
|
|
|
foreach (const FilePath &base, path) {
|
2018-07-02 13:55:58 +02:00
|
|
|
if (base.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
QFileInfo fi;
|
|
|
|
|
for (const QString &exec : execs) {
|
|
|
|
|
fi.setFile(QDir(base.toString()), exec);
|
|
|
|
|
if (fi.exists() && fi.isFile() && fi.isExecutable())
|
2019-05-28 13:49:26 +02:00
|
|
|
suspects << FilePath::fromString(fi.absoluteFilePath());
|
2018-07-02 13:55:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<CMakeTool>> found;
|
2019-05-28 13:49:26 +02:00
|
|
|
foreach (const FilePath &command, suspects) {
|
2018-07-02 13:55:58 +02:00
|
|
|
auto item = std::make_unique<CMakeTool>(CMakeTool::AutoDetection, CMakeTool::createId());
|
2019-08-12 14:44:29 +02:00
|
|
|
item->setFilePath(command);
|
2018-07-02 13:55:58 +02:00
|
|
|
item->setDisplayName(CMakeToolManager::tr("System CMake at %1").arg(command.toUserOutput()));
|
|
|
|
|
|
|
|
|
|
found.emplace_back(std::move(item));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static std::vector<std::unique_ptr<CMakeTool>>
|
|
|
|
|
mergeTools(std::vector<std::unique_ptr<CMakeTool>> &sdkTools,
|
|
|
|
|
std::vector<std::unique_ptr<CMakeTool>> &userTools,
|
|
|
|
|
std::vector<std::unique_ptr<CMakeTool>> &autoDetectedTools)
|
|
|
|
|
{
|
2018-07-02 15:11:22 +02:00
|
|
|
std::vector<std::unique_ptr<CMakeTool>> result = std::move(sdkTools);
|
2018-07-02 13:55:58 +02:00
|
|
|
while (userTools.size() > 0) {
|
|
|
|
|
std::unique_ptr<CMakeTool> userTool = std::move(userTools[0]);
|
|
|
|
|
userTools.erase(std::begin(userTools));
|
|
|
|
|
|
2021-06-25 18:10:45 +02:00
|
|
|
int userToolIndex = Utils::indexOf(result, Utils::equal(&CMakeTool::id, userTool->id()));
|
|
|
|
|
if (userToolIndex >= 0) {
|
|
|
|
|
// Replace the sdk tool with the user tool, so any user changes do not get lost
|
|
|
|
|
result[userToolIndex] = std::move(userTool);
|
|
|
|
|
} else {
|
2018-07-02 13:55:58 +02:00
|
|
|
if (userTool->isAutoDetected()
|
|
|
|
|
&& !Utils::contains(autoDetectedTools, Utils::equal(&CMakeTool::cmakeExecutable,
|
|
|
|
|
userTool->cmakeExecutable()))) {
|
|
|
|
|
|
|
|
|
|
qWarning() << QString::fromLatin1("Previously SDK provided CMakeTool \"%1\" (%2) dropped.")
|
|
|
|
|
.arg(userTool->cmakeExecutable().toUserOutput(), userTool->id().toString());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
result.emplace_back(std::move(userTool));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add all the autodetected tools that are not known yet
|
|
|
|
|
while (autoDetectedTools.size() > 0) {
|
|
|
|
|
std::unique_ptr<CMakeTool> autoDetectedTool = std::move(autoDetectedTools[0]);
|
|
|
|
|
autoDetectedTools.erase(std::begin(autoDetectedTools));
|
|
|
|
|
|
|
|
|
|
if (!Utils::contains(result,
|
|
|
|
|
Utils::equal(&CMakeTool::cmakeExecutable, autoDetectedTool->cmakeExecutable())))
|
|
|
|
|
result.emplace_back(std::move(autoDetectedTool));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// CMakeToolSettingsAccessor:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
CMakeToolSettingsAccessor::CMakeToolSettingsAccessor() :
|
|
|
|
|
UpgradingSettingsAccessor("QtCreatorCMakeTools",
|
|
|
|
|
QCoreApplication::translate("CMakeProjectManager::CMakeToolManager", "CMake"),
|
|
|
|
|
Core::Constants::IDE_DISPLAY_NAME)
|
|
|
|
|
{
|
2021-04-26 15:46:09 +02:00
|
|
|
setBaseFilePath(Core::ICore::userResourcePath(CMAKE_TOOL_FILENAME));
|
2018-07-02 13:55:58 +02:00
|
|
|
|
|
|
|
|
addVersionUpgrader(std::make_unique<CMakeToolSettingsUpgraderV0>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeToolSettingsAccessor::CMakeTools CMakeToolSettingsAccessor::restoreCMakeTools(QWidget *parent) const
|
|
|
|
|
{
|
|
|
|
|
CMakeTools result;
|
|
|
|
|
|
2021-04-26 15:46:09 +02:00
|
|
|
const FilePath sdkSettingsFile = Core::ICore::installerResourcePath(CMAKE_TOOL_FILENAME);
|
2018-07-02 13:55:58 +02:00
|
|
|
|
|
|
|
|
CMakeTools sdkTools = cmakeTools(restoreSettings(sdkSettingsFile, parent), true);
|
|
|
|
|
|
|
|
|
|
//read the tools from the user settings file
|
|
|
|
|
CMakeTools userTools = cmakeTools(restoreSettings(parent), false);
|
|
|
|
|
|
|
|
|
|
//autodetect tools
|
|
|
|
|
std::vector<std::unique_ptr<CMakeTool>> autoDetectedTools = autoDetectCMakeTools();
|
|
|
|
|
|
|
|
|
|
//filter out the tools that were stored in SDK
|
|
|
|
|
std::vector<std::unique_ptr<CMakeTool>> toRegister = mergeTools(sdkTools.cmakeTools,
|
|
|
|
|
userTools.cmakeTools,
|
|
|
|
|
autoDetectedTools);
|
|
|
|
|
|
|
|
|
|
// Store all tools
|
|
|
|
|
for (auto it = std::begin(toRegister); it != std::end(toRegister); ++it)
|
|
|
|
|
result.cmakeTools.emplace_back(std::move(*it));
|
|
|
|
|
|
|
|
|
|
result.defaultToolId = userTools.defaultToolId.isValid() ? userTools.defaultToolId : sdkTools.defaultToolId;
|
|
|
|
|
|
|
|
|
|
// Set default TC...
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeToolSettingsAccessor::saveCMakeTools(const QList<CMakeTool *> &cmakeTools,
|
2021-05-17 13:11:42 +02:00
|
|
|
const Id &defaultId,
|
2018-07-02 13:55:58 +02:00
|
|
|
QWidget *parent)
|
|
|
|
|
{
|
|
|
|
|
QVariantMap data;
|
|
|
|
|
data.insert(QLatin1String(CMAKE_TOOL_DEFAULT_KEY), defaultId.toSetting());
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
for (const CMakeTool *item : cmakeTools) {
|
2021-07-14 15:20:37 +02:00
|
|
|
Utils::FilePath fi = item->cmakeExecutable();
|
2018-07-02 13:55:58 +02:00
|
|
|
|
2021-10-04 09:40:33 +02:00
|
|
|
if (fi.needsDevice() || fi.isExecutableFile()) { // be graceful for device related stuff
|
2018-07-02 13:55:58 +02:00
|
|
|
QVariantMap tmp = item->toMap();
|
|
|
|
|
if (tmp.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
data.insert(QString::fromLatin1(CMAKE_TOOL_DATA_KEY) + QString::number(count), tmp);
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
data.insert(QLatin1String(CMAKE_TOOL_COUNT_KEY), count);
|
|
|
|
|
|
|
|
|
|
saveSettings(data, parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeToolSettingsAccessor::CMakeTools
|
|
|
|
|
CMakeToolSettingsAccessor::cmakeTools(const QVariantMap &data, bool fromSdk) const
|
|
|
|
|
{
|
|
|
|
|
CMakeTools result;
|
|
|
|
|
|
|
|
|
|
int count = data.value(QLatin1String(CMAKE_TOOL_COUNT_KEY), 0).toInt();
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
|
const QString key = QString::fromLatin1(CMAKE_TOOL_DATA_KEY) + QString::number(i);
|
|
|
|
|
if (!data.contains(key))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const QVariantMap dbMap = data.value(key).toMap();
|
|
|
|
|
auto item = std::make_unique<CMakeTool>(dbMap, fromSdk);
|
2021-07-14 15:26:56 +02:00
|
|
|
if (item->isAutoDetected() && !item->cmakeExecutable().isExecutableFile()) {
|
2018-07-02 13:55:58 +02:00
|
|
|
qWarning() << QString::fromLatin1("CMakeTool \"%1\" (%2) dropped since the command is not executable.")
|
|
|
|
|
.arg(item->cmakeExecutable().toUserOutput(), item->id().toString());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.cmakeTools.emplace_back(std::move(item));
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 13:11:42 +02:00
|
|
|
result.defaultToolId = Id::fromSetting(data.value(CMAKE_TOOL_DEFAULT_KEY, Id().toSetting()));
|
2018-07-02 13:55:58 +02:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace CMakeProjectManager
|