forked from qt-creator/qt-creator
Add a locator to compile a specific cmake target
The locator will show all the targets for the cmake projects, even the /fast one. It allows people to build a specific target without reloading the whole project. It's using the make prefix. Change-Id: Ia6701bb19c1ae390af647d94d0a2834b05a1772a Reviewed-by: Eike Ziller <eike.ziller@nokia.com> Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
committed by
Daniel Teske
parent
6de2b28130
commit
aef4a8fbaf
145
src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp
Normal file
145
src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2011 Nicolas Arnaud-Cormos
|
||||||
|
**
|
||||||
|
** Contact: KDAB (info@kdab.com)
|
||||||
|
**
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
**
|
||||||
|
** This file may be used under the terms of the GNU Lesser General Public
|
||||||
|
** License version 2.1 as published by the Free Software Foundation and
|
||||||
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
||||||
|
** Please review the following information to ensure the GNU Lesser General
|
||||||
|
** Public License version 2.1 requirements will be met:
|
||||||
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** Other Usage
|
||||||
|
**
|
||||||
|
** Alternatively, this file may be used in accordance with the terms and
|
||||||
|
** conditions contained in a signed written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at info@qt.nokia.com.
|
||||||
|
**
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#include "cmakelocatorfilter.h"
|
||||||
|
#include "cmaketarget.h"
|
||||||
|
#include "cmakeproject.h"
|
||||||
|
#include "makestep.h"
|
||||||
|
|
||||||
|
#include <projectexplorer/projectexplorer.h>
|
||||||
|
#include <projectexplorer/session.h>
|
||||||
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
|
#include <projectexplorer/buildsteplist.h>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace CMakeProjectManager;
|
||||||
|
using namespace CMakeProjectManager::Internal;
|
||||||
|
|
||||||
|
CMakeLocatorFilter::CMakeLocatorFilter()
|
||||||
|
{
|
||||||
|
setShortcutString(QLatin1String("cm"));
|
||||||
|
|
||||||
|
ProjectExplorer::SessionManager *sm = ProjectExplorer::ProjectExplorerPlugin::instance()->session();
|
||||||
|
connect(sm, SIGNAL(projectAdded(ProjectExplorer::Project*)),
|
||||||
|
this, SLOT(slotProjectListUpdated()));
|
||||||
|
connect(sm, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
|
||||||
|
this, SLOT(slotProjectListUpdated()));
|
||||||
|
}
|
||||||
|
|
||||||
|
CMakeLocatorFilter::~CMakeLocatorFilter()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Locator::FilterEntry> CMakeLocatorFilter::matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry)
|
||||||
|
{
|
||||||
|
Q_UNUSED(future)
|
||||||
|
QList<Locator::FilterEntry> result;
|
||||||
|
|
||||||
|
QList<ProjectExplorer::Project *> projects =
|
||||||
|
ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projects();
|
||||||
|
foreach (ProjectExplorer::Project *p, projects) {
|
||||||
|
CMakeProject *cmakeProject = qobject_cast<CMakeProject *>(p);
|
||||||
|
if (cmakeProject) {
|
||||||
|
foreach (CMakeBuildTarget ct, cmakeProject->buildTargets()) {
|
||||||
|
if (ct.title.contains(entry)) {
|
||||||
|
Locator::FilterEntry entry(this, ct.title, cmakeProject->file()->fileName());
|
||||||
|
entry.extraInfo = cmakeProject->file()->fileName();
|
||||||
|
result.append(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMakeLocatorFilter::accept(Locator::FilterEntry selection) const
|
||||||
|
{
|
||||||
|
// Get the project containing the target selected
|
||||||
|
CMakeProject *cmakeProject = 0;
|
||||||
|
|
||||||
|
QList<ProjectExplorer::Project *> projects =
|
||||||
|
ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projects();
|
||||||
|
foreach (ProjectExplorer::Project *p, projects) {
|
||||||
|
cmakeProject = qobject_cast<CMakeProject *>(p);
|
||||||
|
if (cmakeProject && cmakeProject->file()->fileName() == selection.internalData.toString())
|
||||||
|
break;
|
||||||
|
cmakeProject = 0;
|
||||||
|
}
|
||||||
|
if (!cmakeProject)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Find the make step
|
||||||
|
MakeStep *makeStep = 0;
|
||||||
|
ProjectExplorer::BuildStepList *buildStepList = cmakeProject->activeTarget()->activeBuildConfiguration()
|
||||||
|
->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
||||||
|
for (int i = 0; i < buildStepList->count(); ++i) {
|
||||||
|
makeStep = qobject_cast<MakeStep *>(buildStepList->at(i));
|
||||||
|
if (makeStep)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!makeStep)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Change the make step to build only the given target
|
||||||
|
QStringList oldTargets = makeStep->buildTargets();
|
||||||
|
makeStep->setClean(false);
|
||||||
|
makeStep->clearBuildTargets();
|
||||||
|
makeStep->setBuildTarget(selection.displayName, true);
|
||||||
|
|
||||||
|
// Build
|
||||||
|
ProjectExplorer::ProjectExplorerPlugin::instance()->buildProject(cmakeProject);
|
||||||
|
makeStep->setBuildTargets(oldTargets);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMakeLocatorFilter::refresh(QFutureInterface<void> &future)
|
||||||
|
{
|
||||||
|
Q_UNUSED(future)
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMakeLocatorFilter::slotProjectListUpdated()
|
||||||
|
{
|
||||||
|
CMakeProject *cmakeProject = 0;
|
||||||
|
|
||||||
|
QList<ProjectExplorer::Project *> projects =
|
||||||
|
ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projects();
|
||||||
|
foreach (ProjectExplorer::Project *p, projects) {
|
||||||
|
cmakeProject = qobject_cast<CMakeProject *>(p);
|
||||||
|
if (cmakeProject)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide the locator if there's no CMake project
|
||||||
|
setHidden(!cmakeProject);
|
||||||
|
}
|
||||||
66
src/plugins/cmakeprojectmanager/cmakelocatorfilter.h
Normal file
66
src/plugins/cmakeprojectmanager/cmakelocatorfilter.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2011 Nicolas Arnaud-Cormos
|
||||||
|
**
|
||||||
|
** Contact: KDAB (info@kdab.com)
|
||||||
|
**
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
**
|
||||||
|
** This file may be used under the terms of the GNU Lesser General Public
|
||||||
|
** License version 2.1 as published by the Free Software Foundation and
|
||||||
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
||||||
|
** Please review the following information to ensure the GNU Lesser General
|
||||||
|
** Public License version 2.1 requirements will be met:
|
||||||
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
** Other Usage
|
||||||
|
**
|
||||||
|
** Alternatively, this file may be used in accordance with the terms and
|
||||||
|
** conditions contained in a signed written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** If you have questions regarding the use of this file, please contact
|
||||||
|
** Nokia at info@qt.nokia.com.
|
||||||
|
**
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CMAKEPROJECTMANAGER_INTERNAL_CMAKEFILTER_H
|
||||||
|
#define CMAKEPROJECTMANAGER_INTERNAL_CMAKEFILTER_H
|
||||||
|
|
||||||
|
#include <locator/ilocatorfilter.h>
|
||||||
|
|
||||||
|
#include <QtGui/QIcon>
|
||||||
|
|
||||||
|
namespace CMakeProjectManager {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class CMakeLocatorFilter : public Locator::ILocatorFilter
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
CMakeLocatorFilter();
|
||||||
|
~CMakeLocatorFilter();
|
||||||
|
|
||||||
|
QString displayName() const { return tr("Build CMake target"); }
|
||||||
|
QString id() const { return QLatin1String("Build CMake target"); }
|
||||||
|
Priority priority() const { return Medium; }
|
||||||
|
|
||||||
|
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||||
|
void accept(Locator::FilterEntry selection) const;
|
||||||
|
void refresh(QFutureInterface<void> &future);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void slotProjectListUpdated();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace CMakeProjectManager
|
||||||
|
|
||||||
|
#endif // CMAKEPROJECTMANAGER_INTERNAL_CMAKEFILTER_H
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/cmakeproject" >
|
<qresource prefix="/cmakeproject">
|
||||||
<file>CMakeProject.mimetypes.xml</file>
|
<file>CMakeProject.mimetypes.xml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
TARGET = CMakeProjectManager
|
TARGET = CMakeProjectManager
|
||||||
|
|
||||||
include(../../qtcreatorplugin.pri)
|
include(../../qtcreatorplugin.pri)
|
||||||
include(cmakeprojectmanager_dependencies.pri)
|
include(cmakeprojectmanager_dependencies.pri)
|
||||||
|
|
||||||
HEADERS = cmakeproject.h \
|
HEADERS = cmakeproject.h \
|
||||||
cmakeprojectplugin.h \
|
cmakeprojectplugin.h \
|
||||||
cmakeprojectmanager.h \
|
cmakeprojectmanager.h \
|
||||||
@@ -15,7 +17,9 @@ HEADERS = cmakeproject.h \
|
|||||||
cmakeeditorfactory.h \
|
cmakeeditorfactory.h \
|
||||||
cmakeeditor.h \
|
cmakeeditor.h \
|
||||||
cmakehighlighter.h \
|
cmakehighlighter.h \
|
||||||
cmakeuicodemodelsupport.h
|
cmakeuicodemodelsupport.h \
|
||||||
|
cmakelocatorfilter.h
|
||||||
|
|
||||||
SOURCES = cmakeproject.cpp \
|
SOURCES = cmakeproject.cpp \
|
||||||
cmakeprojectplugin.cpp \
|
cmakeprojectplugin.cpp \
|
||||||
cmakeprojectmanager.cpp \
|
cmakeprojectmanager.cpp \
|
||||||
@@ -28,8 +32,11 @@ SOURCES = cmakeproject.cpp \
|
|||||||
cmakeeditorfactory.cpp \
|
cmakeeditorfactory.cpp \
|
||||||
cmakeeditor.cpp \
|
cmakeeditor.cpp \
|
||||||
cmakehighlighter.cpp \
|
cmakehighlighter.cpp \
|
||||||
cmakeuicodemodelsupport.cpp
|
cmakeuicodemodelsupport.cpp \
|
||||||
|
cmakelocatorfilter.cpp
|
||||||
|
|
||||||
RESOURCES += cmakeproject.qrc
|
RESOURCES += cmakeproject.qrc
|
||||||
|
|
||||||
FORMS +=
|
FORMS +=
|
||||||
|
|
||||||
OTHER_FILES += CMakeProject.mimetypes.xml
|
OTHER_FILES += CMakeProject.mimetypes.xml
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include "makestep.h"
|
#include "makestep.h"
|
||||||
#include "cmakeprojectconstants.h"
|
#include "cmakeprojectconstants.h"
|
||||||
#include "cmaketarget.h"
|
#include "cmaketarget.h"
|
||||||
|
#include "cmakelocatorfilter.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/mimedatabase.h>
|
#include <coreplugin/mimedatabase.h>
|
||||||
@@ -72,6 +73,7 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
|
|||||||
|
|
||||||
addAutoReleasedObject(new CMakeEditorFactory(manager, editorHandler));
|
addAutoReleasedObject(new CMakeEditorFactory(manager, editorHandler));
|
||||||
addAutoReleasedObject(new CMakeTargetFactory);
|
addAutoReleasedObject(new CMakeTargetFactory);
|
||||||
|
addAutoReleasedObject(new CMakeLocatorFilter);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,6 +187,11 @@ void MakeStep::stdOutput(const QString &line)
|
|||||||
AbstractProcessStep::stdOutput(line);
|
AbstractProcessStep::stdOutput(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList MakeStep::buildTargets() const
|
||||||
|
{
|
||||||
|
return m_buildTargets;
|
||||||
|
}
|
||||||
|
|
||||||
bool MakeStep::buildsBuildTarget(const QString &target) const
|
bool MakeStep::buildsBuildTarget(const QString &target) const
|
||||||
{
|
{
|
||||||
return m_buildTargets.contains(target);
|
return m_buildTargets.contains(target);
|
||||||
@@ -202,6 +207,16 @@ void MakeStep::setBuildTarget(const QString &buildTarget, bool on)
|
|||||||
m_buildTargets = old;
|
m_buildTargets = old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MakeStep::setBuildTargets(const QStringList &targets)
|
||||||
|
{
|
||||||
|
m_buildTargets = targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MakeStep::clearBuildTargets()
|
||||||
|
{
|
||||||
|
m_buildTargets.clear();
|
||||||
|
}
|
||||||
|
|
||||||
QString MakeStep::additionalArguments() const
|
QString MakeStep::additionalArguments() const
|
||||||
{
|
{
|
||||||
return m_additionalArguments;
|
return m_additionalArguments;
|
||||||
|
|||||||
@@ -66,8 +66,13 @@ public:
|
|||||||
|
|
||||||
virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
|
virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
|
||||||
virtual bool immutable() const;
|
virtual bool immutable() const;
|
||||||
|
|
||||||
|
QStringList buildTargets() const;
|
||||||
bool buildsBuildTarget(const QString &target) const;
|
bool buildsBuildTarget(const QString &target) const;
|
||||||
void setBuildTarget(const QString &target, bool on);
|
void setBuildTarget(const QString &target, bool on);
|
||||||
|
void setBuildTargets(const QStringList &targets);
|
||||||
|
void clearBuildTargets();
|
||||||
|
|
||||||
QString additionalArguments() const;
|
QString additionalArguments() const;
|
||||||
void setAdditionalArguments(const QString &list);
|
void setAdditionalArguments(const QString &list);
|
||||||
|
|
||||||
@@ -75,6 +80,7 @@ public:
|
|||||||
|
|
||||||
QVariantMap toMap() const;
|
QVariantMap toMap() const;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MakeStep(ProjectExplorer::BuildStepList *bsl, MakeStep *bs);
|
MakeStep(ProjectExplorer::BuildStepList *bsl, MakeStep *bs);
|
||||||
MakeStep(ProjectExplorer::BuildStepList *bsl, const QString &id);
|
MakeStep(ProjectExplorer::BuildStepList *bsl, const QString &id);
|
||||||
|
|||||||
Reference in New Issue
Block a user