2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-09 14:53:06 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-09 14:53:06 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-09 14:53:06 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-09 14:53:06 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-09 14:53:06 +01:00
|
|
|
|
|
|
|
|
#include "cmakerunconfiguration.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2009-11-25 18:50:20 +01:00
|
|
|
#include "cmakebuildconfiguration.h"
|
2010-02-08 15:50:06 +01:00
|
|
|
#include "cmakeproject.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
#include "cmakeprojectconstants.h"
|
2008-12-09 14:53:06 +01:00
|
|
|
|
2015-11-23 16:41:54 +01:00
|
|
|
#include <coreplugin/coreicons.h>
|
2011-02-24 14:58:37 +01:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2013-04-09 12:05:15 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2017-11-03 12:40:49 +01:00
|
|
|
#include <qtsupport/qtoutputformatter.h>
|
2013-11-01 14:13:41 +01:00
|
|
|
#include <projectexplorer/localenvironmentaspect.h>
|
2015-04-30 13:11:25 +02:00
|
|
|
#include <projectexplorer/runconfigurationaspects.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2011-02-28 16:50:14 +01:00
|
|
|
|
|
|
|
|
#include <utils/detailswidget.h>
|
2017-07-12 12:52:06 +02:00
|
|
|
#include <utils/fancylineedit.h>
|
2017-11-23 14:06:48 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2016-01-06 11:40:52 +01:00
|
|
|
#include <utils/pathchooser.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2011-08-18 13:46:52 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
|
|
|
|
#include <utils/stringutils.h>
|
2011-02-28 16:50:14 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QGroupBox>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QCheckBox>
|
2008-12-09 14:53:06 +01:00
|
|
|
|
|
|
|
|
using namespace CMakeProjectManager;
|
|
|
|
|
using namespace CMakeProjectManager::Internal;
|
2014-05-26 22:13:14 +03:00
|
|
|
using namespace ProjectExplorer;
|
2008-12-09 14:53:06 +01:00
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
namespace {
|
2011-11-02 16:45:13 +01:00
|
|
|
const char CMAKE_RC_PREFIX[] = "CMakeProjectManager.CMakeRunConfiguration.";
|
|
|
|
|
const char TITLE_KEY[] = "CMakeProjectManager.CMakeRunConfiguation.Title";
|
2010-01-19 13:41:02 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
2017-09-01 13:23:02 +02:00
|
|
|
CMakeRunConfiguration::CMakeRunConfiguration(Target *target)
|
|
|
|
|
: RunConfiguration(target)
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2017-11-23 14:06:48 +01:00
|
|
|
// Workaround for QTCREATORBUG-19354:
|
|
|
|
|
auto cmakeRunEnvironmentModifier = [](RunConfiguration *rc, Utils::Environment &env) {
|
|
|
|
|
if (!Utils::HostOsInfo::isWindowsHost() || !rc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const Kit *k = rc->target()->kit();
|
|
|
|
|
const QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(k);
|
|
|
|
|
if (qt)
|
|
|
|
|
env.prependOrSetPath(qt->qmakeProperty("QT_INSTALL_BINS"));
|
|
|
|
|
};
|
|
|
|
|
addExtraAspect(new LocalEnvironmentAspect(this, cmakeRunEnvironmentModifier));
|
2017-09-01 13:23:02 +02:00
|
|
|
addExtraAspect(new ArgumentsAspect(this, "CMakeProjectManager.CMakeRunConfiguration.Arguments"));
|
|
|
|
|
addExtraAspect(new TerminalAspect(this, "CMakeProjectManager.CMakeRunConfiguration.UseTerminal"));
|
|
|
|
|
addExtraAspect(new WorkingDirectoryAspect(this, "CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory"));
|
2010-01-19 13:41:02 +01:00
|
|
|
}
|
2009-11-26 14:43:27 +01:00
|
|
|
|
2017-11-14 15:48:08 +01:00
|
|
|
void CMakeRunConfiguration::initialize(Core::Id id)
|
2010-01-19 13:41:02 +01:00
|
|
|
{
|
2017-09-01 13:23:02 +02:00
|
|
|
RunConfiguration::initialize(id);
|
2017-11-14 15:48:08 +01:00
|
|
|
QString executable = id.suffixAfter(CMAKE_RC_PREFIX);
|
2017-09-01 13:23:02 +02:00
|
|
|
|
2017-11-14 15:48:08 +01:00
|
|
|
CMakeProject *project = static_cast<CMakeProject *>(target()->project());
|
|
|
|
|
|
|
|
|
|
m_buildSystemTarget = executable;
|
|
|
|
|
m_executable = executable;
|
|
|
|
|
|
|
|
|
|
if (!executable.isEmpty()) {
|
|
|
|
|
const CMakeBuildTarget ct = project->buildTargetForTitle(executable);
|
|
|
|
|
m_title = ct.title;
|
|
|
|
|
extraAspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(ct.workingDirectory);
|
|
|
|
|
}
|
2017-09-01 13:23:02 +02:00
|
|
|
|
2010-08-19 12:26:21 +02:00
|
|
|
setDefaultDisplayName(defaultDisplayName());
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
2010-01-19 13:41:02 +01:00
|
|
|
|
2016-01-25 15:00:20 +01:00
|
|
|
Runnable CMakeRunConfiguration::runnable() const
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2016-01-25 15:00:20 +01:00
|
|
|
StandardRunnable r;
|
2017-03-27 12:08:30 +02:00
|
|
|
r.executable = m_executable;
|
2016-01-25 15:00:20 +01:00
|
|
|
r.commandLineArguments = extraAspect<ArgumentsAspect>()->arguments();
|
|
|
|
|
r.workingDirectory = extraAspect<WorkingDirectoryAspect>()->workingDirectory().toString();
|
|
|
|
|
r.environment = extraAspect<LocalEnvironmentAspect>()->environment();
|
|
|
|
|
r.runMode = extraAspect<TerminalAspect>()->runMode();
|
|
|
|
|
return r;
|
2010-09-27 15:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeRunConfiguration::baseWorkingDirectory() const
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2017-03-27 12:08:30 +02:00
|
|
|
const QString exe = m_executable;
|
2015-12-16 12:10:11 +01:00
|
|
|
if (!exe.isEmpty())
|
2017-03-27 12:08:30 +02:00
|
|
|
return QFileInfo(m_executable).absolutePath();
|
2015-12-16 12:10:11 +01:00
|
|
|
return QString();
|
2008-12-09 14:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-16 17:33:05 +01:00
|
|
|
QString CMakeRunConfiguration::title() const
|
|
|
|
|
{
|
|
|
|
|
return m_title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeRunConfiguration::setExecutable(const QString &executable)
|
|
|
|
|
{
|
2017-03-27 12:08:30 +02:00
|
|
|
m_executable = executable;
|
2009-03-16 17:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-13 12:02:52 +02:00
|
|
|
void CMakeRunConfiguration::setBaseWorkingDirectory(const Utils::FileName &wd)
|
2009-03-16 17:33:05 +01:00
|
|
|
{
|
2016-10-13 12:02:52 +02:00
|
|
|
extraAspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(wd);
|
2009-03-16 17:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
QVariantMap CMakeRunConfiguration::toMap() const
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2016-01-25 15:00:20 +01:00
|
|
|
QVariantMap map(RunConfiguration::toMap());
|
2010-01-19 13:41:02 +01:00
|
|
|
map.insert(QLatin1String(TITLE_KEY), m_title);
|
|
|
|
|
return map;
|
2008-12-09 14:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
bool CMakeRunConfiguration::fromMap(const QVariantMap &map)
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2010-01-19 13:41:02 +01:00
|
|
|
m_title = map.value(QLatin1String(TITLE_KEY)).toString();
|
|
|
|
|
return RunConfiguration::fromMap(map);
|
2008-12-09 14:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
2010-08-19 12:26:21 +02:00
|
|
|
QString CMakeRunConfiguration::defaultDisplayName() const
|
|
|
|
|
{
|
|
|
|
|
if (m_title.isEmpty())
|
2012-10-19 17:07:26 +02:00
|
|
|
return tr("Run CMake kit");
|
2017-07-17 14:34:05 +02:00
|
|
|
return m_title;
|
2010-08-19 12:26:21 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-17 14:34:05 +02:00
|
|
|
void CMakeRunConfiguration::updateEnabledState()
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2017-07-17 14:34:05 +02:00
|
|
|
auto cp = qobject_cast<CMakeProject *>(target()->project());
|
|
|
|
|
if (!cp->hasBuildTarget(m_buildSystemTarget))
|
|
|
|
|
setEnabled(false);
|
|
|
|
|
else
|
|
|
|
|
RunConfiguration::updateEnabledState();
|
2009-03-25 18:29:42 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-17 14:34:05 +02:00
|
|
|
QWidget *CMakeRunConfiguration::createConfigurationWidget()
|
2010-06-09 13:21:08 +02:00
|
|
|
{
|
2017-07-17 14:34:05 +02:00
|
|
|
return new CMakeRunConfigurationWidget(this);
|
2010-06-09 13:21:08 +02:00
|
|
|
}
|
2009-05-27 17:28:50 +02:00
|
|
|
|
2011-05-26 16:30:35 +02:00
|
|
|
QString CMakeRunConfiguration::disabledReason() const
|
|
|
|
|
{
|
2017-07-17 14:34:05 +02:00
|
|
|
auto cp = qobject_cast<CMakeProject *>(target()->project());
|
|
|
|
|
QTC_ASSERT(cp, return QString());
|
|
|
|
|
|
2017-09-28 17:56:48 +02:00
|
|
|
if (!cp->hasBuildTarget(m_buildSystemTarget))
|
2017-07-17 14:34:05 +02:00
|
|
|
return tr("The project no longer builds the target associated with this run configuration.");
|
|
|
|
|
return RunConfiguration::disabledReason();
|
2011-05-26 16:30:35 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-03 12:40:49 +01:00
|
|
|
Utils::OutputFormatter *CMakeRunConfiguration::createOutputFormatter() const
|
|
|
|
|
{
|
|
|
|
|
if (QtSupport::QtKitInformation::qtVersion(target()->kit()))
|
|
|
|
|
return new QtSupport::QtOutputFormatter(target()->project());
|
|
|
|
|
return RunConfiguration::createOutputFormatter();
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-12 12:52:06 +02:00
|
|
|
static void updateExecutable(CMakeRunConfiguration *rc, Utils::FancyLineEdit *fle)
|
|
|
|
|
{
|
|
|
|
|
const Runnable runnable = rc->runnable();
|
|
|
|
|
fle->setText(runnable.is<StandardRunnable>()
|
|
|
|
|
? Utils::FileName::fromString(runnable.as<StandardRunnable>().executable).toUserOutput()
|
|
|
|
|
: QString());
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-09 13:21:08 +02:00
|
|
|
// Configuration widget
|
2009-05-27 17:28:50 +02:00
|
|
|
CMakeRunConfigurationWidget::CMakeRunConfigurationWidget(CMakeRunConfiguration *cmakeRunConfiguration, QWidget *parent)
|
2015-12-16 12:10:11 +01:00
|
|
|
: QWidget(parent)
|
2009-05-27 17:28:50 +02:00
|
|
|
{
|
2015-12-16 12:10:11 +01:00
|
|
|
auto fl = new QFormLayout();
|
2009-07-23 17:00:38 +02:00
|
|
|
fl->setMargin(0);
|
|
|
|
|
fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
2015-04-30 13:11:25 +02:00
|
|
|
|
2017-07-12 12:52:06 +02:00
|
|
|
auto executableLabel = new QLabel(tr("Executable:"));
|
|
|
|
|
auto executable = new Utils::FancyLineEdit;
|
|
|
|
|
executable->setReadOnly(true);
|
|
|
|
|
executable->setPlaceholderText(tr("<unknown>"));
|
|
|
|
|
connect(cmakeRunConfiguration, &CMakeRunConfiguration::enabledChanged,
|
|
|
|
|
this, std::bind(updateExecutable, cmakeRunConfiguration, executable));
|
|
|
|
|
updateExecutable(cmakeRunConfiguration, executable);
|
|
|
|
|
|
|
|
|
|
fl->addRow(executableLabel, executable);
|
|
|
|
|
|
2015-04-30 13:11:25 +02:00
|
|
|
cmakeRunConfiguration->extraAspect<ArgumentsAspect>()->addToMainConfigurationWidget(this, fl);
|
2015-12-16 12:10:11 +01:00
|
|
|
cmakeRunConfiguration->extraAspect<WorkingDirectoryAspect>()->addToMainConfigurationWidget(this, fl);
|
|
|
|
|
cmakeRunConfiguration->extraAspect<TerminalAspect>()->addToMainConfigurationWidget(this, fl);
|
2009-05-27 17:28:50 +02:00
|
|
|
|
2015-12-16 12:10:11 +01:00
|
|
|
auto detailsContainer = new Utils::DetailsWidget(this);
|
|
|
|
|
detailsContainer->setState(Utils::DetailsWidget::NoSummary);
|
2009-06-16 18:37:16 +02:00
|
|
|
|
2015-12-16 12:10:11 +01:00
|
|
|
auto detailsWidget = new QWidget(detailsContainer);
|
|
|
|
|
detailsContainer->setWidget(detailsWidget);
|
|
|
|
|
detailsWidget->setLayout(fl);
|
2011-04-27 16:33:21 +02:00
|
|
|
|
2015-12-16 12:10:11 +01:00
|
|
|
auto vbx = new QVBoxLayout(this);
|
2013-09-03 18:48:02 +02:00
|
|
|
vbx->setMargin(0);
|
2015-12-16 12:10:11 +01:00
|
|
|
vbx->addWidget(detailsContainer);
|
2013-01-29 18:00:30 +01:00
|
|
|
}
|
2009-09-17 13:59:10 +02:00
|
|
|
|
2008-12-09 14:53:06 +01:00
|
|
|
// Factory
|
2010-01-19 13:41:02 +01:00
|
|
|
CMakeRunConfigurationFactory::CMakeRunConfigurationFactory(QObject *parent) :
|
2014-05-26 22:13:14 +03:00
|
|
|
IRunConfigurationFactory(parent)
|
2017-11-10 15:43:23 +01:00
|
|
|
{
|
|
|
|
|
setObjectName("CMakeRunConfigurationFactory");
|
2017-11-20 11:56:19 +01:00
|
|
|
registerRunConfiguration<CMakeRunConfiguration>(CMAKE_RC_PREFIX);
|
2017-11-17 08:24:47 +01:00
|
|
|
setSupportedProjectType<CMakeProject>();
|
2017-11-10 15:43:23 +01:00
|
|
|
}
|
2008-12-09 14:53:06 +01:00
|
|
|
|
2017-11-20 11:56:19 +01:00
|
|
|
QList<QString> CMakeRunConfigurationFactory::availableBuildTargets(Target *parent, CreationMode) const
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2012-07-04 12:20:13 +02:00
|
|
|
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
|
2017-11-20 11:56:19 +01:00
|
|
|
return project->buildTargetTitles(true);
|
2008-12-09 14:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
2017-11-20 11:56:19 +01:00
|
|
|
bool CMakeRunConfigurationFactory::canCreateHelper(Target *parent, const QString &buildTarget) const
|
2008-12-09 14:53:06 +01:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
|
2017-11-20 11:56:19 +01:00
|
|
|
return project->hasBuildTarget(buildTarget);
|
2012-07-17 15:56:43 +02:00
|
|
|
}
|