forked from qt-creator/qt-creator
Integrate target support
* Ease cross device development by introducing 'targets' which group build- and runsettings that are valid for this one target Most of the kudos for the code review go to dt. Con, thorbjorn, ckandler and others did also review parts of this patch. Reviewed-by: dt
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "cmakeopenprojectwizard.h"
|
||||
#include "cmakeproject.h"
|
||||
#include "cmaketarget.h"
|
||||
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -46,25 +47,17 @@ const char * const CMAKE_BC_ID("CMakeProjectManager.CMakeBuildConfiguration");
|
||||
const char * const USER_ENVIRONMENT_CHANGES_KEY("CMakeProjectManager.CMakeBuildConfiguration.UserEnvironmentChanges");
|
||||
const char * const MSVC_VERSION_KEY("CMakeProjectManager.CMakeBuildConfiguration.MsvcVersion");
|
||||
const char * const BUILD_DIRECTORY_KEY("CMakeProjectManager.CMakeBuildConfiguration.BuildDirectory");
|
||||
} // namespace
|
||||
|
||||
}
|
||||
|
||||
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeProject *project) :
|
||||
BuildConfiguration(project, QLatin1String(CMAKE_BC_ID)),
|
||||
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeTarget *parent) :
|
||||
BuildConfiguration(parent, QLatin1String(CMAKE_BC_ID)),
|
||||
m_toolChain(0),
|
||||
m_clearSystemEnvironment(false)
|
||||
{
|
||||
}
|
||||
|
||||
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeProject *project, const QString &id) :
|
||||
BuildConfiguration(project, id),
|
||||
m_toolChain(0),
|
||||
m_clearSystemEnvironment(false)
|
||||
{
|
||||
}
|
||||
|
||||
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeProject *pro, CMakeBuildConfiguration *source) :
|
||||
BuildConfiguration(pro, source),
|
||||
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeTarget *parent, CMakeBuildConfiguration *source) :
|
||||
BuildConfiguration(parent, source),
|
||||
m_toolChain(0),
|
||||
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
|
||||
m_userEnvironmentChanges(source->m_userEnvironmentChanges),
|
||||
@@ -97,9 +90,9 @@ CMakeBuildConfiguration::~CMakeBuildConfiguration()
|
||||
delete m_toolChain;
|
||||
}
|
||||
|
||||
CMakeProject *CMakeBuildConfiguration::cmakeProject() const
|
||||
CMakeTarget *CMakeBuildConfiguration::cmakeTarget() const
|
||||
{
|
||||
return static_cast<CMakeProject *>(project());
|
||||
return static_cast<CMakeTarget *>(target());
|
||||
}
|
||||
|
||||
ProjectExplorer::Environment CMakeBuildConfiguration::baseEnvironment() const
|
||||
@@ -155,7 +148,7 @@ QString CMakeBuildConfiguration::buildDirectory() const
|
||||
{
|
||||
QString buildDirectory = m_buildDirectory;
|
||||
if (buildDirectory.isEmpty())
|
||||
buildDirectory = cmakeProject()->sourceDirectory() + "/qtcreator-build";
|
||||
buildDirectory = cmakeTarget()->cmakeProject()->sourceDirectory() + "/qtcreator-build";
|
||||
return buildDirectory;
|
||||
}
|
||||
|
||||
@@ -230,9 +223,9 @@ CMakeBuildConfigurationFactory::~CMakeBuildConfigurationFactory()
|
||||
{
|
||||
}
|
||||
|
||||
QStringList CMakeBuildConfigurationFactory::availableCreationIds(ProjectExplorer::Project *parent) const
|
||||
QStringList CMakeBuildConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
|
||||
{
|
||||
if (!qobject_cast<CMakeProject *>(parent))
|
||||
if (!qobject_cast<CMakeTarget *>(parent))
|
||||
return QStringList();
|
||||
return QStringList() << QLatin1String(CMAKE_BC_ID);
|
||||
}
|
||||
@@ -244,22 +237,22 @@ QString CMakeBuildConfigurationFactory::displayNameForId(const QString &id) cons
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool CMakeBuildConfigurationFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
|
||||
bool CMakeBuildConfigurationFactory::canCreate(ProjectExplorer::Target *parent, const QString &id) const
|
||||
{
|
||||
if (!qobject_cast<CMakeProject *>(parent))
|
||||
if (!qobject_cast<CMakeTarget *>(parent))
|
||||
return false;
|
||||
if (id == QLatin1String(CMAKE_BC_ID))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer::Project *parent, const QString &id)
|
||||
CMakeBuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer::Target *parent, const QString &id)
|
||||
{
|
||||
if (!canCreate(parent, id))
|
||||
return 0;
|
||||
|
||||
CMakeProject *cmProject = static_cast<CMakeProject *>(parent);
|
||||
Q_ASSERT(cmProject);
|
||||
CMakeTarget *cmtarget = static_cast<CMakeTarget *>(parent);
|
||||
Q_ASSERT(cmtarget);
|
||||
|
||||
//TODO configuration name should be part of the cmakeopenprojectwizard
|
||||
bool ok;
|
||||
@@ -271,7 +264,7 @@ ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(Proj
|
||||
&ok);
|
||||
if (!ok || buildConfigurationName.isEmpty())
|
||||
return false;
|
||||
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(cmProject);
|
||||
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(cmtarget);
|
||||
bc->setDisplayName(buildConfigurationName);
|
||||
|
||||
MakeStep *makeStep = new MakeStep(bc);
|
||||
@@ -282,53 +275,53 @@ ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(Proj
|
||||
cleanMakeStep->setAdditionalArguments(QStringList() << "clean");
|
||||
cleanMakeStep->setClean(true);
|
||||
|
||||
CMakeOpenProjectWizard copw(cmProject->projectManager(),
|
||||
cmProject->sourceDirectory(),
|
||||
CMakeOpenProjectWizard copw(cmtarget->cmakeProject()->projectManager(),
|
||||
cmtarget->cmakeProject()->sourceDirectory(),
|
||||
bc->buildDirectory(),
|
||||
bc->environment());
|
||||
if (copw.exec() != QDialog::Accepted) {
|
||||
delete bc;
|
||||
return false;
|
||||
}
|
||||
cmProject->addBuildConfiguration(bc); // this also makes the name unique
|
||||
cmtarget->addBuildConfiguration(bc); // this also makes the name unique
|
||||
|
||||
bc->setBuildDirectory(copw.buildDirectory());
|
||||
bc->setMsvcVersion(copw.msvcVersion());
|
||||
cmProject->parseCMakeLists();
|
||||
cmtarget->cmakeProject()->parseCMakeLists();
|
||||
|
||||
// Default to all
|
||||
if (cmProject->hasBuildTarget("all"))
|
||||
if (cmtarget->cmakeProject()->hasBuildTarget("all"))
|
||||
makeStep->setBuildTarget("all", true);
|
||||
|
||||
return bc;
|
||||
}
|
||||
|
||||
bool CMakeBuildConfigurationFactory::canClone(ProjectExplorer::Project *parent, ProjectExplorer::BuildConfiguration *source) const
|
||||
bool CMakeBuildConfigurationFactory::canClone(ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source) const
|
||||
{
|
||||
return canCreate(parent, source->id());
|
||||
}
|
||||
|
||||
ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::clone(ProjectExplorer::Project *parent, ProjectExplorer::BuildConfiguration *source)
|
||||
CMakeBuildConfiguration *CMakeBuildConfigurationFactory::clone(ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source)
|
||||
{
|
||||
if (!canClone(parent, source))
|
||||
return 0;
|
||||
CMakeBuildConfiguration *old = static_cast<CMakeBuildConfiguration *>(source);
|
||||
CMakeProject *cmProject(static_cast<CMakeProject *>(parent));
|
||||
return new CMakeBuildConfiguration(cmProject, old);
|
||||
CMakeTarget *cmtarget(static_cast<CMakeTarget *>(parent));
|
||||
return new CMakeBuildConfiguration(cmtarget, old);
|
||||
}
|
||||
|
||||
bool CMakeBuildConfigurationFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
|
||||
bool CMakeBuildConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
|
||||
{
|
||||
QString id(ProjectExplorer::idFromMap(map));
|
||||
return canCreate(parent, id);
|
||||
}
|
||||
|
||||
ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
|
||||
CMakeBuildConfiguration *CMakeBuildConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
|
||||
{
|
||||
if (!canRestore(parent, map))
|
||||
return 0;
|
||||
CMakeProject *cmProject(static_cast<CMakeProject *>(parent));
|
||||
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(cmProject);
|
||||
CMakeTarget *cmtarget(static_cast<CMakeTarget *>(parent));
|
||||
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(cmtarget);
|
||||
if (bc->fromMap(map))
|
||||
return bc;
|
||||
delete bc;
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
namespace CMakeProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
class CMakeProject;
|
||||
class CMakeTarget;
|
||||
class CMakeBuildConfigurationFactory;
|
||||
|
||||
class CMakeBuildConfiguration : public ProjectExplorer::BuildConfiguration
|
||||
@@ -45,10 +45,10 @@ class CMakeBuildConfiguration : public ProjectExplorer::BuildConfiguration
|
||||
friend class CMakeBuildConfigurationFactory;
|
||||
|
||||
public:
|
||||
CMakeBuildConfiguration(CMakeProject *pro);
|
||||
CMakeBuildConfiguration(CMakeTarget *parent);
|
||||
~CMakeBuildConfiguration();
|
||||
|
||||
CMakeProject *cmakeProject() const;
|
||||
CMakeTarget *cmakeTarget() const;
|
||||
|
||||
ProjectExplorer::Environment environment() const;
|
||||
ProjectExplorer::Environment baseEnvironment() const;
|
||||
@@ -74,8 +74,7 @@ signals:
|
||||
void msvcVersionChanged();
|
||||
|
||||
protected:
|
||||
CMakeBuildConfiguration(CMakeProject *pro, const QString &id);
|
||||
CMakeBuildConfiguration(CMakeProject *pro, CMakeBuildConfiguration *source);
|
||||
CMakeBuildConfiguration(CMakeTarget *parent, CMakeBuildConfiguration *source);
|
||||
virtual bool fromMap(const QVariantMap &map);
|
||||
|
||||
private:
|
||||
@@ -95,15 +94,15 @@ public:
|
||||
CMakeBuildConfigurationFactory(QObject *parent = 0);
|
||||
~CMakeBuildConfigurationFactory();
|
||||
|
||||
QStringList availableCreationIds(ProjectExplorer::Project *project) const;
|
||||
QStringList availableCreationIds(ProjectExplorer::Target *parent) const;
|
||||
QString displayNameForId(const QString &id) const;
|
||||
|
||||
bool canCreate(ProjectExplorer::Project *parent, const QString &id) const;
|
||||
ProjectExplorer::BuildConfiguration *create(ProjectExplorer::Project *parent, const QString &id);
|
||||
bool canClone(ProjectExplorer::Project *parent, ProjectExplorer::BuildConfiguration *source) const;
|
||||
ProjectExplorer::BuildConfiguration *clone(ProjectExplorer::Project *parent, ProjectExplorer::BuildConfiguration *source);
|
||||
bool canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const;
|
||||
ProjectExplorer::BuildConfiguration *restore(ProjectExplorer::Project *parent, const QVariantMap &map);
|
||||
bool canCreate(ProjectExplorer::Target *parent, const QString &id) const;
|
||||
CMakeBuildConfiguration *create(ProjectExplorer::Target *parent, const QString &id);
|
||||
bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source) const;
|
||||
CMakeBuildConfiguration *clone(ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source);
|
||||
bool canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const;
|
||||
CMakeBuildConfiguration *restore(ProjectExplorer::Target *parent, const QVariantMap &map);
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "cmakeprojectconstants.h"
|
||||
#include "cmakeprojectnodes.h"
|
||||
#include "cmakerunconfiguration.h"
|
||||
#include "cmaketarget.h"
|
||||
#include "makestep.h"
|
||||
#include "cmakeopenprojectwizard.h"
|
||||
#include "cmakebuildenvironmentwidget.h"
|
||||
@@ -72,12 +73,14 @@ using ProjectExplorer::EnvironmentItem;
|
||||
CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName)
|
||||
: m_manager(manager),
|
||||
m_fileName(fileName),
|
||||
m_buildConfigurationFactory(new CMakeBuildConfigurationFactory(this)),
|
||||
m_rootNode(new CMakeProjectNode(m_fileName)),
|
||||
m_insideFileChanged(false),
|
||||
m_lastActiveBuildConfiguration(0)
|
||||
m_targetFactory(new CMakeTargetFactory(this))
|
||||
{
|
||||
m_file = new CMakeFile(this, fileName);
|
||||
|
||||
connect(this, SIGNAL(addedTarget(ProjectExplorer::Target*)),
|
||||
SLOT(targetAdded(ProjectExplorer::Target*)));
|
||||
}
|
||||
|
||||
CMakeProject::~CMakeProject()
|
||||
@@ -85,29 +88,34 @@ CMakeProject::~CMakeProject()
|
||||
delete m_rootNode;
|
||||
}
|
||||
|
||||
CMakeBuildConfiguration *CMakeProject::activeCMakeBuildConfiguration() const
|
||||
void CMakeProject::fileChanged(const QString &fileName)
|
||||
{
|
||||
return static_cast<CMakeBuildConfiguration *>(activeBuildConfiguration());
|
||||
Q_UNUSED(fileName)
|
||||
if (!activeTarget() ||
|
||||
!activeTarget()->activeBuildConfiguration())
|
||||
return;
|
||||
|
||||
if (m_insideFileChanged)
|
||||
return;
|
||||
m_insideFileChanged = true;
|
||||
changeActiveBuildConfiguration(activeTarget()->activeBuildConfiguration());
|
||||
m_insideFileChanged = false;
|
||||
}
|
||||
|
||||
IBuildConfigurationFactory *CMakeProject::buildConfigurationFactory() const
|
||||
void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
|
||||
{
|
||||
return m_buildConfigurationFactory;
|
||||
}
|
||||
CMakeTarget *target(qobject_cast<CMakeTarget *>(sender()));
|
||||
if (!bc || !target || target != activeTarget())
|
||||
return;
|
||||
|
||||
void CMakeProject::slotActiveBuildConfiguration()
|
||||
{
|
||||
if (m_lastActiveBuildConfiguration)
|
||||
disconnect(m_lastActiveBuildConfiguration, SIGNAL(environmentChanged()),
|
||||
this, SIGNAL(environmentChanged()));
|
||||
CMakeBuildConfiguration * cmakebc(qobject_cast<CMakeBuildConfiguration *>(bc));
|
||||
if (!cmakebc)
|
||||
return;
|
||||
|
||||
CMakeBuildConfiguration *activeBC = activeCMakeBuildConfiguration();
|
||||
connect(activeBC, SIGNAL(environmentChanged()),
|
||||
this, SIGNAL(environmentChanged()));
|
||||
// Pop up a dialog asking the user to rerun cmake
|
||||
QFileInfo sourceFileInfo(m_fileName);
|
||||
|
||||
QString cbpFile = CMakeManager::findCbpFile(QDir(activeBC->buildDirectory()));
|
||||
QString cbpFile = CMakeManager::findCbpFile(QDir(bc->buildDirectory()));
|
||||
QFileInfo cbpFileFi(cbpFile);
|
||||
CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing;
|
||||
if (!cbpFileFi.exists()) {
|
||||
@@ -124,25 +132,23 @@ void CMakeProject::slotActiveBuildConfiguration()
|
||||
if (mode != CMakeOpenProjectWizard::Nothing) {
|
||||
CMakeOpenProjectWizard copw(m_manager,
|
||||
sourceFileInfo.absolutePath(),
|
||||
activeBC->buildDirectory(),
|
||||
cmakebc->buildDirectory(),
|
||||
mode,
|
||||
activeBC->environment());
|
||||
cmakebc->environment());
|
||||
copw.exec();
|
||||
activeBC->setMsvcVersion(copw.msvcVersion());
|
||||
cmakebc->setMsvcVersion(copw.msvcVersion());
|
||||
}
|
||||
// reparse
|
||||
parseCMakeLists();
|
||||
emit environmentChanged();
|
||||
}
|
||||
|
||||
void CMakeProject::fileChanged(const QString &fileName)
|
||||
void CMakeProject::targetAdded(ProjectExplorer::Target *t)
|
||||
{
|
||||
Q_UNUSED(fileName)
|
||||
if (m_insideFileChanged)
|
||||
if (!t)
|
||||
return;
|
||||
m_insideFileChanged = true;
|
||||
slotActiveBuildConfiguration();
|
||||
m_insideFileChanged = false;
|
||||
|
||||
connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
|
||||
SLOT(changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
|
||||
}
|
||||
|
||||
void CMakeProject::changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory)
|
||||
@@ -158,8 +164,12 @@ QString CMakeProject::sourceDirectory() const
|
||||
|
||||
bool CMakeProject::parseCMakeLists()
|
||||
{
|
||||
if (!activeTarget() ||
|
||||
!activeTarget()->activeBuildConfiguration())
|
||||
return false;
|
||||
|
||||
// Find cbp file
|
||||
CMakeBuildConfiguration *activeBC = activeCMakeBuildConfiguration();
|
||||
CMakeBuildConfiguration *activeBC = activeTarget()->activeBuildConfiguration();
|
||||
QString cbpFile = CMakeManager::findCbpFile(activeBC->buildDirectory());
|
||||
|
||||
// setFolderName
|
||||
@@ -181,7 +191,6 @@ bool CMakeProject::parseCMakeLists()
|
||||
m_rootNode->setFolderName(cbpparser.projectName());
|
||||
|
||||
//qDebug()<<"Building Tree";
|
||||
|
||||
QList<ProjectExplorer::FileNode *> fileList = cbpparser.fileList();
|
||||
QSet<QString> projectFiles;
|
||||
if (cbpparser.hasCMakeFiles()) {
|
||||
@@ -253,59 +262,15 @@ bool CMakeProject::parseCMakeLists()
|
||||
}
|
||||
}
|
||||
|
||||
// Create run configurations for m_targets
|
||||
//qDebug()<<"Create run configurations of m_targets";
|
||||
QMultiMap<QString, CMakeRunConfiguration* > existingRunConfigurations;
|
||||
foreach(ProjectExplorer::RunConfiguration* cmakeRunConfiguration, runConfigurations()) {
|
||||
if (CMakeRunConfiguration* rc = qobject_cast<CMakeRunConfiguration *>(cmakeRunConfiguration)) {
|
||||
existingRunConfigurations.insert(rc->title(), rc);
|
||||
}
|
||||
}
|
||||
|
||||
bool setActive = existingRunConfigurations.isEmpty();
|
||||
foreach(const CMakeBuildTarget &ct, m_buildTargets) {
|
||||
if (ct.executable.isEmpty())
|
||||
continue;
|
||||
if (ct.title.endsWith(QLatin1String("/fast")))
|
||||
continue;
|
||||
QList<CMakeRunConfiguration *> list = existingRunConfigurations.values(ct.title);
|
||||
if (!list.isEmpty()) {
|
||||
// Already exists, so override the settings...
|
||||
foreach (CMakeRunConfiguration *rc, list) {
|
||||
//qDebug()<<"Updating Run Configuration with title"<<ct.title;
|
||||
//qDebug()<<" Executable new:"<<ct.executable<< "old:"<<rc->executable();
|
||||
//qDebug()<<" WD new:"<<ct.workingDirectory<<"old:"<<rc->workingDirectory();
|
||||
rc->setExecutable(ct.executable);
|
||||
rc->setWorkingDirectory(ct.workingDirectory);
|
||||
}
|
||||
existingRunConfigurations.remove(ct.title);
|
||||
} else {
|
||||
// Does not exist yet
|
||||
//qDebug()<<"Adding new run configuration with title"<<ct.title;
|
||||
//qDebug()<<" Executable:"<<ct.executable<<"WD:"<<ct.workingDirectory;
|
||||
ProjectExplorer::RunConfiguration *rc(new CMakeRunConfiguration(this, ct.executable, ct.workingDirectory, ct.title));
|
||||
addRunConfiguration(rc);
|
||||
// The first one gets the honour of being the active one
|
||||
if (setActive) {
|
||||
setActiveRunConfiguration(rc);
|
||||
setActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
QMultiMap<QString, CMakeRunConfiguration *>::const_iterator it =
|
||||
existingRunConfigurations.constBegin();
|
||||
for( ; it != existingRunConfigurations.constEnd(); ++it) {
|
||||
CMakeRunConfiguration *rc = it.value();
|
||||
//qDebug()<<"Removing old RunConfiguration with title:"<<rc->title();
|
||||
//qDebug()<<" Executable:"<<rc->executable()<<rc->workingDirectory();
|
||||
removeRunConfiguration(rc);
|
||||
}
|
||||
//qDebug()<<"\n";
|
||||
|
||||
emit buildTargetsChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<CMakeBuildTarget> CMakeProject::buildTargets() const
|
||||
{
|
||||
return m_buildTargets;
|
||||
}
|
||||
|
||||
QStringList CMakeProject::buildTargetTitles() const
|
||||
{
|
||||
QStringList results;
|
||||
@@ -452,11 +417,21 @@ Core::IFile *CMakeProject::file() const
|
||||
return m_file;
|
||||
}
|
||||
|
||||
CMakeTargetFactory *CMakeProject::targetFactory() const
|
||||
{
|
||||
return m_targetFactory;
|
||||
}
|
||||
|
||||
CMakeManager *CMakeProject::projectManager() const
|
||||
{
|
||||
return m_manager;
|
||||
}
|
||||
|
||||
CMakeTarget *CMakeProject::activeTarget() const
|
||||
{
|
||||
return static_cast<CMakeTarget *>(Project::activeTarget());
|
||||
}
|
||||
|
||||
QList<ProjectExplorer::Project *> CMakeProject::dependsOn()
|
||||
{
|
||||
return QList<Project *>();
|
||||
@@ -496,9 +471,15 @@ bool CMakeProject::fromMap(const QVariantMap &map)
|
||||
if (!Project::fromMap(map))
|
||||
return false;
|
||||
|
||||
bool hasUserFile = !buildConfigurations().isEmpty();
|
||||
MakeStep *makeStep = 0;
|
||||
bool hasUserFile = activeTarget() &&
|
||||
activeTarget()->activeBuildConfiguration();
|
||||
if (!hasUserFile) {
|
||||
CMakeTarget *t(0);
|
||||
if (!activeTarget())
|
||||
t = new CMakeTarget(this);
|
||||
else
|
||||
t = activeTarget();
|
||||
|
||||
// Ask the user for where he wants to build it
|
||||
// and the cmake command line
|
||||
|
||||
@@ -506,29 +487,18 @@ bool CMakeProject::fromMap(const QVariantMap &map)
|
||||
if (copw.exec() != QDialog::Accepted)
|
||||
return false;
|
||||
|
||||
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(this);
|
||||
bc->setDisplayName("all");
|
||||
CMakeBuildConfiguration *bc =
|
||||
static_cast<CMakeBuildConfiguration *>(t->buildConfigurations().at(0));
|
||||
bc->setMsvcVersion(copw.msvcVersion());
|
||||
if (!copw.buildDirectory().isEmpty())
|
||||
bc->setBuildDirectory(copw.buildDirectory());
|
||||
|
||||
// Now create a standard build configuration
|
||||
makeStep = new MakeStep(bc);
|
||||
bc->insertBuildStep(0, makeStep);
|
||||
|
||||
//TODO save arguments somewhere copw.arguments()
|
||||
MakeStep *cleanMakeStep = new MakeStep(bc);
|
||||
bc->insertCleanStep(0, cleanMakeStep);
|
||||
cleanMakeStep->setAdditionalArguments(QStringList() << "clean");
|
||||
cleanMakeStep->setClean(true);
|
||||
|
||||
addBuildConfiguration(bc);
|
||||
setActiveBuildConfiguration(bc);
|
||||
addTarget(t);
|
||||
} else {
|
||||
// We have a user file, but we could still be missing the cbp file
|
||||
// or simply run createXml with the saved settings
|
||||
QFileInfo sourceFileInfo(m_fileName);
|
||||
CMakeBuildConfiguration *activeBC = activeCMakeBuildConfiguration();
|
||||
CMakeBuildConfiguration *activeBC = activeTarget()->activeBuildConfiguration();
|
||||
QString cbpFile = CMakeManager::findCbpFile(QDir(activeBC->buildDirectory()));
|
||||
QFileInfo cbpFileFi(cbpFile);
|
||||
|
||||
@@ -552,20 +522,22 @@ bool CMakeProject::fromMap(const QVariantMap &map)
|
||||
|
||||
m_watcher = new ProjectExplorer::FileWatcher(this);
|
||||
connect(m_watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString)));
|
||||
bool result = parseCMakeLists(); // Gets the directory from the active buildconfiguration
|
||||
if (!result)
|
||||
|
||||
if (!parseCMakeLists()) // Gets the directory from the active buildconfiguration
|
||||
return false;
|
||||
|
||||
if (!hasUserFile && hasBuildTarget("all"))
|
||||
if (!hasUserFile && hasBuildTarget("all")) {
|
||||
MakeStep *makeStep(qobject_cast<MakeStep *>(activeTarget()->activeBuildConfiguration()->buildSteps().at(0)));
|
||||
Q_ASSERT(makeStep);
|
||||
makeStep->setBuildTarget("all", true);
|
||||
}
|
||||
|
||||
m_lastActiveBuildConfiguration = activeCMakeBuildConfiguration();
|
||||
if (m_lastActiveBuildConfiguration)
|
||||
connect(m_lastActiveBuildConfiguration, SIGNAL(environmentChanged()),
|
||||
this, SIGNAL(environmentChanged()));
|
||||
|
||||
connect(this, SIGNAL(activeBuildConfigurationChanged()),
|
||||
this, SLOT(slotActiveBuildConfiguration()));
|
||||
foreach (Target *t, targets()) {
|
||||
connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
|
||||
this, SLOT(changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
|
||||
connect(t, SIGNAL(environmentChanged()),
|
||||
this, SLOT(changeEnvironment()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "cmakeprojectmanager.h"
|
||||
#include "cmakeprojectnodes.h"
|
||||
#include "cmakebuildconfiguration.h"
|
||||
#include "cmaketarget.h"
|
||||
#include "makestep.h"
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
@@ -72,14 +73,14 @@ public:
|
||||
CMakeProject(CMakeManager *manager, const QString &filename);
|
||||
~CMakeProject();
|
||||
|
||||
CMakeBuildConfiguration *activeCMakeBuildConfiguration() const;
|
||||
|
||||
QString displayName() const;
|
||||
QString id() const;
|
||||
Core::IFile *file() const;
|
||||
ProjectExplorer::IBuildConfigurationFactory *buildConfigurationFactory() const;
|
||||
CMakeTargetFactory *targetFactory() const;
|
||||
CMakeManager *projectManager() const;
|
||||
|
||||
CMakeTarget *activeTarget() const;
|
||||
|
||||
QList<ProjectExplorer::Project *> dependsOn(); //NBS TODO implement dependsOn
|
||||
|
||||
bool isApplication() const;
|
||||
@@ -98,10 +99,9 @@ public:
|
||||
|
||||
QString sourceDirectory() const;
|
||||
|
||||
bool parseCMakeLists();
|
||||
|
||||
signals:
|
||||
/// convenience signal emitted if the activeBuildConfiguration emits environmentChanged
|
||||
/// or if the activeBuildConfiguration changes
|
||||
void environmentChanged();
|
||||
/// emitted after parsing
|
||||
void buildTargetsChanged();
|
||||
|
||||
@@ -113,11 +113,10 @@ protected:
|
||||
|
||||
private slots:
|
||||
void fileChanged(const QString &fileName);
|
||||
void slotActiveBuildConfiguration();
|
||||
void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
|
||||
void targetAdded(ProjectExplorer::Target *);
|
||||
|
||||
private:
|
||||
bool parseCMakeLists();
|
||||
|
||||
void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
|
||||
void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
|
||||
ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);
|
||||
@@ -126,7 +125,6 @@ private:
|
||||
QString m_fileName;
|
||||
CMakeFile *m_file;
|
||||
QString m_projectName;
|
||||
CMakeBuildConfigurationFactory *m_buildConfigurationFactory;
|
||||
|
||||
// TODO probably need a CMake specific node structure
|
||||
CMakeProjectNode *m_rootNode;
|
||||
@@ -135,9 +133,7 @@ private:
|
||||
ProjectExplorer::FileWatcher *m_watcher;
|
||||
bool m_insideFileChanged;
|
||||
QSet<QString> m_watchedFiles;
|
||||
CMakeBuildConfiguration *m_lastActiveBuildConfiguration;
|
||||
|
||||
friend class CMakeBuildConfigurationFactory; // for parseCMakeLists
|
||||
CMakeTargetFactory *m_targetFactory;
|
||||
};
|
||||
|
||||
class CMakeCbpParser : public QXmlStreamReader
|
||||
|
||||
@@ -7,6 +7,7 @@ HEADERS = cmakeproject.h \
|
||||
cmakeprojectmanager.h \
|
||||
cmakeprojectconstants.h \
|
||||
cmakeprojectnodes.h \
|
||||
cmaketarget.h \
|
||||
makestep.h \
|
||||
cmakerunconfiguration.h \
|
||||
cmakeopenprojectwizard.h \
|
||||
@@ -16,6 +17,7 @@ SOURCES = cmakeproject.cpp \
|
||||
cmakeprojectplugin.cpp \
|
||||
cmakeprojectmanager.cpp \
|
||||
cmakeprojectnodes.cpp \
|
||||
cmaketarget.cpp \
|
||||
makestep.cpp \
|
||||
cmakerunconfiguration.cpp \
|
||||
cmakeopenprojectwizard.cpp \
|
||||
|
||||
@@ -29,9 +29,10 @@
|
||||
|
||||
#include "cmakerunconfiguration.h"
|
||||
|
||||
#include "cmakeproject.h"
|
||||
#include "cmakebuildconfiguration.h"
|
||||
#include "cmakeproject.h"
|
||||
#include "cmakeprojectconstants.h"
|
||||
#include "cmaketarget.h"
|
||||
|
||||
#include <projectexplorer/environment.h>
|
||||
#include <projectexplorer/debugginghelper.h>
|
||||
@@ -73,8 +74,8 @@ QString idFromBuildTarget(const QString &target)
|
||||
|
||||
} // namespace
|
||||
|
||||
CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, const QString &target, const QString &workingDirectory, const QString &title) :
|
||||
ProjectExplorer::LocalApplicationRunConfiguration(pro, QString::fromLatin1(CMAKE_RC_PREFIX)),
|
||||
CMakeRunConfiguration::CMakeRunConfiguration(CMakeTarget *parent, const QString &target, const QString &workingDirectory, const QString &title) :
|
||||
ProjectExplorer::LocalApplicationRunConfiguration(parent, QString::fromLatin1(CMAKE_RC_PREFIX)),
|
||||
m_runMode(Gui),
|
||||
m_buildTarget(target),
|
||||
m_workingDirectory(workingDirectory),
|
||||
@@ -84,8 +85,8 @@ CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, const QString &t
|
||||
ctor();
|
||||
}
|
||||
|
||||
CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, CMakeRunConfiguration *source) :
|
||||
ProjectExplorer::LocalApplicationRunConfiguration(pro, source),
|
||||
CMakeRunConfiguration::CMakeRunConfiguration(CMakeTarget *parent, CMakeRunConfiguration *source) :
|
||||
ProjectExplorer::LocalApplicationRunConfiguration(parent, source),
|
||||
m_runMode(source->m_runMode),
|
||||
m_buildTarget(source->m_buildTarget),
|
||||
m_workingDirectory(source->m_workingDirectory),
|
||||
@@ -105,14 +106,16 @@ CMakeRunConfiguration::~CMakeRunConfiguration()
|
||||
void CMakeRunConfiguration::ctor()
|
||||
{
|
||||
setDisplayName(m_title);
|
||||
|
||||
connect(project(), SIGNAL(environmentChanged()),
|
||||
this, SIGNAL(baseEnvironmentChanged()));
|
||||
}
|
||||
|
||||
CMakeProject *CMakeRunConfiguration::cmakeProject() const
|
||||
CMakeTarget *CMakeRunConfiguration::cmakeTarget() const
|
||||
{
|
||||
return static_cast<CMakeProject *>(project());
|
||||
return static_cast<CMakeTarget *>(target());
|
||||
}
|
||||
|
||||
CMakeBuildConfiguration *CMakeRunConfiguration::activeBuildConfiguration() const
|
||||
{
|
||||
return cmakeTarget()->activeBuildConfiguration();
|
||||
}
|
||||
|
||||
QString CMakeRunConfiguration::executable() const
|
||||
@@ -232,7 +235,7 @@ ProjectExplorer::Environment CMakeRunConfiguration::baseEnvironment() const
|
||||
} else if (m_baseEnvironmentBase == CMakeRunConfiguration::SystemEnvironmentBase) {
|
||||
env = ProjectExplorer::Environment::systemEnvironment();
|
||||
} else if (m_baseEnvironmentBase == CMakeRunConfiguration::BuildEnvironmentBase) {
|
||||
env = project()->activeBuildConfiguration()->environment();
|
||||
env = activeBuildConfiguration()->environment();
|
||||
}
|
||||
return env;
|
||||
}
|
||||
@@ -284,7 +287,9 @@ void CMakeRunConfiguration::setUserEnvironmentChanges(const QList<ProjectExplore
|
||||
|
||||
ProjectExplorer::ToolChain::ToolChainType CMakeRunConfiguration::toolChainType() const
|
||||
{
|
||||
CMakeBuildConfiguration *bc = cmakeProject()->activeCMakeBuildConfiguration();
|
||||
CMakeBuildConfiguration *bc = activeBuildConfiguration();
|
||||
if (!bc)
|
||||
return ProjectExplorer::ToolChain::UNKNOWN;
|
||||
return bc->toolChainType();
|
||||
}
|
||||
|
||||
@@ -447,13 +452,13 @@ CMakeRunConfigurationFactory::~CMakeRunConfigurationFactory()
|
||||
}
|
||||
|
||||
// used to show the list of possible additons to a project, returns a list of ids
|
||||
QStringList CMakeRunConfigurationFactory::availableCreationIds(ProjectExplorer::Project *parent) const
|
||||
QStringList CMakeRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
|
||||
{
|
||||
CMakeProject *project(qobject_cast<CMakeProject *>(parent));
|
||||
if (!project)
|
||||
CMakeTarget *t(qobject_cast<CMakeTarget *>(parent));
|
||||
if (!t)
|
||||
return QStringList();
|
||||
QStringList allIds;
|
||||
foreach (const QString &buildTarget, project->buildTargetTitles())
|
||||
foreach (const QString &buildTarget, t->cmakeProject()->buildTargetTitles())
|
||||
allIds << idFromBuildTarget(buildTarget);
|
||||
return allIds;
|
||||
}
|
||||
@@ -464,55 +469,55 @@ QString CMakeRunConfigurationFactory::displayNameForId(const QString &id) const
|
||||
return buildTargetFromId(id);
|
||||
}
|
||||
|
||||
bool CMakeRunConfigurationFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
|
||||
bool CMakeRunConfigurationFactory::canCreate(ProjectExplorer::Target *parent, const QString &id) const
|
||||
{
|
||||
CMakeProject *project(qobject_cast<CMakeProject *>(parent));
|
||||
if (!project)
|
||||
CMakeTarget *t(qobject_cast<CMakeTarget *>(parent));
|
||||
if (!t)
|
||||
return false;
|
||||
return project->hasBuildTarget(buildTargetFromId(id));
|
||||
return t->cmakeProject()->hasBuildTarget(buildTargetFromId(id));
|
||||
}
|
||||
|
||||
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::create(ProjectExplorer::Project *parent, const QString &id)
|
||||
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::create(ProjectExplorer::Target *parent, const QString &id)
|
||||
{
|
||||
if (!canCreate(parent, id))
|
||||
return 0;
|
||||
CMakeProject *project(static_cast<CMakeProject *>(parent));
|
||||
CMakeTarget *t(static_cast<CMakeTarget *>(parent));
|
||||
|
||||
const QString title(buildTargetFromId(id));
|
||||
const CMakeBuildTarget &ct = project->buildTargetForTitle(title);
|
||||
return new CMakeRunConfiguration(project, ct.executable, ct.workingDirectory, ct.title);
|
||||
const CMakeBuildTarget &ct = t->cmakeProject()->buildTargetForTitle(title);
|
||||
return new CMakeRunConfiguration(t, ct.executable, ct.workingDirectory, ct.title);
|
||||
}
|
||||
|
||||
bool CMakeRunConfigurationFactory::canClone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *source) const
|
||||
bool CMakeRunConfigurationFactory::canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const
|
||||
{
|
||||
if (!qobject_cast<CMakeProject *>(parent))
|
||||
if (!qobject_cast<CMakeTarget *>(parent))
|
||||
return false;
|
||||
return source->id() == QLatin1String(CMAKE_RC_ID);
|
||||
}
|
||||
|
||||
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::clone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration * source)
|
||||
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration * source)
|
||||
{
|
||||
if (!canClone(parent, source))
|
||||
return 0;
|
||||
CMakeProject *project(static_cast<CMakeProject *>(parent));
|
||||
CMakeTarget *t(static_cast<CMakeTarget *>(parent));
|
||||
CMakeRunConfiguration *crc(static_cast<CMakeRunConfiguration *>(source));
|
||||
return new CMakeRunConfiguration(project, crc);
|
||||
return new CMakeRunConfiguration(t, crc);
|
||||
}
|
||||
|
||||
bool CMakeRunConfigurationFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
|
||||
bool CMakeRunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
|
||||
{
|
||||
if (!qobject_cast<CMakeProject *>(parent))
|
||||
if (!qobject_cast<CMakeTarget *>(parent))
|
||||
return false;
|
||||
QString id(ProjectExplorer::idFromMap(map));
|
||||
return id.startsWith(QLatin1String(CMAKE_RC_ID));
|
||||
}
|
||||
|
||||
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
|
||||
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
|
||||
{
|
||||
if (!canRestore(parent, map))
|
||||
return 0;
|
||||
CMakeProject *project(static_cast<CMakeProject *>(parent));
|
||||
CMakeRunConfiguration *rc(new CMakeRunConfiguration(project, QString(), QString(), QString()));
|
||||
CMakeTarget *t(static_cast<CMakeTarget *>(parent));
|
||||
CMakeRunConfiguration *rc(new CMakeRunConfiguration(t, QString(), QString(), QString()));
|
||||
if (rc->fromMap(map))
|
||||
return rc;
|
||||
delete rc;
|
||||
|
||||
@@ -44,7 +44,8 @@ QT_END_NAMESPACE
|
||||
namespace CMakeProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
class CMakeProject;
|
||||
class CMakeBuildConfiguration;
|
||||
class CMakeTarget;
|
||||
|
||||
class CMakeRunConfiguration : public ProjectExplorer::LocalApplicationRunConfiguration
|
||||
{
|
||||
@@ -53,11 +54,12 @@ class CMakeRunConfiguration : public ProjectExplorer::LocalApplicationRunConfigu
|
||||
friend class CMakeRunConfigurationFactory;
|
||||
|
||||
public:
|
||||
CMakeRunConfiguration(CMakeProject *project, const QString &target,
|
||||
CMakeRunConfiguration(CMakeTarget *parent, const QString &target,
|
||||
const QString &workingDirectory, const QString &title);
|
||||
~CMakeRunConfiguration();
|
||||
|
||||
CMakeProject *cmakeProject() const;
|
||||
CMakeTarget *cmakeTarget() const;
|
||||
CMakeBuildConfiguration *activeBuildConfiguration() const;
|
||||
|
||||
QString executable() const;
|
||||
RunMode runMode() const;
|
||||
@@ -88,7 +90,7 @@ private slots:
|
||||
void setArguments(const QString &newText);
|
||||
|
||||
protected:
|
||||
CMakeRunConfiguration(CMakeProject *project, CMakeRunConfiguration *source);
|
||||
CMakeRunConfiguration(CMakeTarget *parent, CMakeRunConfiguration *source);
|
||||
virtual bool fromMap(const QVariantMap &map);
|
||||
|
||||
private:
|
||||
@@ -150,17 +152,15 @@ class CMakeRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFa
|
||||
public:
|
||||
explicit CMakeRunConfigurationFactory(QObject *parent = 0);
|
||||
~CMakeRunConfigurationFactory();
|
||||
// used to recreate the runConfigurations when restoring settings
|
||||
bool canCreate(ProjectExplorer::Project *project, const QString &id) const;
|
||||
ProjectExplorer::RunConfiguration *create(ProjectExplorer::Project *project, const QString &id);
|
||||
bool canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const;
|
||||
ProjectExplorer::RunConfiguration *restore(ProjectExplorer::Project *parent, const QVariantMap &map);
|
||||
bool canClone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *product) const;
|
||||
ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Project *parent, ProjectExplorer::RunConfiguration *product);
|
||||
|
||||
// used to show the list of possible additons to a project, returns a list of types
|
||||
QStringList availableCreationIds(ProjectExplorer::Project *pro) const;
|
||||
// used to translate the types to names to display to the user
|
||||
bool canCreate(ProjectExplorer::Target *parent, const QString &id) const;
|
||||
ProjectExplorer::RunConfiguration *create(ProjectExplorer::Target *parent, const QString &id);
|
||||
bool canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const;
|
||||
ProjectExplorer::RunConfiguration *restore(ProjectExplorer::Target *parent, const QVariantMap &map);
|
||||
bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *product) const;
|
||||
ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *product);
|
||||
|
||||
QStringList availableCreationIds(ProjectExplorer::Target *parent) const;
|
||||
QString displayNameForId(const QString &id) const;
|
||||
};
|
||||
|
||||
|
||||
204
src/plugins/cmakeprojectmanager/cmaketarget.cpp
Normal file
204
src/plugins/cmakeprojectmanager/cmaketarget.cpp
Normal file
@@ -0,0 +1,204 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, 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.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "cmaketarget.h"
|
||||
|
||||
#include "cmakeopenprojectwizard.h"
|
||||
#include "cmakeproject.h"
|
||||
#include "cmakerunconfiguration.h"
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QStyle>
|
||||
|
||||
using namespace CMakeProjectManager;
|
||||
using namespace CMakeProjectManager::Internal;
|
||||
|
||||
namespace {
|
||||
|
||||
QString displayNameForId(const QString &id) {
|
||||
if (id == QLatin1String(DEFAULT_CMAKE_TARGET_ID))
|
||||
return QApplication::translate("CMakeProjectManager::Internal::CMakeTarget", "Desktop", "CMake Default target display name");
|
||||
return QString();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// CMakeTarget
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
CMakeTarget::CMakeTarget(CMakeProject *parent) :
|
||||
ProjectExplorer::Target(parent, QLatin1String(DEFAULT_CMAKE_TARGET_ID)),
|
||||
m_buildConfigurationFactory(new CMakeBuildConfigurationFactory(this))
|
||||
{
|
||||
setDisplayName(displayNameForId(id()));
|
||||
setIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
|
||||
connect(parent, SIGNAL(buildTargetsChanged()), SLOT(updateRunConfigurations()));
|
||||
}
|
||||
|
||||
CMakeTarget::~CMakeTarget()
|
||||
{
|
||||
}
|
||||
|
||||
CMakeProject *CMakeTarget::cmakeProject() const
|
||||
{
|
||||
return static_cast<CMakeProject *>(project());
|
||||
}
|
||||
|
||||
CMakeBuildConfiguration *CMakeTarget::activeBuildConfiguration() const
|
||||
{
|
||||
return static_cast<CMakeBuildConfiguration *>(Target::activeBuildConfiguration());
|
||||
}
|
||||
|
||||
CMakeBuildConfigurationFactory *CMakeTarget::buildConfigurationFactory() const
|
||||
{
|
||||
return m_buildConfigurationFactory;
|
||||
}
|
||||
|
||||
bool CMakeTarget::fromMap(const QVariantMap &map)
|
||||
{
|
||||
if (!Target::fromMap(map))
|
||||
return false;
|
||||
|
||||
if (displayName().isEmpty())
|
||||
setDisplayName(displayNameForId(id()));
|
||||
if (icon().isNull())
|
||||
setIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMakeTarget::updateRunConfigurations()
|
||||
{
|
||||
// *Update* runconfigurations:
|
||||
QMultiMap<QString, CMakeRunConfiguration*> existingRunConfigurations;
|
||||
foreach(ProjectExplorer::RunConfiguration* cmakeRunConfiguration, runConfigurations()) {
|
||||
if (CMakeRunConfiguration* rc = qobject_cast<CMakeRunConfiguration *>(cmakeRunConfiguration))
|
||||
existingRunConfigurations.insert(rc->title(), rc);
|
||||
}
|
||||
|
||||
foreach(const CMakeBuildTarget &ct, cmakeProject()->buildTargets()) {
|
||||
if (ct.executable.isEmpty())
|
||||
continue;
|
||||
if (ct.title.endsWith("/fast"))
|
||||
continue;
|
||||
QList<CMakeRunConfiguration *> list = existingRunConfigurations.values(ct.title);
|
||||
if (!list.isEmpty()) {
|
||||
// Already exists, so override the settings...
|
||||
foreach (CMakeRunConfiguration *rc, list) {
|
||||
rc->setExecutable(ct.executable);
|
||||
rc->setWorkingDirectory(ct.workingDirectory);
|
||||
}
|
||||
existingRunConfigurations.remove(ct.title);
|
||||
} else {
|
||||
// Does not exist yet
|
||||
addRunConfiguration(new CMakeRunConfiguration(this, ct.executable, ct.workingDirectory, ct.title));
|
||||
}
|
||||
}
|
||||
QMultiMap<QString, CMakeRunConfiguration *>::const_iterator it =
|
||||
existingRunConfigurations.constBegin();
|
||||
for( ; it != existingRunConfigurations.constEnd(); ++it) {
|
||||
CMakeRunConfiguration *rc = it.value();
|
||||
removeRunConfiguration(rc);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// CMakeTargetFactory
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
CMakeTargetFactory::CMakeTargetFactory(QObject *parent) :
|
||||
ITargetFactory(parent)
|
||||
{
|
||||
}
|
||||
|
||||
CMakeTargetFactory::~CMakeTargetFactory()
|
||||
{
|
||||
}
|
||||
|
||||
QStringList CMakeTargetFactory::availableCreationIds(ProjectExplorer::Project *parent) const
|
||||
{
|
||||
if (!qobject_cast<CMakeProject *>(parent))
|
||||
return QStringList();
|
||||
return QStringList() << QLatin1String(DEFAULT_CMAKE_TARGET_ID);
|
||||
}
|
||||
QString CMakeTargetFactory::displayNameForId(const QString &id) const
|
||||
{
|
||||
return ::displayNameForId(id);
|
||||
}
|
||||
|
||||
bool CMakeTargetFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
|
||||
{
|
||||
if (!qobject_cast<CMakeProject *>(parent))
|
||||
return false;
|
||||
return id == QLatin1String(DEFAULT_CMAKE_TARGET_ID);
|
||||
}
|
||||
|
||||
CMakeTarget *CMakeTargetFactory::create(ProjectExplorer::Project *parent, const QString &id)
|
||||
{
|
||||
if (!canCreate(parent, id))
|
||||
return 0;
|
||||
CMakeProject *cmakeparent(static_cast<CMakeProject *>(parent));
|
||||
CMakeTarget *t(new CMakeTarget(cmakeparent));
|
||||
|
||||
// Add default build configuration:
|
||||
CMakeBuildConfiguration *bc(new CMakeBuildConfiguration(t));
|
||||
bc->setDisplayName("all");
|
||||
|
||||
// Now create a standard build configuration
|
||||
bc->insertBuildStep(0, new MakeStep(bc));
|
||||
|
||||
MakeStep *cleanMakeStep = new MakeStep(bc);
|
||||
bc->insertCleanStep(0, cleanMakeStep);
|
||||
cleanMakeStep->setAdditionalArguments(QStringList() << "clean");
|
||||
cleanMakeStep->setClean(true);
|
||||
|
||||
t->addBuildConfiguration(bc);
|
||||
|
||||
t->updateRunConfigurations();
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
bool CMakeTargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
|
||||
{
|
||||
return canCreate(parent, ProjectExplorer::idFromMap(map));
|
||||
}
|
||||
|
||||
CMakeTarget *CMakeTargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
|
||||
{
|
||||
if (!canRestore(parent, map))
|
||||
return 0;
|
||||
CMakeProject *cmakeparent(static_cast<CMakeProject *>(parent));
|
||||
CMakeTarget *t(new CMakeTarget(cmakeparent));
|
||||
if (t->fromMap(map))
|
||||
return t;
|
||||
delete t;
|
||||
return 0;
|
||||
}
|
||||
93
src/plugins/cmakeprojectmanager/cmaketarget.h
Normal file
93
src/plugins/cmakeprojectmanager/cmaketarget.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, 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.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef CMAKETARGET_H
|
||||
#define CMAKETARGET_H
|
||||
|
||||
#include "cmakebuildconfiguration.h"
|
||||
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
|
||||
namespace Internal {
|
||||
|
||||
const char * const DEFAULT_CMAKE_TARGET_ID("CMakeProjectManager.DefaultCMakeTarget");
|
||||
|
||||
class CMakeBuildConfiguration;
|
||||
class CMakeBuildConfigurationFactory;
|
||||
class CMakeProject;
|
||||
class CMakeTargetFactory;
|
||||
|
||||
class CMakeTarget : public ProjectExplorer::Target
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class CMakeTargetFactory;
|
||||
|
||||
public:
|
||||
CMakeTarget(CMakeProject *parent);
|
||||
~CMakeTarget();
|
||||
|
||||
CMakeProject *cmakeProject() const;
|
||||
CMakeBuildConfiguration *activeBuildConfiguration() const;
|
||||
|
||||
CMakeBuildConfigurationFactory *buildConfigurationFactory() const;
|
||||
|
||||
protected:
|
||||
bool fromMap(const QVariantMap &map);
|
||||
|
||||
private slots:
|
||||
void updateRunConfigurations();
|
||||
|
||||
private:
|
||||
CMakeBuildConfigurationFactory *m_buildConfigurationFactory;
|
||||
};
|
||||
|
||||
class CMakeTargetFactory : public ProjectExplorer::ITargetFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CMakeTargetFactory(QObject *parent = 0);
|
||||
~CMakeTargetFactory();
|
||||
|
||||
QStringList availableCreationIds(ProjectExplorer::Project *parent) const;
|
||||
QString displayNameForId(const QString &id) const;
|
||||
|
||||
bool canCreate(ProjectExplorer::Project *parent, const QString &id) const;
|
||||
CMakeTarget *create(ProjectExplorer::Project *parent, const QString &id);
|
||||
bool canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const;
|
||||
CMakeTarget *restore(ProjectExplorer::Project *parent, const QVariantMap &map);
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
} // namespace CMakeProjectManager
|
||||
|
||||
#endif // CMAKETARGET_H
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "cmakeprojectconstants.h"
|
||||
#include "cmakeproject.h"
|
||||
#include "cmaketarget.h"
|
||||
#include "cmakebuildconfiguration.h"
|
||||
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
@@ -220,7 +221,7 @@ MakeStepConfigWidget::MakeStepConfigWidget(MakeStep *makeStep)
|
||||
|
||||
// TODO update this list also on rescans of the CMakeLists.txt
|
||||
// TODO shouldn't be accessing project
|
||||
CMakeProject *pro = m_makeStep->cmakeBuildConfiguration()->cmakeProject();
|
||||
CMakeProject *pro = m_makeStep->cmakeBuildConfiguration()->cmakeTarget()->cmakeProject();
|
||||
foreach(const QString& buildTarget, pro->buildTargetTitles()) {
|
||||
QListWidgetItem *item = new QListWidgetItem(buildTarget, m_buildTargetsList);
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
@@ -265,7 +266,7 @@ void MakeStepConfigWidget::init()
|
||||
m_additionalArguments->setText(Environment::joinArgumentList(m_makeStep->additionalArguments()));
|
||||
updateDetails();
|
||||
|
||||
CMakeProject *pro = m_makeStep->cmakeBuildConfiguration()->cmakeProject();
|
||||
CMakeProject *pro = m_makeStep->cmakeBuildConfiguration()->cmakeTarget()->cmakeProject();
|
||||
connect(pro, SIGNAL(buildTargetsChanged()),
|
||||
this, SLOT(buildTargetsChanged()));
|
||||
}
|
||||
@@ -274,7 +275,7 @@ void MakeStepConfigWidget::buildTargetsChanged()
|
||||
{
|
||||
disconnect(m_buildTargetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
|
||||
m_buildTargetsList->clear();
|
||||
CMakeProject *pro = m_makeStep->cmakeBuildConfiguration()->cmakeProject();
|
||||
CMakeProject *pro = m_makeStep->cmakeBuildConfiguration()->cmakeTarget()->cmakeProject();
|
||||
foreach(const QString& buildTarget, pro->buildTargetTitles()) {
|
||||
QListWidgetItem *item = new QListWidgetItem(buildTarget, m_buildTargetsList);
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
|
||||
Reference in New Issue
Block a user