cmakerunconfiguration.cpp 19.1 KB
Newer Older
1
/**************************************************************************
dt's avatar
dt committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
dt's avatar
dt committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
dt's avatar
dt committed
8
**
9
** Commercial Usage
dt's avatar
dt committed
10
**
11
12
13
14
** 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.
dt's avatar
dt committed
15
**
16
** GNU Lesser General Public License Usage
dt's avatar
dt committed
17
**
18
19
20
21
22
23
** 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.
dt's avatar
dt committed
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
dt's avatar
dt committed
27
**
28
**************************************************************************/
dt's avatar
dt committed
29
30

#include "cmakerunconfiguration.h"
hjk's avatar
hjk committed
31

32
#include "cmakebuildconfiguration.h"
Tobias Hunger's avatar
Tobias Hunger committed
33
#include "cmakeproject.h"
hjk's avatar
hjk committed
34
#include "cmakeprojectconstants.h"
Tobias Hunger's avatar
Tobias Hunger committed
35
#include "cmaketarget.h"
dt's avatar
dt committed
36
37

#include <projectexplorer/environment.h>
38
#include <projectexplorer/debugginghelper.h>
hjk's avatar
hjk committed
39
#include <utils/qtcassert.h>
40
41
#include <QtGui/QFormLayout>
#include <QtGui/QLineEdit>
42
43
#include <QtGui/QGroupBox>
#include <QtGui/QLabel>
44
#include <QtGui/QComboBox>
45
#include <QtGui/QToolButton>
dt's avatar
dt committed
46
47
48
49

using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;

50
51
52
53
54
55
56
57
58
59
60
61
62
namespace {
const char * const CMAKE_RC_ID("CMakeProjectManager.CMakeRunConfiguration");
const char * const CMAKE_RC_PREFIX("CMakeProjectManager.CMakeRunConfiguration.");

const char * const TARGET_KEY("CMakeProjectManager.CMakeRunConfiguration.Target");
const char * const WORKING_DIRECTORY_KEY("CMakeProjectManager.CMakeRunConfiguration.WorkingDirectory");
const char * const USER_WORKING_DIRECTORY_KEY("CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory");
const char * const USE_TERMINAL_KEY("CMakeProjectManager.CMakeRunConfiguration.UseTerminal");
const char * const TITLE_KEY("CMakeProjectManager.CMakeRunConfiguation.Title");
const char * const ARGUMENTS_KEY("CMakeProjectManager.CMakeRunConfiguration.Arguments");
const char * const USER_ENVIRONMENT_CHANGES_KEY("CMakeProjectManager.CMakeRunConfiguration.UserEnvironmentChanges");
const char * const BASE_ENVIRONMENT_BASE_KEY("CMakeProjectManager.BaseEnvironmentBase");

63
QString buildTargetFromId(const QString &id)
dt's avatar
dt committed
64
{
65
66
67
68
    if (!id.startsWith(QLatin1String(CMAKE_RC_PREFIX)))
        return QString();
    return id.mid(QString::fromLatin1(CMAKE_RC_PREFIX).length());
}
69

70
QString idFromBuildTarget(const QString &target)
71
72
{
    return QString::fromLatin1(CMAKE_RC_PREFIX) + target;
dt's avatar
dt committed
73
}
hjk's avatar
hjk committed
74

75
76
} // namespace

Tobias Hunger's avatar
Tobias Hunger committed
77
78
CMakeRunConfiguration::CMakeRunConfiguration(CMakeTarget *parent, const QString &target, const QString &workingDirectory, const QString &title) :
    ProjectExplorer::LocalApplicationRunConfiguration(parent, QString::fromLatin1(CMAKE_RC_PREFIX)),
79
    m_runMode(Gui),
80
    m_buildTarget(target),
81
82
83
    m_workingDirectory(workingDirectory),
    m_title(title),
    m_baseEnvironmentBase(CMakeRunConfiguration::BuildEnvironmentBase)
dt's avatar
dt committed
84
{
85
86
    ctor();
}
dt's avatar
dt committed
87

Tobias Hunger's avatar
Tobias Hunger committed
88
89
CMakeRunConfiguration::CMakeRunConfiguration(CMakeTarget *parent, CMakeRunConfiguration *source) :
    ProjectExplorer::LocalApplicationRunConfiguration(parent, source),
90
    m_runMode(source->m_runMode),
91
    m_buildTarget(source->m_buildTarget),
92
93
94
95
96
97
98
99
    m_workingDirectory(source->m_workingDirectory),
    m_userWorkingDirectory(source->m_userWorkingDirectory),
    m_title(source->m_title),
    m_arguments(source->m_arguments),
    m_userEnvironmentChanges(source->m_userEnvironmentChanges),
    m_baseEnvironmentBase(source->m_baseEnvironmentBase)
{
    ctor();
dt's avatar
dt committed
100
101
}

102
CMakeRunConfiguration::~CMakeRunConfiguration()
dt's avatar
dt committed
103
{
dt's avatar
dt committed
104
105
}

106
void CMakeRunConfiguration::ctor()
dt's avatar
dt committed
107
{
108
    setDisplayName(m_title);
Tobias Hunger's avatar
Tobias Hunger committed
109
}
110

Tobias Hunger's avatar
Tobias Hunger committed
111
112
113
CMakeTarget *CMakeRunConfiguration::cmakeTarget() const
{
    return static_cast<CMakeTarget *>(target());
114
115
}

Tobias Hunger's avatar
Tobias Hunger committed
116
CMakeBuildConfiguration *CMakeRunConfiguration::activeBuildConfiguration() const
117
{
Tobias Hunger's avatar
Tobias Hunger committed
118
    return cmakeTarget()->activeBuildConfiguration();
dt's avatar
dt committed
119
120
121
122
}

QString CMakeRunConfiguration::executable() const
{
123
    return m_buildTarget;
dt's avatar
dt committed
124
125
}

126
ProjectExplorer::LocalApplicationRunConfiguration::RunMode CMakeRunConfiguration::runMode() const
dt's avatar
dt committed
127
{
128
    return m_runMode;
dt's avatar
dt committed
129
130
131
132
}

QString CMakeRunConfiguration::workingDirectory() const
{
133
134
    if (!m_userWorkingDirectory.isEmpty())
        return m_userWorkingDirectory;
dt's avatar
dt committed
135
136
137
138
139
    return m_workingDirectory;
}

QStringList CMakeRunConfiguration::commandLineArguments() const
{
140
    return ProjectExplorer::Environment::parseCombinedArgString(m_arguments);
dt's avatar
dt committed
141
142
}

dt's avatar
dt committed
143
144
145
146
147
148
149
QString CMakeRunConfiguration::title() const
{
    return m_title;
}

void CMakeRunConfiguration::setExecutable(const QString &executable)
{
150
    m_buildTarget = executable;
dt's avatar
dt committed
151
152
}

153
void CMakeRunConfiguration::setWorkingDirectory(const QString &wd)
dt's avatar
dt committed
154
{
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
    const QString & oldWorkingDirectory = workingDirectory();

    m_workingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
        emit workingDirectoryChanged(newWorkingDirectory);
}

void CMakeRunConfiguration::setUserWorkingDirectory(const QString &wd)
{
    const QString & oldWorkingDirectory = workingDirectory();

    m_userWorkingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
        emit workingDirectoryChanged(newWorkingDirectory);
dt's avatar
dt committed
173
174
}

175
QVariantMap CMakeRunConfiguration::toMap() const
dt's avatar
dt committed
176
{
177
178
    QVariantMap map(ProjectExplorer::LocalApplicationRunConfiguration::toMap());

179
    map.insert(QLatin1String(TARGET_KEY), m_buildTarget);
180
181
182
183
184
185
186
    map.insert(QLatin1String(WORKING_DIRECTORY_KEY), m_workingDirectory);
    map.insert(QLatin1String(USER_WORKING_DIRECTORY_KEY), m_userWorkingDirectory);
    map.insert(QLatin1String(USE_TERMINAL_KEY), m_runMode == Console);
    map.insert(QLatin1String(TITLE_KEY), m_title);
    map.insert(QLatin1String(ARGUMENTS_KEY), m_arguments);
    map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges));
    map.insert(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), m_baseEnvironmentBase);
187

188
    return map;
dt's avatar
dt committed
189
190
}

191
bool CMakeRunConfiguration::fromMap(const QVariantMap &map)
dt's avatar
dt committed
192
{
193
    m_buildTarget = map.value(QLatin1String(TARGET_KEY)).toString();
194
195
196
197
198
199
200
201
202
    m_workingDirectory = map.value(QLatin1String(WORKING_DIRECTORY_KEY)).toString();
    m_userWorkingDirectory = map.value(QLatin1String(USER_WORKING_DIRECTORY_KEY)).toString();
    m_runMode = map.value(QLatin1String(USE_TERMINAL_KEY)).toBool() ? Console : Gui;
    m_title = map.value(QLatin1String(TITLE_KEY)).toString();
    m_arguments = map.value(QLatin1String(ARGUMENTS_KEY)).toString();
    m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
    m_baseEnvironmentBase = static_cast<BaseEnvironmentBase>(map.value(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), static_cast<int>(CMakeRunConfiguration::BuildEnvironmentBase)).toInt());

    return RunConfiguration::fromMap(map);
dt's avatar
dt committed
203
204
205
206
}

QWidget *CMakeRunConfiguration::configurationWidget()
{
207
    return new CMakeRunConfigurationWidget(this);
208
209
210
211
212
}

void CMakeRunConfiguration::setArguments(const QString &newText)
{
    m_arguments = newText;
dt's avatar
dt committed
213
214
}

215
216
QString CMakeRunConfiguration::dumperLibrary() const
{
217
    QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment());
dt's avatar
dt committed
218
219
    QString qtInstallData = ProjectExplorer::DebuggingHelperLibrary::qtInstallDataDir(qmakePath);
    QString dhl = ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryByInstallData(qtInstallData);
220
    return dhl;
221
222
}

223
224
225
QStringList CMakeRunConfiguration::dumperLibraryLocations() const
{
    QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment());
dt's avatar
dt committed
226
227
    QString qtInstallData = ProjectExplorer::DebuggingHelperLibrary::qtInstallDataDir(qmakePath);
    return ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryLocationsByInstallData(qtInstallData);
228
229
}

230
231
ProjectExplorer::Environment CMakeRunConfiguration::baseEnvironment() const
{
232
233
234
235
236
237
    ProjectExplorer::Environment env;
    if (m_baseEnvironmentBase == CMakeRunConfiguration::CleanEnvironmentBase) {
        // Nothing
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::SystemEnvironmentBase) {
        env = ProjectExplorer::Environment::systemEnvironment();
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::BuildEnvironmentBase) {
Tobias Hunger's avatar
Tobias Hunger committed
238
        env = activeBuildConfiguration()->environment();
239
    }
240
241
242
    return env;
}

243
244
245
246
247
248
249
250
251
252
253
254
QString CMakeRunConfiguration::baseEnvironmentText() const
{
    if (m_baseEnvironmentBase == CMakeRunConfiguration::CleanEnvironmentBase) {
        return tr("Clean Environment");
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::SystemEnvironmentBase) {
        return tr("System Environment");
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::BuildEnvironmentBase) {
        return tr("Build Environment");
    }
    return QString();
}

255
256
257
258
259
260
261
262
263
264
265
266
267
void CMakeRunConfiguration::setBaseEnvironmentBase(BaseEnvironmentBase env)
{
    if (m_baseEnvironmentBase == env)
        return;
    m_baseEnvironmentBase = env;
    emit baseEnvironmentChanged();
}

CMakeRunConfiguration::BaseEnvironmentBase CMakeRunConfiguration::baseEnvironmentBase() const
{
    return m_baseEnvironmentBase;
}

268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
ProjectExplorer::Environment CMakeRunConfiguration::environment() const
{
    ProjectExplorer::Environment env = baseEnvironment();
    env.modify(userEnvironmentChanges());
    return env;
}

QList<ProjectExplorer::EnvironmentItem> CMakeRunConfiguration::userEnvironmentChanges() const
{
    return m_userEnvironmentChanges;
}

void CMakeRunConfiguration::setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff)
{
    if (m_userEnvironmentChanges != diff) {
        m_userEnvironmentChanges = diff;
        emit userEnvironmentChangesChanged(diff);
    }
}

288
289
ProjectExplorer::ToolChain::ToolChainType CMakeRunConfiguration::toolChainType() const
{
Tobias Hunger's avatar
Tobias Hunger committed
290
291
292
    CMakeBuildConfiguration *bc = activeBuildConfiguration();
    if (!bc)
        return ProjectExplorer::ToolChain::UNKNOWN;
293
    return bc->toolChainType();
294
295
}

296
297
298
299
// Configuration widget


CMakeRunConfigurationWidget::CMakeRunConfigurationWidget(CMakeRunConfiguration *cmakeRunConfiguration, QWidget *parent)
300
    : QWidget(parent), m_ignoreChange(false), m_cmakeRunConfiguration(cmakeRunConfiguration)
301
302
303
{

    QFormLayout *fl = new QFormLayout();
304
305
    fl->setMargin(0);
    fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
306
307
308
309
310
311
    QLineEdit *argumentsLineEdit = new QLineEdit();
    argumentsLineEdit->setText(ProjectExplorer::Environment::joinArgumentList(cmakeRunConfiguration->commandLineArguments()));
    connect(argumentsLineEdit, SIGNAL(textChanged(QString)),
            this, SLOT(setArguments(QString)));
    fl->addRow(tr("Arguments:"), argumentsLineEdit);

312
    m_workingDirectoryEdit = new Utils::PathChooser();
313
    m_workingDirectoryEdit->setPath(m_cmakeRunConfiguration->workingDirectory());
314
    m_workingDirectoryEdit->setExpectedKind(Utils::PathChooser::Directory);
315
316
317
318
319
320
321
322
323
324
325
326
    m_workingDirectoryEdit->setPromptDialogTitle(tr("Select the working directory"));

    QToolButton *resetButton = new QToolButton();
    resetButton->setToolTip(tr("Reset to default"));
    resetButton->setIcon(QIcon(":/core/images/reset.png"));

    QHBoxLayout *boxlayout = new QHBoxLayout();
    boxlayout->addWidget(m_workingDirectoryEdit);
    boxlayout->addWidget(resetButton);

    fl->addRow(tr("Working Directory:"), boxlayout);

327
    m_detailsContainer = new Utils::DetailsWidget(this);
328
    m_detailsContainer->setState(Utils::DetailsWidget::NoSummary);
dt's avatar
dt committed
329

330
331
332
    QWidget *m_details = new QWidget(m_detailsContainer);
    m_detailsContainer->setWidget(m_details);
    m_details->setLayout(fl);
dt's avatar
dt committed
333

334
    QVBoxLayout *vbx = new QVBoxLayout(this);
335
336
    vbx->setMargin(0);;
    vbx->addWidget(m_detailsContainer);
337
338
339
340
341
342
343
344

    QLabel *environmentLabel = new QLabel(this);
    environmentLabel->setText(tr("Run Environment"));
    QFont f = environmentLabel->font();
    f.setBold(true);
    f.setPointSizeF(f.pointSizeF() *1.2);
    environmentLabel->setFont(f);
    vbx->addWidget(environmentLabel);
345

346
347
348
    QWidget *baseEnvironmentWidget = new QWidget;
    QHBoxLayout *baseEnvironmentLayout = new QHBoxLayout(baseEnvironmentWidget);
    baseEnvironmentLayout->setMargin(0);
349
    QLabel *label = new QLabel(tr("Base environment for this runconfiguration:"), this);
350
    baseEnvironmentLayout->addWidget(label);
351
    m_baseEnvironmentComboBox = new QComboBox(this);
352
353
354
355
356
357
358
    m_baseEnvironmentComboBox->addItems(QStringList()
                                        << tr("Clean Environment")
                                        << tr("System Environment")
                                        << tr("Build Environment"));
    m_baseEnvironmentComboBox->setCurrentIndex(m_cmakeRunConfiguration->baseEnvironmentBase());
    connect(m_baseEnvironmentComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(baseEnvironmentComboBoxChanged(int)));
359
360
    baseEnvironmentLayout->addWidget(m_baseEnvironmentComboBox);
    baseEnvironmentLayout->addStretch(10);
361

dt's avatar
dt committed
362
363
    m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this, baseEnvironmentWidget);
    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
364
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
dt's avatar
dt committed
365
366
367
368
    m_environmentWidget->setUserChanges(m_cmakeRunConfiguration->userEnvironmentChanges());

    vbx->addWidget(m_environmentWidget);

con's avatar
con committed
369
    connect(m_workingDirectoryEdit, SIGNAL(changed(QString)),
370
371
372
373
374
            this, SLOT(setWorkingDirectory()));

    connect(resetButton, SIGNAL(clicked()),
            this, SLOT(resetWorkingDirectory()));

375
376
    connect(m_environmentWidget, SIGNAL(userChangesChanged()),
            this, SLOT(userChangesChanged()));
377

378
379
    connect(m_cmakeRunConfiguration, SIGNAL(workingDirectoryChanged(QString)),
            this, SLOT(workingDirectoryChanged(QString)));
380
381
382
383
    connect(m_cmakeRunConfiguration, SIGNAL(baseEnvironmentChanged()),
            this, SLOT(baseEnvironmentChanged()));
    connect(m_cmakeRunConfiguration, SIGNAL(userEnvironmentChangesChanged(QList<ProjectExplorer::EnvironmentItem>)),
            this, SLOT(userEnvironmentChangesChanged()));
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

}

void CMakeRunConfigurationWidget::setWorkingDirectory()
{
    if (m_ignoreChange)
        return;
    m_ignoreChange = true;
    m_cmakeRunConfiguration->setUserWorkingDirectory(m_workingDirectoryEdit->path());
    m_ignoreChange = false;
}

void CMakeRunConfigurationWidget::workingDirectoryChanged(const QString &workingDirectory)
{
    if (!m_ignoreChange)
        m_workingDirectoryEdit->setPath(workingDirectory);
}

void CMakeRunConfigurationWidget::resetWorkingDirectory()
{
    // This emits a signal connected to workingDirectoryChanged()
    // that sets the m_workingDirectoryEdit
    m_cmakeRunConfiguration->setUserWorkingDirectory("");
407
408
}

409
void CMakeRunConfigurationWidget::userChangesChanged()
410
411
412
413
{
    m_cmakeRunConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
}

414
void CMakeRunConfigurationWidget::baseEnvironmentComboBoxChanged(int index)
415
416
{
    m_ignoreChange = true;
417
    m_cmakeRunConfiguration->setBaseEnvironmentBase(CMakeRunConfiguration::BaseEnvironmentBase(index));
418
419

    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
420
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
421
422
423
    m_ignoreChange = false;
}

424
425
void CMakeRunConfigurationWidget::baseEnvironmentChanged()
{
426
427
428
    if (m_ignoreChange)
        return;

429
    m_baseEnvironmentComboBox->setCurrentIndex(m_cmakeRunConfiguration->baseEnvironmentBase());
430
    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
431
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
432
433
434
435
436
437
438
439
440
441
}

void CMakeRunConfigurationWidget::userEnvironmentChangesChanged()
{
    m_environmentWidget->setUserChanges(m_cmakeRunConfiguration->userEnvironmentChanges());
}

void CMakeRunConfigurationWidget::setArguments(const QString &args)
{
    m_cmakeRunConfiguration->setArguments(args);
dt's avatar
dt committed
442
443
}

dt's avatar
dt committed
444
// Factory
445
446
CMakeRunConfigurationFactory::CMakeRunConfigurationFactory(QObject *parent) :
    ProjectExplorer::IRunConfigurationFactory(parent)
dt's avatar
dt committed
447
448
449
450
451
452
453
{
}

CMakeRunConfigurationFactory::~CMakeRunConfigurationFactory()
{
}

454
// used to show the list of possible additons to a project, returns a list of ids
Tobias Hunger's avatar
Tobias Hunger committed
455
QStringList CMakeRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
dt's avatar
dt committed
456
{
Tobias Hunger's avatar
Tobias Hunger committed
457
458
    CMakeTarget *t(qobject_cast<CMakeTarget *>(parent));
    if (!t)
dt's avatar
dt committed
459
        return QStringList();
460
    QStringList allIds;
Tobias Hunger's avatar
Tobias Hunger committed
461
    foreach (const QString &buildTarget, t->cmakeProject()->buildTargetTitles())
462
        allIds << idFromBuildTarget(buildTarget);
463
    return allIds;
dt's avatar
dt committed
464
465
}

466
467
// used to translate the ids to names to display to the user
QString CMakeRunConfigurationFactory::displayNameForId(const QString &id) const
dt's avatar
dt committed
468
{
469
    return buildTargetFromId(id);
470
}
dt's avatar
dt committed
471

Tobias Hunger's avatar
Tobias Hunger committed
472
bool CMakeRunConfigurationFactory::canCreate(ProjectExplorer::Target *parent, const QString &id) const
473
{
Tobias Hunger's avatar
Tobias Hunger committed
474
475
    CMakeTarget *t(qobject_cast<CMakeTarget *>(parent));
    if (!t)
476
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
477
    return t->cmakeProject()->hasBuildTarget(buildTargetFromId(id));
dt's avatar
dt committed
478
479
}

Tobias Hunger's avatar
Tobias Hunger committed
480
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::create(ProjectExplorer::Target *parent, const QString &id)
dt's avatar
dt committed
481
{
482
483
    if (!canCreate(parent, id))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
484
    CMakeTarget *t(static_cast<CMakeTarget *>(parent));
485

486
    const QString title(buildTargetFromId(id));
Tobias Hunger's avatar
Tobias Hunger committed
487
488
    const CMakeBuildTarget &ct = t->cmakeProject()->buildTargetForTitle(title);
    return new CMakeRunConfiguration(t, ct.executable, ct.workingDirectory, ct.title);
489
490
}

Tobias Hunger's avatar
Tobias Hunger committed
491
bool CMakeRunConfigurationFactory::canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const
492
{
Tobias Hunger's avatar
Tobias Hunger committed
493
    if (!qobject_cast<CMakeTarget *>(parent))
494
495
496
497
        return false;
    return source->id() == QLatin1String(CMAKE_RC_ID);
}

Tobias Hunger's avatar
Tobias Hunger committed
498
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration * source)
499
500
501
{
    if (!canClone(parent, source))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
502
    CMakeTarget *t(static_cast<CMakeTarget *>(parent));
503
    CMakeRunConfiguration *crc(static_cast<CMakeRunConfiguration *>(source));
Tobias Hunger's avatar
Tobias Hunger committed
504
    return new CMakeRunConfiguration(t, crc);
505
506
}

Tobias Hunger's avatar
Tobias Hunger committed
507
bool CMakeRunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
508
{
Tobias Hunger's avatar
Tobias Hunger committed
509
    if (!qobject_cast<CMakeTarget *>(parent))
510
511
512
513
514
        return false;
    QString id(ProjectExplorer::idFromMap(map));
    return id.startsWith(QLatin1String(CMAKE_RC_ID));
}

Tobias Hunger's avatar
Tobias Hunger committed
515
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
516
517
518
{
    if (!canRestore(parent, map))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
519
520
    CMakeTarget *t(static_cast<CMakeTarget *>(parent));
    CMakeRunConfiguration *rc(new CMakeRunConfiguration(t, QString(), QString(), QString()));
521
    if (rc->fromMap(map))
dt's avatar
dt committed
522
        return rc;
523
524
    delete rc;
    return 0;
dt's avatar
dt committed
525
}