2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-11-23 12:11:48 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-11-23 12:11:48 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-11-23 12:11:48 +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
|
|
|
|
|
** 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.
|
2009-11-23 12:11:48 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-11-23 12:11:48 +01:00
|
|
|
|
|
|
|
|
#include "cmakebuildconfiguration.h"
|
2010-01-07 18:17:24 +01:00
|
|
|
|
|
|
|
|
#include "cmakeopenprojectwizard.h"
|
2009-11-23 13:29:45 +01:00
|
|
|
#include "cmakeproject.h"
|
2012-10-02 17:46:19 +02:00
|
|
|
#include "cmakeprojectconstants.h"
|
2010-01-07 18:17:24 +01:00
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
#include <projectexplorer/buildsteplist.h>
|
2012-06-29 11:19:03 +02:00
|
|
|
#include <projectexplorer/gnumakeparser.h>
|
|
|
|
|
#include <projectexplorer/ioutputparser.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2012-06-29 11:19:03 +02:00
|
|
|
#include <qtsupport/baseqtversion.h>
|
|
|
|
|
#include <qtsupport/qtparser.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2010-01-07 18:17:24 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QInputDialog>
|
2009-11-23 12:11:48 +01:00
|
|
|
|
2009-11-23 13:29:45 +01:00
|
|
|
using namespace CMakeProjectManager;
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2010-01-18 12:11:04 +01:00
|
|
|
namespace {
|
2011-11-02 16:45:13 +01:00
|
|
|
const char BUILD_DIRECTORY_KEY[] = "CMakeProjectManager.CMakeBuildConfiguration.BuildDirectory";
|
2012-10-09 16:53:50 +02:00
|
|
|
const char USE_NINJA_KEY[] = "CMakeProjectManager.CMakeBuildConfiguration.UseNinja";
|
2010-02-08 15:50:06 +01:00
|
|
|
} // namespace
|
2010-01-18 12:11:04 +01:00
|
|
|
|
2012-07-18 12:02:35 +02:00
|
|
|
CMakeBuildConfiguration::CMakeBuildConfiguration(ProjectExplorer::Target *parent) :
|
2012-10-02 17:46:19 +02:00
|
|
|
BuildConfiguration(parent, Core::Id(Constants::CMAKE_BC_ID)), m_useNinja(false)
|
2009-11-23 12:11:48 +01:00
|
|
|
{
|
2012-07-18 12:02:35 +02:00
|
|
|
m_buildDirectory = static_cast<CMakeProject *>(parent->project())->defaultBuildDirectory();
|
2009-12-08 12:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
CMakeBuildConfiguration::CMakeBuildConfiguration(ProjectExplorer::Target *parent,
|
|
|
|
|
CMakeBuildConfiguration *source) :
|
2010-02-08 15:50:06 +01:00
|
|
|
BuildConfiguration(parent, source),
|
2009-12-08 12:21:11 +01:00
|
|
|
m_buildDirectory(source->m_buildDirectory),
|
2012-10-02 17:46:12 +02:00
|
|
|
m_msvcVersion(source->m_msvcVersion),
|
|
|
|
|
m_useNinja(false)
|
2009-12-08 12:21:11 +01:00
|
|
|
{
|
2010-07-16 14:00:41 +02:00
|
|
|
Q_ASSERT(parent);
|
2010-02-25 14:23:11 +01:00
|
|
|
cloneSteps(source);
|
2009-12-08 12:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-18 12:11:04 +01:00
|
|
|
QVariantMap CMakeBuildConfiguration::toMap() const
|
2009-12-08 12:21:11 +01:00
|
|
|
{
|
2010-01-18 12:11:04 +01:00
|
|
|
QVariantMap map(ProjectExplorer::BuildConfiguration::toMap());
|
|
|
|
|
map.insert(QLatin1String(BUILD_DIRECTORY_KEY), m_buildDirectory);
|
2012-10-09 16:53:50 +02:00
|
|
|
map.insert(QLatin1String(USE_NINJA_KEY), m_useNinja);
|
2010-01-18 12:11:04 +01:00
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeBuildConfiguration::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
2010-09-22 15:14:07 +02:00
|
|
|
if (!BuildConfiguration::fromMap(map))
|
|
|
|
|
return false;
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
m_buildDirectory = map.value(QLatin1String(BUILD_DIRECTORY_KEY)).toString();
|
2012-10-09 16:53:50 +02:00
|
|
|
m_useNinja = map.value(QLatin1String(USE_NINJA_KEY), false).toBool();
|
2010-01-18 12:11:04 +01:00
|
|
|
|
2010-09-22 15:14:07 +02:00
|
|
|
return true;
|
2009-11-23 12:11:48 +01:00
|
|
|
}
|
2009-11-23 13:29:45 +01:00
|
|
|
|
2012-10-02 17:46:12 +02:00
|
|
|
bool CMakeBuildConfiguration::useNinja() const
|
|
|
|
|
{
|
|
|
|
|
return m_useNinja;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildConfiguration::setUseNinja(bool useNninja)
|
|
|
|
|
{
|
|
|
|
|
if (m_useNinja != useNninja) {
|
|
|
|
|
m_useNinja = useNninja;
|
|
|
|
|
emit useNinjaChanged(m_useNinja);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-25 18:50:20 +01:00
|
|
|
CMakeBuildConfiguration::~CMakeBuildConfiguration()
|
2012-04-24 15:49:09 +02:00
|
|
|
{ }
|
2009-11-25 18:50:20 +01:00
|
|
|
|
2012-11-08 18:02:50 +01:00
|
|
|
ProjectExplorer::NamedWidget *CMakeBuildConfiguration::createConfigWidget()
|
2009-11-26 14:43:27 +01:00
|
|
|
{
|
2012-11-08 17:35:59 +01:00
|
|
|
return new CMakeBuildSettingsWidget(this);
|
2009-11-26 14:43:27 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-25 18:50:20 +01:00
|
|
|
QString CMakeBuildConfiguration::buildDirectory() const
|
|
|
|
|
{
|
2010-03-25 11:55:49 +01:00
|
|
|
return m_buildDirectory;
|
2009-11-25 18:50:20 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-03 19:45:09 +01:00
|
|
|
void CMakeBuildConfiguration::setBuildDirectory(const QString &buildDirectory)
|
|
|
|
|
{
|
2009-12-08 12:21:11 +01:00
|
|
|
if (m_buildDirectory == buildDirectory)
|
2009-12-03 19:45:09 +01:00
|
|
|
return;
|
2009-12-08 12:21:11 +01:00
|
|
|
m_buildDirectory = buildDirectory;
|
2009-12-03 19:45:09 +01:00
|
|
|
emit buildDirectoryChanged();
|
2010-09-22 15:14:07 +02:00
|
|
|
emit environmentChanged();
|
2009-12-03 19:45:09 +01:00
|
|
|
}
|
2009-11-25 18:50:20 +01:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
/*!
|
|
|
|
|
\class CMakeBuildConfigurationFactory
|
|
|
|
|
*/
|
|
|
|
|
|
2010-01-18 12:11:04 +01:00
|
|
|
CMakeBuildConfigurationFactory::CMakeBuildConfigurationFactory(QObject *parent) :
|
|
|
|
|
ProjectExplorer::IBuildConfigurationFactory(parent)
|
2010-01-07 18:17:24 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeBuildConfigurationFactory::~CMakeBuildConfigurationFactory()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QList<Core::Id> CMakeBuildConfigurationFactory::availableCreationIds(const ProjectExplorer::Target *parent) const
|
2010-01-07 18:17:24 +01:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!canHandle(parent))
|
2012-03-15 17:17:40 +01:00
|
|
|
return QList<Core::Id>();
|
2012-10-02 17:46:19 +02:00
|
|
|
return QList<Core::Id>() << Core::Id(Constants::CMAKE_BC_ID);
|
2010-01-07 18:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
2012-03-15 17:17:40 +01:00
|
|
|
QString CMakeBuildConfigurationFactory::displayNameForId(const Core::Id id) const
|
2010-01-07 18:17:24 +01:00
|
|
|
{
|
2012-10-02 17:46:19 +02:00
|
|
|
if (id == Constants::CMAKE_BC_ID)
|
2010-01-18 12:11:04 +01:00
|
|
|
return tr("Build");
|
|
|
|
|
return QString();
|
2010-01-07 18:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool CMakeBuildConfigurationFactory::canCreate(const ProjectExplorer::Target *parent, const Core::Id id) const
|
2010-01-07 18:17:24 +01:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!canHandle(parent))
|
2010-01-18 12:11:04 +01:00
|
|
|
return false;
|
2012-10-02 17:46:19 +02:00
|
|
|
if (id == Constants::CMAKE_BC_ID)
|
2010-01-18 12:11:04 +01:00
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
CMakeBuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer::Target *parent, const Core::Id id, const QString &name)
|
2010-01-18 12:11:04 +01:00
|
|
|
{
|
|
|
|
|
if (!canCreate(parent, id))
|
|
|
|
|
return 0;
|
|
|
|
|
|
2012-07-04 13:00:10 +02:00
|
|
|
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
|
2012-04-24 15:49:09 +02:00
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
QString buildConfigurationName = name;
|
|
|
|
|
if (buildConfigurationName.isEmpty())
|
|
|
|
|
buildConfigurationName = QInputDialog::getText(0,
|
|
|
|
|
tr("New Configuration"),
|
|
|
|
|
tr("New configuration name:"),
|
|
|
|
|
QLineEdit::Normal,
|
|
|
|
|
QString(), &ok);
|
|
|
|
|
buildConfigurationName = buildConfigurationName.trimmed();
|
2010-01-07 18:17:24 +01:00
|
|
|
if (!ok || buildConfigurationName.isEmpty())
|
2010-06-21 12:05:18 +02:00
|
|
|
return 0;
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2012-10-02 17:46:19 +02:00
|
|
|
CMakeOpenProjectWizard::BuildInfo info;
|
|
|
|
|
info.sourceDirectory = project->projectDirectory();
|
|
|
|
|
info.environment = Utils::Environment::systemEnvironment();
|
2012-10-18 12:53:45 +02:00
|
|
|
parent->kit()->addToEnvironment(info.environment);
|
2012-10-02 17:46:19 +02:00
|
|
|
info.buildDirectory = project->defaultBuildDirectory();
|
|
|
|
|
info.kit = parent->kit();
|
|
|
|
|
info.useNinja = false; // This is ignored anyway
|
|
|
|
|
|
|
|
|
|
CMakeOpenProjectWizard copw(project->projectManager(), CMakeOpenProjectWizard::ChangeDirectory, info);
|
|
|
|
|
if (copw.exec() != QDialog::Accepted)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2012-07-18 12:02:35 +02:00
|
|
|
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(parent);
|
2010-01-07 18:17:24 +01:00
|
|
|
bc->setDisplayName(buildConfigurationName);
|
|
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
ProjectExplorer::BuildStepList *buildSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
|
|
|
|
ProjectExplorer::BuildStepList *cleanSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
|
2010-01-07 18:17:24 +01:00
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
MakeStep *makeStep = new MakeStep(buildSteps);
|
|
|
|
|
buildSteps->insertStep(0, makeStep);
|
|
|
|
|
|
|
|
|
|
MakeStep *cleanMakeStep = new MakeStep(cleanSteps);
|
|
|
|
|
cleanSteps->insertStep(0, cleanMakeStep);
|
2010-10-19 11:14:03 +02:00
|
|
|
cleanMakeStep->setAdditionalArguments("clean");
|
2010-01-07 18:17:24 +01:00
|
|
|
cleanMakeStep->setClean(true);
|
|
|
|
|
|
|
|
|
|
bc->setBuildDirectory(copw.buildDirectory());
|
2012-10-02 17:46:19 +02:00
|
|
|
bc->setUseNinja(copw.useNinja());
|
2010-01-07 18:17:24 +01:00
|
|
|
|
|
|
|
|
// Default to all
|
2012-04-24 15:49:09 +02:00
|
|
|
if (project->hasBuildTarget("all"))
|
2010-01-07 18:17:24 +01:00
|
|
|
makeStep->setBuildTarget("all", true);
|
2010-01-18 12:11:04 +01:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
return bc;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool CMakeBuildConfigurationFactory::canClone(const ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source) const
|
2010-01-18 12:11:04 +01:00
|
|
|
{
|
|
|
|
|
return canCreate(parent, source->id());
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
CMakeBuildConfiguration *CMakeBuildConfigurationFactory::clone(ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source)
|
2010-01-07 18:17:24 +01:00
|
|
|
{
|
2010-01-18 12:11:04 +01:00
|
|
|
if (!canClone(parent, source))
|
|
|
|
|
return 0;
|
2010-01-07 18:17:24 +01:00
|
|
|
CMakeBuildConfiguration *old = static_cast<CMakeBuildConfiguration *>(source);
|
2012-04-24 15:49:09 +02:00
|
|
|
return new CMakeBuildConfiguration(parent, old);
|
2010-01-07 18:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool CMakeBuildConfigurationFactory::canRestore(const ProjectExplorer::Target *parent, const QVariantMap &map) const
|
2010-01-07 18:17:24 +01:00
|
|
|
{
|
2012-03-15 17:17:40 +01:00
|
|
|
return canCreate(parent, ProjectExplorer::idFromMap(map));
|
2010-01-18 12:11:04 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
CMakeBuildConfiguration *CMakeBuildConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
|
2010-01-18 12:11:04 +01:00
|
|
|
{
|
|
|
|
|
if (!canRestore(parent, map))
|
|
|
|
|
return 0;
|
2012-04-24 15:49:09 +02:00
|
|
|
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(parent);
|
2010-01-18 12:11:04 +01:00
|
|
|
if (bc->fromMap(map))
|
|
|
|
|
return bc;
|
|
|
|
|
delete bc;
|
|
|
|
|
return 0;
|
2010-01-07 18:17:24 +01:00
|
|
|
}
|
2011-03-03 16:12:00 +01:00
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool CMakeBuildConfigurationFactory::canHandle(const ProjectExplorer::Target *t) const
|
|
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
if (!t->project()->supportsKit(t->kit()))
|
2012-04-24 15:49:09 +02:00
|
|
|
return false;
|
|
|
|
|
return qobject_cast<CMakeProject *>(t->project());
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-03 16:12:00 +01:00
|
|
|
ProjectExplorer::BuildConfiguration::BuildType CMakeBuildConfiguration::buildType() const
|
|
|
|
|
{
|
|
|
|
|
QString cmakeBuildType;
|
|
|
|
|
QFile cmakeCache(buildDirectory() + "/CMakeCache.txt");
|
|
|
|
|
if (cmakeCache.open(QIODevice::ReadOnly)) {
|
|
|
|
|
while (!cmakeCache.atEnd()) {
|
|
|
|
|
QString line = cmakeCache.readLine();
|
|
|
|
|
if (line.startsWith("CMAKE_BUILD_TYPE")) {
|
|
|
|
|
if (int pos = line.indexOf('=')) {
|
|
|
|
|
cmakeBuildType = line.mid(pos + 1).trimmed();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cmakeCache.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cover all common CMake build types
|
|
|
|
|
if (cmakeBuildType.compare("Release", Qt::CaseInsensitive) == 0
|
|
|
|
|
|| cmakeBuildType.compare("MinSizeRel", Qt::CaseInsensitive) == 0)
|
|
|
|
|
{
|
|
|
|
|
return Release;
|
|
|
|
|
} else if (cmakeBuildType.compare("Debug", Qt::CaseInsensitive) == 0
|
|
|
|
|
|| cmakeBuildType.compare("debugfull", Qt::CaseInsensitive) == 0
|
|
|
|
|
|| cmakeBuildType.compare("RelWithDebInfo", Qt::CaseInsensitive) == 0)
|
|
|
|
|
{
|
|
|
|
|
return Debug;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Unknown;
|
|
|
|
|
}
|
2012-10-02 17:46:12 +02:00
|
|
|
|