forked from qt-creator/qt-creator
CMakeProjectManager: Provide way for plugins to autodetect cmake tools
This patch adds support for plugins to register a callback/lambda to autodetect CMakeTools that would not be found by the default auto- detection function. Without this feature the CMakeToolManager would drop autodetected CMakeTools otherwise on every start. Change-Id: I23b146e5b9acc60018ac87ea4b6cc7573fa0dd30 Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
@@ -73,7 +73,6 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
|
|||||||
addAutoReleasedObject(new CMakeLocatorFilter);
|
addAutoReleasedObject(new CMakeLocatorFilter);
|
||||||
|
|
||||||
new CMakeToolManager(this);
|
new CMakeToolManager(this);
|
||||||
CMakeToolManager::restoreCMakeTools();
|
|
||||||
|
|
||||||
ProjectExplorer::KitManager::registerKitInformation(new CMakeKitInformation);
|
ProjectExplorer::KitManager::registerKitInformation(new CMakeKitInformation);
|
||||||
|
|
||||||
@@ -82,4 +81,6 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
|
|||||||
|
|
||||||
void CMakeProjectPlugin::extensionsInitialized()
|
void CMakeProjectPlugin::extensionsInitialized()
|
||||||
{
|
{
|
||||||
|
//restore the cmake tools before loading the kits
|
||||||
|
CMakeToolManager::restoreCMakeTools();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "cmaketoolmanager.h"
|
#include "cmaketoolmanager.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <projectexplorer/toolchainmanager.h>
|
||||||
#include <utils/persistentsettings.h>
|
#include <utils/persistentsettings.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
@@ -42,6 +43,7 @@
|
|||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
namespace CMakeProjectManager {
|
namespace CMakeProjectManager {
|
||||||
|
|
||||||
@@ -65,6 +67,7 @@ public:
|
|||||||
Id m_defaultCMake;
|
Id m_defaultCMake;
|
||||||
QList<CMakeTool *> m_cmakeTools;
|
QList<CMakeTool *> m_cmakeTools;
|
||||||
PersistentSettingsWriter *m_writer;
|
PersistentSettingsWriter *m_writer;
|
||||||
|
QList<CMakeToolManager::AutodetectionHelper> m_autoDetectionHelpers;
|
||||||
};
|
};
|
||||||
static CMakeToolManagerPrivate *d = 0;
|
static CMakeToolManagerPrivate *d = 0;
|
||||||
|
|
||||||
@@ -186,6 +189,10 @@ static QList<CMakeTool *> autoDetectCMakeTools()
|
|||||||
found.append(item);
|
found.append(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//execute custom helpers if available
|
||||||
|
foreach (CMakeToolManager::AutodetectionHelper source, d->m_autoDetectionHelpers)
|
||||||
|
found.append(source());
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,8 +370,8 @@ void CMakeToolManager::restoreCMakeTools()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//filter out the tools that are already known
|
//filter out the tools that are already known
|
||||||
for (int i = autoDetected.size() - 1; i >= 0; i--) {
|
while (autoDetected.size()) {
|
||||||
CMakeTool *currTool = autoDetected.takeAt(i);
|
CMakeTool *currTool = autoDetected.takeFirst();
|
||||||
if (Utils::anyOf(toolsToRegister,
|
if (Utils::anyOf(toolsToRegister,
|
||||||
Utils::equal(&CMakeTool::cmakeExecutable, currTool->cmakeExecutable())))
|
Utils::equal(&CMakeTool::cmakeExecutable, currTool->cmakeExecutable())))
|
||||||
delete currTool;
|
delete currTool;
|
||||||
@@ -390,6 +397,11 @@ void CMakeToolManager::restoreCMakeTools()
|
|||||||
readAndDeleteLegacyCMakeSettings();
|
readAndDeleteLegacyCMakeSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMakeToolManager::registerAutodetectionHelper(CMakeToolManager::AutodetectionHelper helper)
|
||||||
|
{
|
||||||
|
d->m_autoDetectionHelpers.append(helper);
|
||||||
|
}
|
||||||
|
|
||||||
void CMakeToolManager::notifyAboutUpdate(CMakeTool *tool)
|
void CMakeToolManager::notifyAboutUpdate(CMakeTool *tool)
|
||||||
{
|
{
|
||||||
if (!tool || !d->m_cmakeTools.contains(tool))
|
if (!tool || !d->m_cmakeTools.contains(tool))
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <texteditor/codeassist/keywordscompletionassist.h>
|
#include <texteditor/codeassist/keywordscompletionassist.h>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
@@ -45,6 +46,8 @@ class CMAKE_EXPORT CMakeToolManager : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
typedef std::function<QList<CMakeTool *> ()> AutodetectionHelper;
|
||||||
|
|
||||||
CMakeToolManager(QObject *parent);
|
CMakeToolManager(QObject *parent);
|
||||||
~CMakeToolManager();
|
~CMakeToolManager();
|
||||||
|
|
||||||
@@ -62,9 +65,10 @@ public:
|
|||||||
static void setDefaultCMakeTool(const Core::Id &id);
|
static void setDefaultCMakeTool(const Core::Id &id);
|
||||||
static CMakeTool *findByCommand(const Utils::FileName &command);
|
static CMakeTool *findByCommand(const Utils::FileName &command);
|
||||||
static CMakeTool *findById(const Core::Id &id);
|
static CMakeTool *findById(const Core::Id &id);
|
||||||
static void restoreCMakeTools();
|
static void registerAutodetectionHelper(AutodetectionHelper helper);
|
||||||
|
|
||||||
static void notifyAboutUpdate(CMakeTool *);
|
static void notifyAboutUpdate(CMakeTool *);
|
||||||
|
static void restoreCMakeTools();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void cmakeAdded (const Core::Id &id);
|
void cmakeAdded (const Core::Id &id);
|
||||||
|
|||||||
Reference in New Issue
Block a user