2009-11-23 12:11:48 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2009 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 "cmakebuildconfiguration.h"
|
2010-01-07 18:17:24 +01:00
|
|
|
|
|
|
|
|
#include "cmakeopenprojectwizard.h"
|
2009-11-23 13:29:45 +01:00
|
|
|
#include "cmakeproject.h"
|
2010-02-08 15:50:06 +01:00
|
|
|
#include "cmaketarget.h"
|
2010-01-07 18:17:24 +01:00
|
|
|
|
2009-11-25 18:50:20 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2010-01-07 18:17:24 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/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 {
|
|
|
|
|
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");
|
2010-02-08 15:50:06 +01:00
|
|
|
} // namespace
|
2010-01-18 12:11:04 +01:00
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeTarget *parent) :
|
|
|
|
|
BuildConfiguration(parent, QLatin1String(CMAKE_BC_ID)),
|
2010-01-18 12:11:04 +01:00
|
|
|
m_toolChain(0),
|
|
|
|
|
m_clearSystemEnvironment(false)
|
2009-11-23 12:11:48 +01:00
|
|
|
{
|
2009-12-08 12:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeTarget *parent, CMakeBuildConfiguration *source) :
|
|
|
|
|
BuildConfiguration(parent, source),
|
2009-12-08 12:21:11 +01:00
|
|
|
m_toolChain(0),
|
|
|
|
|
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
|
|
|
|
|
m_userEnvironmentChanges(source->m_userEnvironmentChanges),
|
|
|
|
|
m_buildDirectory(source->m_buildDirectory),
|
|
|
|
|
m_msvcVersion(source->m_msvcVersion)
|
|
|
|
|
{
|
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(USER_ENVIRONMENT_CHANGES_KEY),
|
2009-12-08 12:21:11 +01:00
|
|
|
ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges));
|
2010-01-18 12:11:04 +01:00
|
|
|
map.insert(QLatin1String(MSVC_VERSION_KEY), m_msvcVersion);
|
|
|
|
|
map.insert(QLatin1String(BUILD_DIRECTORY_KEY), m_buildDirectory);
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeBuildConfiguration::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
|
|
|
|
|
m_msvcVersion = map.value(QLatin1String(MSVC_VERSION_KEY)).toString();
|
|
|
|
|
m_buildDirectory = map.value(QLatin1String(BUILD_DIRECTORY_KEY)).toString();
|
|
|
|
|
|
|
|
|
|
return BuildConfiguration::fromMap(map);
|
2009-11-23 12:11:48 +01:00
|
|
|
}
|
2009-11-23 13:29:45 +01:00
|
|
|
|
2009-11-25 18:50:20 +01:00
|
|
|
CMakeBuildConfiguration::~CMakeBuildConfiguration()
|
|
|
|
|
{
|
|
|
|
|
delete m_toolChain;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
CMakeTarget *CMakeBuildConfiguration::cmakeTarget() const
|
2009-11-26 14:43:27 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
return static_cast<CMakeTarget *>(target());
|
2009-11-26 14:43:27 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-25 18:50:20 +01:00
|
|
|
ProjectExplorer::Environment CMakeBuildConfiguration::baseEnvironment() const
|
|
|
|
|
{
|
|
|
|
|
ProjectExplorer::Environment env = useSystemEnvironment() ?
|
|
|
|
|
ProjectExplorer::Environment(QProcess::systemEnvironment()) :
|
|
|
|
|
ProjectExplorer::Environment();
|
|
|
|
|
return env;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-14 13:40:17 +01:00
|
|
|
QString CMakeBuildConfiguration::baseEnvironmentText() const
|
|
|
|
|
{
|
|
|
|
|
if (useSystemEnvironment())
|
|
|
|
|
return tr("System Environment");
|
|
|
|
|
else
|
|
|
|
|
return tr("Clear Environment");
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-25 18:50:20 +01:00
|
|
|
ProjectExplorer::Environment CMakeBuildConfiguration::environment() const
|
|
|
|
|
{
|
|
|
|
|
ProjectExplorer::Environment env = baseEnvironment();
|
|
|
|
|
env.modify(userEnvironmentChanges());
|
|
|
|
|
return env;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildConfiguration::setUseSystemEnvironment(bool b)
|
|
|
|
|
{
|
2009-12-08 12:21:11 +01:00
|
|
|
if (b == m_clearSystemEnvironment)
|
2009-11-25 18:50:20 +01:00
|
|
|
return;
|
2009-12-08 12:21:11 +01:00
|
|
|
m_clearSystemEnvironment = !b;
|
2009-11-25 18:50:20 +01:00
|
|
|
emit environmentChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeBuildConfiguration::useSystemEnvironment() const
|
|
|
|
|
{
|
2009-12-08 12:21:11 +01:00
|
|
|
return !m_clearSystemEnvironment;
|
2009-11-25 18:50:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ProjectExplorer::EnvironmentItem> CMakeBuildConfiguration::userEnvironmentChanges() const
|
|
|
|
|
{
|
2009-12-08 12:21:11 +01:00
|
|
|
return m_userEnvironmentChanges;
|
2009-11-25 18:50:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildConfiguration::setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff)
|
|
|
|
|
{
|
2009-12-08 12:21:11 +01:00
|
|
|
if (m_userEnvironmentChanges == diff)
|
2009-11-25 18:50:20 +01:00
|
|
|
return;
|
2009-12-08 12:21:11 +01:00
|
|
|
m_userEnvironmentChanges = diff;
|
2009-11-25 18:50:20 +01:00
|
|
|
emit environmentChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeBuildConfiguration::buildDirectory() const
|
|
|
|
|
{
|
2009-12-08 12:21:11 +01:00
|
|
|
QString buildDirectory = m_buildDirectory;
|
2009-11-25 18:50:20 +01:00
|
|
|
if (buildDirectory.isEmpty())
|
2010-02-08 15:50:06 +01:00
|
|
|
buildDirectory = cmakeTarget()->cmakeProject()->sourceDirectory() + "/qtcreator-build";
|
2009-11-25 18:50:20 +01:00
|
|
|
return buildDirectory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::ToolChain::ToolChainType CMakeBuildConfiguration::toolChainType() const
|
|
|
|
|
{
|
|
|
|
|
if (m_toolChain)
|
|
|
|
|
return m_toolChain->type();
|
|
|
|
|
return ProjectExplorer::ToolChain::UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::ToolChain *CMakeBuildConfiguration::toolChain() const
|
|
|
|
|
{
|
2009-12-03 19:45:09 +01:00
|
|
|
updateToolChain();
|
2009-11-25 18:50:20 +01:00
|
|
|
return m_toolChain;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-03 19:45:09 +01:00
|
|
|
void CMakeBuildConfiguration::updateToolChain() const
|
2009-11-25 18:50:20 +01:00
|
|
|
{
|
|
|
|
|
ProjectExplorer::ToolChain *newToolChain = 0;
|
2009-12-03 19:45:09 +01:00
|
|
|
if (msvcVersion().isEmpty()) {
|
2009-11-25 18:50:20 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
newToolChain = ProjectExplorer::ToolChain::createMinGWToolChain("gcc", QString());
|
|
|
|
|
#else
|
|
|
|
|
newToolChain = ProjectExplorer::ToolChain::createGccToolChain("gcc");
|
|
|
|
|
#endif
|
2009-12-03 19:45:09 +01:00
|
|
|
} else { // msvc
|
2009-12-08 12:21:11 +01:00
|
|
|
newToolChain = ProjectExplorer::ToolChain::createMSVCToolChain(m_msvcVersion, false);
|
2009-11-25 18:50:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ProjectExplorer::ToolChain::equals(newToolChain, m_toolChain)) {
|
|
|
|
|
delete newToolChain;
|
|
|
|
|
newToolChain = 0;
|
|
|
|
|
} else {
|
|
|
|
|
delete m_toolChain;
|
|
|
|
|
m_toolChain = newToolChain;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2009-11-25 18:50:20 +01:00
|
|
|
|
2009-12-03 19:45:09 +01:00
|
|
|
QString CMakeBuildConfiguration::msvcVersion() const
|
|
|
|
|
{
|
2009-12-08 12:21:11 +01:00
|
|
|
return m_msvcVersion;
|
2009-12-03 19:45:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildConfiguration::setMsvcVersion(const QString &msvcVersion)
|
|
|
|
|
{
|
2009-12-08 12:21:11 +01:00
|
|
|
if (m_msvcVersion == msvcVersion)
|
2009-12-03 19:45:09 +01:00
|
|
|
return;
|
2009-12-08 12:21:11 +01:00
|
|
|
m_msvcVersion = msvcVersion;
|
2009-12-03 19:45:09 +01:00
|
|
|
updateToolChain();
|
|
|
|
|
|
|
|
|
|
emit msvcVersionChanged();
|
|
|
|
|
}
|
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()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
QStringList CMakeBuildConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
|
2010-01-07 18:17:24 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
if (!qobject_cast<CMakeTarget *>(parent))
|
2010-01-18 12:11:04 +01:00
|
|
|
return QStringList();
|
|
|
|
|
return QStringList() << QLatin1String(CMAKE_BC_ID);
|
2010-01-07 18:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeBuildConfigurationFactory::displayNameForId(const QString &id) const
|
|
|
|
|
{
|
2010-01-18 12:11:04 +01:00
|
|
|
if (id == QLatin1String(CMAKE_BC_ID))
|
|
|
|
|
return tr("Build");
|
|
|
|
|
return QString();
|
2010-01-07 18:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
bool CMakeBuildConfigurationFactory::canCreate(ProjectExplorer::Target *parent, const QString &id) const
|
2010-01-07 18:17:24 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
if (!qobject_cast<CMakeTarget *>(parent))
|
2010-01-18 12:11:04 +01:00
|
|
|
return false;
|
|
|
|
|
if (id == QLatin1String(CMAKE_BC_ID))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
CMakeBuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer::Target *parent, const QString &id)
|
2010-01-18 12:11:04 +01:00
|
|
|
{
|
|
|
|
|
if (!canCreate(parent, id))
|
|
|
|
|
return 0;
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
CMakeTarget *cmtarget = static_cast<CMakeTarget *>(parent);
|
|
|
|
|
Q_ASSERT(cmtarget);
|
2010-01-07 18:17:24 +01:00
|
|
|
|
|
|
|
|
//TODO configuration name should be part of the cmakeopenprojectwizard
|
|
|
|
|
bool ok;
|
|
|
|
|
QString buildConfigurationName = QInputDialog::getText(0,
|
|
|
|
|
tr("New configuration"),
|
|
|
|
|
tr("New Configuration Name:"),
|
|
|
|
|
QLineEdit::Normal,
|
|
|
|
|
QString(),
|
|
|
|
|
&ok);
|
|
|
|
|
if (!ok || buildConfigurationName.isEmpty())
|
|
|
|
|
return false;
|
2010-02-08 15:50:06 +01:00
|
|
|
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(cmtarget);
|
2010-01-07 18:17:24 +01:00
|
|
|
bc->setDisplayName(buildConfigurationName);
|
|
|
|
|
|
|
|
|
|
MakeStep *makeStep = new MakeStep(bc);
|
|
|
|
|
bc->insertBuildStep(0, makeStep);
|
|
|
|
|
|
|
|
|
|
MakeStep *cleanMakeStep = new MakeStep(bc);
|
|
|
|
|
bc->insertCleanStep(0, cleanMakeStep);
|
2010-01-08 13:54:18 +01:00
|
|
|
cleanMakeStep->setAdditionalArguments(QStringList() << "clean");
|
2010-01-07 18:17:24 +01:00
|
|
|
cleanMakeStep->setClean(true);
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
CMakeOpenProjectWizard copw(cmtarget->cmakeProject()->projectManager(),
|
|
|
|
|
cmtarget->cmakeProject()->sourceDirectory(),
|
2010-01-07 18:17:24 +01:00
|
|
|
bc->buildDirectory(),
|
|
|
|
|
bc->environment());
|
|
|
|
|
if (copw.exec() != QDialog::Accepted) {
|
|
|
|
|
delete bc;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-02-08 15:50:06 +01:00
|
|
|
cmtarget->addBuildConfiguration(bc); // this also makes the name unique
|
2010-01-07 18:17:24 +01:00
|
|
|
|
|
|
|
|
bc->setBuildDirectory(copw.buildDirectory());
|
|
|
|
|
bc->setMsvcVersion(copw.msvcVersion());
|
2010-02-08 15:50:06 +01:00
|
|
|
cmtarget->cmakeProject()->parseCMakeLists();
|
2010-01-07 18:17:24 +01:00
|
|
|
|
|
|
|
|
// Default to all
|
2010-02-08 15:50:06 +01:00
|
|
|
if (cmtarget->cmakeProject()->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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
bool CMakeBuildConfigurationFactory::canClone(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);
|
2010-02-08 15:50:06 +01:00
|
|
|
CMakeTarget *cmtarget(static_cast<CMakeTarget *>(parent));
|
|
|
|
|
return new CMakeBuildConfiguration(cmtarget, old);
|
2010-01-07 18:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
bool CMakeBuildConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
|
2010-01-07 18:17:24 +01:00
|
|
|
{
|
2010-01-18 12:11:04 +01:00
|
|
|
QString id(ProjectExplorer::idFromMap(map));
|
|
|
|
|
return canCreate(parent, id);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2010-02-08 15:50:06 +01:00
|
|
|
CMakeTarget *cmtarget(static_cast<CMakeTarget *>(parent));
|
|
|
|
|
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(cmtarget);
|
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
|
|
|
}
|