cmakerunconfiguration.cpp 20.4 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
dt's avatar
dt committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
dt's avatar
dt committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
dt's avatar
dt committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
dt's avatar
dt committed
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
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"
dt's avatar
dt committed
35

36
#include <coreplugin/coreconstants.h>
37
#include <coreplugin/helpmanager.h>
38
#include <qtsupport/debugginghelper.h>
39
#include <projectexplorer/environmentwidget.h>
Tobias Hunger's avatar
Tobias Hunger committed
40
#include <projectexplorer/target.h>
41 42 43

#include <utils/pathchooser.h>
#include <utils/detailswidget.h>
hjk's avatar
hjk committed
44
#include <utils/qtcassert.h>
45 46
#include <utils/qtcprocess.h>
#include <utils/stringutils.h>
47

48 49 50 51 52 53 54
#include <QFormLayout>
#include <QLineEdit>
#include <QGroupBox>
#include <QLabel>
#include <QComboBox>
#include <QToolButton>
#include <QCheckBox>
dt's avatar
dt committed
55 56 57 58

using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;

59
namespace {
60
const char CMAKE_RC_PREFIX[] = "CMakeProjectManager.CMakeRunConfiguration.";
61

62 63 64 65 66 67
const char USER_WORKING_DIRECTORY_KEY[] = "CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory";
const char USE_TERMINAL_KEY[] = "CMakeProjectManager.CMakeRunConfiguration.UseTerminal";
const char TITLE_KEY[] = "CMakeProjectManager.CMakeRunConfiguation.Title";
const char ARGUMENTS_KEY[] = "CMakeProjectManager.CMakeRunConfiguration.Arguments";
const char USER_ENVIRONMENT_CHANGES_KEY[] = "CMakeProjectManager.CMakeRunConfiguration.UserEnvironmentChanges";
const char BASE_ENVIRONMENT_BASE_KEY[] = "CMakeProjectManager.BaseEnvironmentBase";
68 69 70

} // namespace

Tobias Hunger's avatar
Tobias Hunger committed
71 72 73
CMakeRunConfiguration::CMakeRunConfiguration(ProjectExplorer::Target *parent, Core::Id id, const QString &target,
                                             const QString &workingDirectory, const QString &title) :
    ProjectExplorer::LocalApplicationRunConfiguration(parent, id),
74
    m_runMode(Gui),
75
    m_buildTarget(target),
76 77
    m_workingDirectory(workingDirectory),
    m_title(title),
78 79
    m_baseEnvironmentBase(CMakeRunConfiguration::BuildEnvironmentBase),
    m_enabled(true)
dt's avatar
dt committed
80
{
81 82
    ctor();
}
dt's avatar
dt committed
83

Tobias Hunger's avatar
Tobias Hunger committed
84
CMakeRunConfiguration::CMakeRunConfiguration(ProjectExplorer::Target *parent, CMakeRunConfiguration *source) :
Tobias Hunger's avatar
Tobias Hunger committed
85
    ProjectExplorer::LocalApplicationRunConfiguration(parent, source),
86
    m_runMode(source->m_runMode),
87
    m_buildTarget(source->m_buildTarget),
88 89 90 91 92
    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),
93 94
    m_baseEnvironmentBase(source->m_baseEnvironmentBase),
    m_enabled(source->m_enabled)
95 96
{
    ctor();
dt's avatar
dt committed
97 98
}

99
CMakeRunConfiguration::~CMakeRunConfiguration()
dt's avatar
dt committed
100
{
dt's avatar
dt committed
101 102
}

103
void CMakeRunConfiguration::ctor()
dt's avatar
dt committed
104
{
105
    setDefaultDisplayName(defaultDisplayName());
106 107
    connect(target(), SIGNAL(environmentChanged()),
            this, SIGNAL(baseEnvironmentChanged()));
Tobias Hunger's avatar
Tobias Hunger committed
108
}
109

dt's avatar
dt committed
110 111
QString CMakeRunConfiguration::executable() const
{
112
    return m_buildTarget;
dt's avatar
dt committed
113 114
}

115
ProjectExplorer::LocalApplicationRunConfiguration::RunMode CMakeRunConfiguration::runMode() const
dt's avatar
dt committed
116
{
117
    return m_runMode;
dt's avatar
dt committed
118 119
}

120 121 122 123 124
void CMakeRunConfiguration::setRunMode(RunMode runMode)
{
    m_runMode = runMode;
}

dt's avatar
dt committed
125
QString CMakeRunConfiguration::workingDirectory() const
126
{
127 128
    return QDir::cleanPath(environment().expandVariables(
                Utils::expandMacros(baseWorkingDirectory(), macroExpander())));
129 130 131
}

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

138
QString CMakeRunConfiguration::commandLineArguments() const
139
{
140
    return Utils::QtcProcess::expandMacros(m_arguments, macroExpander());
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::setBaseWorkingDirectory(const QString &wd)
dt's avatar
dt committed
154
{
155
    const QString &oldWorkingDirectory = workingDirectory();
156 157 158 159 160

    m_workingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
161
        emit baseWorkingDirectoryChanged(newWorkingDirectory);
162 163 164 165 166 167 168 169 170 171
}

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

    m_userWorkingDirectory = wd;

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

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

    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);
183
    map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), Utils::EnvironmentItem::toStringList(m_userEnvironmentChanges));
184
    map.insert(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), m_baseEnvironmentBase);
185

186
    return map;
dt's avatar
dt committed
187 188
}

189
bool CMakeRunConfiguration::fromMap(const QVariantMap &map)
dt's avatar
dt committed
190
{
191 192 193 194
    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();
195
    m_userEnvironmentChanges = Utils::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
196 197 198
    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
199 200
}

201 202 203
QString CMakeRunConfiguration::defaultDisplayName() const
{
    if (m_title.isEmpty())
204
        return tr("Run CMake kit");
205
    return m_title + (m_enabled ? QString() : tr(" (disabled)"));
206 207
}

208
QWidget *CMakeRunConfiguration::createConfigurationWidget()
dt's avatar
dt committed
209
{
210
    return new CMakeRunConfigurationWidget(this);
211 212
}

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

218 219
QString CMakeRunConfiguration::dumperLibrary() const
{
220 221 222
    Utils::FileName qmakePath = QtSupport::DebuggingHelperLibrary::findSystemQt(environment());
    QString qtInstallData = QtSupport::DebuggingHelperLibrary::qtInstallDataDir(qmakePath);
    QString dhl = QtSupport::DebuggingHelperLibrary::debuggingHelperLibraryByInstallData(qtInstallData);
223
    return dhl;
224 225
}

226 227
QStringList CMakeRunConfiguration::dumperLibraryLocations() const
{
228 229 230
    Utils::FileName qmakePath = QtSupport::DebuggingHelperLibrary::findSystemQt(environment());
    QString qtInstallData = QtSupport::DebuggingHelperLibrary::qtInstallDataDir(qmakePath);
    return QtSupport::DebuggingHelperLibrary::debuggingHelperLibraryDirectories(qtInstallData);
231 232
}

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

246 247 248 249 250 251 252 253 254 255 256 257
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();
}

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

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

271
Utils::Environment CMakeRunConfiguration::environment() const
272
{
273
    Utils::Environment env = baseEnvironment();
274 275 276 277
    env.modify(userEnvironmentChanges());
    return env;
}

278
QList<Utils::EnvironmentItem> CMakeRunConfiguration::userEnvironmentChanges() const
279 280 281 282
{
    return m_userEnvironmentChanges;
}

283
void CMakeRunConfiguration::setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff)
284 285 286 287 288 289 290
{
    if (m_userEnvironmentChanges != diff) {
        m_userEnvironmentChanges = diff;
        emit userEnvironmentChangesChanged(diff);
    }
}

291 292 293 294 295
void CMakeRunConfiguration::setEnabled(bool b)
{
    if (m_enabled == b)
        return;
    m_enabled = b;
296
    emit enabledChanged();
297
    setDefaultDisplayName(defaultDisplayName());
298
}
299

300
bool CMakeRunConfiguration::isEnabled() const
301
{
302
    return m_enabled;
303
}
304

dt_'s avatar
dt_ committed
305 306 307
QString CMakeRunConfiguration::disabledReason() const
{
    if (!m_enabled)
Friedemann Kleint's avatar
Friedemann Kleint committed
308
        return tr("The executable is not built by the current build configuration");
dt_'s avatar
dt_ committed
309 310 311
    return QString();
}

312
// Configuration widget
313
CMakeRunConfigurationWidget::CMakeRunConfigurationWidget(CMakeRunConfiguration *cmakeRunConfiguration, QWidget *parent)
314
    : QWidget(parent), m_ignoreChange(false), m_cmakeRunConfiguration(cmakeRunConfiguration)
315 316
{
    QFormLayout *fl = new QFormLayout();
317 318
    fl->setMargin(0);
    fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
319
    QLineEdit *argumentsLineEdit = new QLineEdit();
320
    argumentsLineEdit->setText(cmakeRunConfiguration->commandLineArguments());
321 322 323 324
    connect(argumentsLineEdit, SIGNAL(textChanged(QString)),
            this, SLOT(setArguments(QString)));
    fl->addRow(tr("Arguments:"), argumentsLineEdit);

325
    m_workingDirectoryEdit = new Utils::PathChooser();
326
    m_workingDirectoryEdit->setExpectedKind(Utils::PathChooser::Directory);
327
    m_workingDirectoryEdit->setBaseDirectory(m_cmakeRunConfiguration->target()->project()->projectDirectory());
328
    m_workingDirectoryEdit->setPath(m_cmakeRunConfiguration->baseWorkingDirectory());
329
    m_workingDirectoryEdit->setPromptDialogTitle(tr("Select Working Directory"));
330 331 332

    QToolButton *resetButton = new QToolButton();
    resetButton->setToolTip(tr("Reset to default"));
333
    resetButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RESET)));
334 335 336 337 338

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

339
    fl->addRow(tr("Working directory:"), boxlayout);
340

341 342 343
    QCheckBox *runInTerminal = new QCheckBox;
    fl->addRow(tr("Run in Terminal"), runInTerminal);

344
    m_detailsContainer = new Utils::DetailsWidget(this);
345
    m_detailsContainer->setState(Utils::DetailsWidget::NoSummary);
dt's avatar
dt committed
346

347 348 349
    QWidget *m_details = new QWidget(m_detailsContainer);
    m_detailsContainer->setWidget(m_details);
    m_details->setLayout(fl);
dt's avatar
dt committed
350

351
    QVBoxLayout *vbx = new QVBoxLayout(this);
352 353
    vbx->setMargin(0);;
    vbx->addWidget(m_detailsContainer);
354 355 356 357 358 359 360 361

    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);
362

363 364 365
    QWidget *baseEnvironmentWidget = new QWidget;
    QHBoxLayout *baseEnvironmentLayout = new QHBoxLayout(baseEnvironmentWidget);
    baseEnvironmentLayout->setMargin(0);
366
    QLabel *label = new QLabel(tr("Base environment for this runconfiguration:"), this);
367
    baseEnvironmentLayout->addWidget(label);
368
    m_baseEnvironmentComboBox = new QComboBox(this);
369 370 371 372 373 374 375
    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)));
376 377
    baseEnvironmentLayout->addWidget(m_baseEnvironmentComboBox);
    baseEnvironmentLayout->addStretch(10);
378

dt's avatar
dt committed
379 380
    m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this, baseEnvironmentWidget);
    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
381
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
dt's avatar
dt committed
382 383 384 385
    m_environmentWidget->setUserChanges(m_cmakeRunConfiguration->userEnvironmentChanges());

    vbx->addWidget(m_environmentWidget);

con's avatar
con committed
386
    connect(m_workingDirectoryEdit, SIGNAL(changed(QString)),
387 388 389 390 391
            this, SLOT(setWorkingDirectory()));

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

392 393 394
    connect(runInTerminal, SIGNAL(toggled(bool)),
            this, SLOT(runInTerminalToggled(bool)));

395 396
    connect(m_environmentWidget, SIGNAL(userChangesChanged()),
            this, SLOT(userChangesChanged()));
397

398
    connect(m_cmakeRunConfiguration, SIGNAL(baseWorkingDirectoryChanged(QString)),
399
            this, SLOT(workingDirectoryChanged(QString)));
400 401
    connect(m_cmakeRunConfiguration, SIGNAL(baseEnvironmentChanged()),
            this, SLOT(baseEnvironmentChanged()));
402
    connect(m_cmakeRunConfiguration, SIGNAL(userEnvironmentChangesChanged(QList<Utils::EnvironmentItem>)),
403
            this, SLOT(userEnvironmentChangesChanged()));
404

405
    setEnabled(m_cmakeRunConfiguration->isEnabled());
406 407 408 409 410 411 412
}

void CMakeRunConfigurationWidget::setWorkingDirectory()
{
    if (m_ignoreChange)
        return;
    m_ignoreChange = true;
413
    m_cmakeRunConfiguration->setUserWorkingDirectory(m_workingDirectoryEdit->rawPath());
414 415 416 417 418
    m_ignoreChange = false;
}

void CMakeRunConfigurationWidget::workingDirectoryChanged(const QString &workingDirectory)
{
419 420
    if (!m_ignoreChange) {
        m_ignoreChange = true;
421
        m_workingDirectoryEdit->setPath(workingDirectory);
422 423
        m_ignoreChange = false;
    }
424 425 426 427 428 429
}

void CMakeRunConfigurationWidget::resetWorkingDirectory()
{
    // This emits a signal connected to workingDirectoryChanged()
    // that sets the m_workingDirectoryEdit
430
    m_cmakeRunConfiguration->setUserWorkingDirectory(QString());
431 432
}

433 434 435 436 437 438
void CMakeRunConfigurationWidget::runInTerminalToggled(bool toggled)
{
    m_cmakeRunConfiguration->setRunMode(toggled ? ProjectExplorer::LocalApplicationRunConfiguration::Console
                                                : ProjectExplorer::LocalApplicationRunConfiguration::Gui);
}

439
void CMakeRunConfigurationWidget::userChangesChanged()
440 441 442 443
{
    m_cmakeRunConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
}

444
void CMakeRunConfigurationWidget::baseEnvironmentComboBoxChanged(int index)
445 446
{
    m_ignoreChange = true;
447
    m_cmakeRunConfiguration->setBaseEnvironmentBase(CMakeRunConfiguration::BaseEnvironmentBase(index));
448 449

    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
450
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
451 452 453
    m_ignoreChange = false;
}

454 455
void CMakeRunConfigurationWidget::baseEnvironmentChanged()
{
456 457 458
    if (m_ignoreChange)
        return;

459
    m_baseEnvironmentComboBox->setCurrentIndex(m_cmakeRunConfiguration->baseEnvironmentBase());
460
    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
461
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
462 463 464 465 466 467 468 469 470
}

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

void CMakeRunConfigurationWidget::setArguments(const QString &args)
{
471
    m_cmakeRunConfiguration->setCommandLineArguments(args);
dt's avatar
dt committed
472 473
}

dt's avatar
dt committed
474
// Factory
475 476
CMakeRunConfigurationFactory::CMakeRunConfigurationFactory(QObject *parent) :
    ProjectExplorer::IRunConfigurationFactory(parent)
Tobias Hunger's avatar
Tobias Hunger committed
477
{ setObjectName(QLatin1String("CMakeRunConfigurationFactory")); }
dt's avatar
dt committed
478 479 480 481 482

CMakeRunConfigurationFactory::~CMakeRunConfigurationFactory()
{
}

483
// used to show the list of possible additons to a project, returns a list of ids
484
QList<Core::Id> CMakeRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
dt's avatar
dt committed
485
{
Tobias Hunger's avatar
Tobias Hunger committed
486
    if (!canHandle(parent))
487
        return QList<Core::Id>();
488
    CMakeProject *project = static_cast<CMakeProject *>(parent->project());
489
    QList<Core::Id> allIds;
490
    foreach (const QString &buildTarget, project->buildTargetTitles(true))
491
        allIds << idFromBuildTarget(buildTarget);
492
    return allIds;
dt's avatar
dt committed
493 494
}

495
// used to translate the ids to names to display to the user
496
QString CMakeRunConfigurationFactory::displayNameForId(const Core::Id id) const
dt's avatar
dt committed
497
{
498
    return buildTargetFromId(id);
499
}
dt's avatar
dt committed
500

Tobias Hunger's avatar
Tobias Hunger committed
501 502
bool CMakeRunConfigurationFactory::canHandle(ProjectExplorer::Target *parent) const
{
Tobias Hunger's avatar
Tobias Hunger committed
503
    if (!parent->project()->supportsKit(parent->kit()))
Tobias Hunger's avatar
Tobias Hunger committed
504 505 506 507
        return false;
    return qobject_cast<CMakeProject *>(parent->project());
}

508
bool CMakeRunConfigurationFactory::canCreate(ProjectExplorer::Target *parent, const Core::Id id) const
509
{
Tobias Hunger's avatar
Tobias Hunger committed
510
    if (!canHandle(parent))
511
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
512 513
    CMakeProject *project = static_cast<CMakeProject *>(parent->project());
    return project->hasBuildTarget(buildTargetFromId(id));
dt's avatar
dt committed
514 515
}

516 517
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::doCreate(ProjectExplorer::Target *parent,
                                                                          const Core::Id id)
dt's avatar
dt committed
518
{
Tobias Hunger's avatar
Tobias Hunger committed
519
    CMakeProject *project = static_cast<CMakeProject *>(parent->project());
520
    const QString title(buildTargetFromId(id));
Tobias Hunger's avatar
Tobias Hunger committed
521 522
    const CMakeBuildTarget &ct = project->buildTargetForTitle(title);
    return new CMakeRunConfiguration(parent, id, ct.executable, ct.workingDirectory, ct.title);
523 524
}

Tobias Hunger's avatar
Tobias Hunger committed
525
bool CMakeRunConfigurationFactory::canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const
526
{
Tobias Hunger's avatar
Tobias Hunger committed
527
    if (!canHandle(parent))
528
        return false;
hjk's avatar
hjk committed
529
    return source->id().name().startsWith(CMAKE_RC_PREFIX);
530 531
}

Tobias Hunger's avatar
Tobias Hunger committed
532
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration * source)
533 534 535 536
{
    if (!canClone(parent, source))
        return 0;
    CMakeRunConfiguration *crc(static_cast<CMakeRunConfiguration *>(source));
Tobias Hunger's avatar
Tobias Hunger committed
537
    return new CMakeRunConfiguration(parent, crc);
538 539
}

Tobias Hunger's avatar
Tobias Hunger committed
540
bool CMakeRunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
541
{
Tobias Hunger's avatar
Tobias Hunger committed
542
    if (!qobject_cast<CMakeProject *>(parent->project()))
543
        return false;
hjk's avatar
hjk committed
544
    return ProjectExplorer::idFromMap(map).name().startsWith(CMAKE_RC_PREFIX);
545 546
}

547 548
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::doRestore(ProjectExplorer::Target *parent,
                                                                           const QVariantMap &map)
549
{
550 551
    return new CMakeRunConfiguration(parent, ProjectExplorer::idFromMap(map),
                                     QString(), QString(), QString());
dt's avatar
dt committed
552
}
553 554 555

QString CMakeRunConfigurationFactory::buildTargetFromId(Core::Id id)
{
hjk's avatar
hjk committed
556
    return id.suffixAfter(CMAKE_RC_PREFIX);
557 558 559 560
}

Core::Id CMakeRunConfigurationFactory::idFromBuildTarget(const QString &target)
{
hjk's avatar
hjk committed
561
    return Core::Id(CMAKE_RC_PREFIX).withSuffix(target);
562
}