2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-11-23 12:11:48 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
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.
|
2009-11-23 12:11:48 +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
|
|
|
****************************************************************************/
|
2009-11-23 12:11:48 +01:00
|
|
|
|
|
|
|
|
#include "cmakebuildconfiguration.h"
|
2010-01-07 18:17:24 +01:00
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
#include "builddirmanager.h"
|
2013-07-22 15:53:57 +02:00
|
|
|
#include "cmakebuildinfo.h"
|
2016-01-07 12:33:52 +01:00
|
|
|
#include "cmakebuildstep.h"
|
2016-02-03 13:52:50 +01:00
|
|
|
#include "cmakekitinformation.h"
|
2009-11-23 13:29:45 +01:00
|
|
|
#include "cmakeproject.h"
|
2012-10-02 17:46:19 +02:00
|
|
|
#include "cmakeprojectconstants.h"
|
2015-03-10 10:22:38 +01:00
|
|
|
#include "cmakebuildsettingswidget.h"
|
2015-03-10 14:24:14 +01:00
|
|
|
#include "cmakeprojectmanager.h"
|
2010-01-07 18:17:24 +01:00
|
|
|
|
2014-10-22 09:16:55 +02:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2013-07-22 15:53:57 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2014-10-22 09:16:55 +02:00
|
|
|
|
2010-07-16 14:00:41 +02:00
|
|
|
#include <projectexplorer/buildsteplist.h>
|
2013-04-10 12:02:06 +02:00
|
|
|
#include <projectexplorer/kit.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2014-10-22 09:16:55 +02:00
|
|
|
#include <projectexplorer/projectmacroexpander.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2010-01-07 18:17:24 +01:00
|
|
|
|
2016-02-03 13:52:50 +01:00
|
|
|
#include <utils/algorithm.h>
|
2015-02-04 09:32:46 +01:00
|
|
|
#include <utils/mimetypes/mimedatabase.h>
|
2013-07-22 15:53:57 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2016-02-03 13:52:50 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2013-07-22 15:53:57 +02:00
|
|
|
|
2016-02-03 13:52:50 +01:00
|
|
|
#include <QHash>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QInputDialog>
|
2009-11-23 12:11:48 +01:00
|
|
|
|
2014-10-22 09:16:55 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace CMakeProjectManager {
|
|
|
|
|
namespace Internal {
|
2009-11-23 13:29:45 +01:00
|
|
|
|
2016-02-03 13:52:50 +01:00
|
|
|
const char INITIAL_ARGUMENTS[] = "CMakeProjectManager.CMakeBuildConfiguration.InitialArgument"; // Obsolete since QtC 3.7
|
|
|
|
|
const char CONFIGURATION_KEY[] = "CMake.Configuration";
|
2014-10-22 09:16:55 +02:00
|
|
|
|
2015-10-22 17:26:33 +02:00
|
|
|
static FileName shadowBuildDirectory(const FileName &projectFilePath, const Kit *k,
|
|
|
|
|
const QString &bcName, BuildConfiguration::BuildType buildType)
|
2014-10-22 09:16:55 +02:00
|
|
|
{
|
|
|
|
|
if (projectFilePath.isEmpty())
|
2015-01-31 21:05:34 +02:00
|
|
|
return FileName();
|
2014-10-22 09:16:55 +02:00
|
|
|
|
2015-03-09 11:54:57 +01:00
|
|
|
const QString projectName = projectFilePath.parentDir().fileName();
|
2015-10-22 17:26:33 +02:00
|
|
|
ProjectMacroExpander expander(projectName, k, bcName, buildType);
|
2015-01-31 21:05:34 +02:00
|
|
|
QDir projectDir = QDir(Project::projectDirectory(projectFilePath).toString());
|
2014-10-22 09:16:55 +02:00
|
|
|
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory());
|
2015-01-31 21:05:34 +02:00
|
|
|
return FileName::fromUserInput(projectDir.absoluteFilePath(buildPath));
|
2014-10-22 09:16:55 +02:00
|
|
|
}
|
2010-01-18 12:11:04 +01:00
|
|
|
|
2012-07-18 12:02:35 +02:00
|
|
|
CMakeBuildConfiguration::CMakeBuildConfiguration(ProjectExplorer::Target *parent) :
|
2016-01-07 13:19:29 +01:00
|
|
|
BuildConfiguration(parent, Core::Id(Constants::CMAKE_BC_ID))
|
2009-11-23 12:11:48 +01:00
|
|
|
{
|
2016-02-24 18:00:24 +01:00
|
|
|
auto project = static_cast<CMakeProject *>(parent->project());
|
2015-01-31 21:05:34 +02:00
|
|
|
setBuildDirectory(shadowBuildDirectory(project->projectFilePath(),
|
|
|
|
|
parent->kit(),
|
2015-10-22 17:26:33 +02:00
|
|
|
displayName(), BuildConfiguration::Unknown));
|
2016-02-24 18:00:24 +01:00
|
|
|
|
|
|
|
|
m_buildDirManager = new BuildDirManager(this);
|
|
|
|
|
connect(m_buildDirManager, &BuildDirManager::dataAvailable,
|
|
|
|
|
this, &CMakeBuildConfiguration::dataAvailable);
|
|
|
|
|
connect(m_buildDirManager, &BuildDirManager::errorOccured,
|
|
|
|
|
this, &CMakeBuildConfiguration::setError);
|
|
|
|
|
connect(m_buildDirManager, &BuildDirManager::configurationStarted,
|
|
|
|
|
this, [this]() { m_completeConfigurationCache.clear(); emit parsingStarted(); });
|
|
|
|
|
|
|
|
|
|
connect(this, &CMakeBuildConfiguration::environmentChanged,
|
|
|
|
|
m_buildDirManager, &BuildDirManager::forceReparse);
|
|
|
|
|
connect(this, &CMakeBuildConfiguration::buildDirectoryChanged,
|
2016-02-25 14:18:05 +01:00
|
|
|
m_buildDirManager, &BuildDirManager::forceReparse);
|
2016-02-24 18:00:24 +01:00
|
|
|
connect(target(), &Target::kitChanged, m_buildDirManager, &BuildDirManager::forceReparse);
|
|
|
|
|
|
|
|
|
|
connect(this, &CMakeBuildConfiguration::parsingStarted, project, &CMakeProject::handleParsingStarted);
|
|
|
|
|
connect(this, &CMakeBuildConfiguration::dataAvailable, project, &CMakeProject::parseCMakeOutput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeBuildConfiguration::~CMakeBuildConfiguration()
|
|
|
|
|
{
|
|
|
|
|
m_buildDirManager->deleteLater(); // Do not block while waiting for cmake...
|
2009-12-08 12:21:11 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-11 16:33:15 +01:00
|
|
|
bool CMakeBuildConfiguration::isEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return m_error.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeBuildConfiguration::disabledReason() const
|
|
|
|
|
{
|
|
|
|
|
return error();
|
|
|
|
|
}
|
|
|
|
|
|
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),
|
2016-02-03 13:52:50 +01:00
|
|
|
m_configuration(source->m_configuration)
|
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());
|
2016-02-03 13:52:50 +01:00
|
|
|
const QStringList config
|
|
|
|
|
= Utils::transform(m_configuration, [](const CMakeConfigItem &i) { return i.toString(); });
|
|
|
|
|
map.insert(QLatin1String(CONFIGURATION_KEY), config);
|
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;
|
|
|
|
|
|
2016-02-03 13:52:50 +01:00
|
|
|
const CMakeConfig conf
|
|
|
|
|
= Utils::transform(map.value(QLatin1String(CONFIGURATION_KEY)).toStringList(),
|
|
|
|
|
[](const QString &v) { return CMakeConfigItem::fromString(v); });
|
|
|
|
|
|
|
|
|
|
// Legacy (pre QtC 3.7):
|
|
|
|
|
const QStringList args = QtcProcess::splitArgs(map.value(QLatin1String(INITIAL_ARGUMENTS)).toString());
|
|
|
|
|
CMakeConfig legacyConf;
|
|
|
|
|
bool nextIsConfig = false;
|
|
|
|
|
foreach (const QString &a, args) {
|
|
|
|
|
if (a == QLatin1String("-D")) {
|
|
|
|
|
nextIsConfig = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!a.startsWith(QLatin1String("-D")))
|
|
|
|
|
continue;
|
|
|
|
|
legacyConf << CMakeConfigItem::fromString(nextIsConfig ? a : a.mid(2));
|
|
|
|
|
nextIsConfig = false;
|
|
|
|
|
}
|
|
|
|
|
// End Legacy
|
|
|
|
|
|
|
|
|
|
setCMakeConfiguration(legacyConf + conf);
|
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
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
BuildDirManager *CMakeBuildConfiguration::buildDirManager() const
|
|
|
|
|
{
|
|
|
|
|
return m_buildDirManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeBuildConfiguration::isParsing() const
|
|
|
|
|
{
|
|
|
|
|
return m_buildDirManager && m_buildDirManager->isParsing();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildConfiguration::parse()
|
|
|
|
|
{
|
|
|
|
|
m_buildDirManager->parse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildConfiguration::resetData()
|
|
|
|
|
{
|
|
|
|
|
m_buildDirManager->resetData();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-25 14:18:05 +01:00
|
|
|
bool CMakeBuildConfiguration::persistCMakeState()
|
|
|
|
|
{
|
|
|
|
|
return m_buildDirManager->persistCMakeState();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
QList<ConfigModel::DataItem> CMakeBuildConfiguration::completeCMakeConfiguration() const
|
|
|
|
|
{
|
|
|
|
|
if (m_buildDirManager->isParsing())
|
|
|
|
|
return QList<ConfigModel::DataItem>();
|
|
|
|
|
|
|
|
|
|
if (m_completeConfigurationCache.isEmpty())
|
|
|
|
|
m_completeConfigurationCache = m_buildDirManager->configuration();
|
|
|
|
|
|
|
|
|
|
return Utils::transform(m_completeConfigurationCache, [](const CMakeConfigItem &i) {
|
|
|
|
|
ConfigModel::DataItem j;
|
|
|
|
|
j.key = QString::fromUtf8(i.key);
|
|
|
|
|
j.value = QString::fromUtf8(i.value);
|
|
|
|
|
j.description = QString::fromUtf8(i.documentation);
|
|
|
|
|
|
|
|
|
|
j.isAdvanced = i.isAdvanced;
|
|
|
|
|
switch (i.type) {
|
|
|
|
|
case CMakeConfigItem::FILEPATH:
|
|
|
|
|
j.type = ConfigModel::DataItem::FILE;
|
|
|
|
|
break;
|
|
|
|
|
case CMakeConfigItem::PATH:
|
|
|
|
|
j.type = ConfigModel::DataItem::DIRECTORY;
|
|
|
|
|
break;
|
|
|
|
|
case CMakeConfigItem::BOOL:
|
|
|
|
|
j.type = ConfigModel::DataItem::BOOLEAN;
|
|
|
|
|
break;
|
|
|
|
|
case CMakeConfigItem::STRING:
|
|
|
|
|
j.type = ConfigModel::DataItem::STRING;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
j.type = ConfigModel::DataItem::UNKNOWN;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return j;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildConfiguration::setCurrentCMakeConfiguration(const QList<ConfigModel::DataItem> &items)
|
|
|
|
|
{
|
|
|
|
|
if (m_buildDirManager->isParsing())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const CMakeConfig newConfig = Utils::transform(items, [](const ConfigModel::DataItem &i) {
|
|
|
|
|
CMakeConfigItem ni;
|
|
|
|
|
ni.key = i.key.toUtf8();
|
|
|
|
|
ni.value = i.value.toUtf8();
|
|
|
|
|
ni.documentation = i.description.toUtf8();
|
|
|
|
|
ni.isAdvanced = i.isAdvanced;
|
|
|
|
|
switch (i.type) {
|
|
|
|
|
case CMakeProjectManager::ConfigModel::DataItem::BOOLEAN:
|
|
|
|
|
ni.type = CMakeConfigItem::BOOL;
|
|
|
|
|
break;
|
|
|
|
|
case CMakeProjectManager::ConfigModel::DataItem::FILE:
|
|
|
|
|
ni.type = CMakeConfigItem::FILEPATH;
|
|
|
|
|
break;
|
|
|
|
|
case CMakeProjectManager::ConfigModel::DataItem::DIRECTORY:
|
|
|
|
|
ni.type = CMakeConfigItem::PATH;
|
|
|
|
|
break;
|
|
|
|
|
case CMakeProjectManager::ConfigModel::DataItem::STRING:
|
|
|
|
|
ni.type = CMakeConfigItem::STRING;
|
|
|
|
|
break;
|
|
|
|
|
case CMakeProjectManager::ConfigModel::DataItem::UNKNOWN:
|
|
|
|
|
default:
|
|
|
|
|
ni.type = CMakeConfigItem::INTERNAL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ni;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// There is a buildDirManager, so there must also be an active BC:
|
|
|
|
|
const CMakeConfig config = cmakeConfiguration() + newConfig;
|
|
|
|
|
setCMakeConfiguration(config);
|
|
|
|
|
|
|
|
|
|
m_buildDirManager->forceReparse();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 15:29:11 +02:00
|
|
|
void CMakeBuildConfiguration::emitBuildTypeChanged()
|
|
|
|
|
{
|
|
|
|
|
emit buildTypeChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-03 13:52:50 +01:00
|
|
|
static CMakeConfig removeDuplicates(const CMakeConfig &config)
|
|
|
|
|
{
|
|
|
|
|
CMakeConfig result;
|
|
|
|
|
// Remove duplicates (last value wins):
|
|
|
|
|
QSet<QByteArray> knownKeys;
|
|
|
|
|
for (int i = config.count() - 1; i >= 0; --i) {
|
|
|
|
|
const CMakeConfigItem &item = config.at(i);
|
|
|
|
|
if (knownKeys.contains(item.key))
|
|
|
|
|
continue;
|
|
|
|
|
result.append(item);
|
|
|
|
|
knownKeys.insert(item.key);
|
|
|
|
|
}
|
|
|
|
|
Utils::sort(result, CMakeConfigItem::sortOperator());
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildConfiguration::setCMakeConfiguration(const CMakeConfig &config)
|
2015-09-10 16:17:38 +02:00
|
|
|
{
|
2016-02-03 13:52:50 +01:00
|
|
|
m_configuration = removeDuplicates(config);
|
2015-09-10 16:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-03 13:52:50 +01:00
|
|
|
CMakeConfig CMakeBuildConfiguration::cmakeConfiguration() const
|
2015-09-10 16:17:38 +02:00
|
|
|
{
|
2016-02-03 13:52:50 +01:00
|
|
|
return m_configuration;
|
2015-09-10 16:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-11 16:33:15 +01:00
|
|
|
void CMakeBuildConfiguration::setError(const QString &message)
|
|
|
|
|
{
|
|
|
|
|
if (m_error == message)
|
|
|
|
|
return;
|
|
|
|
|
m_error = message;
|
|
|
|
|
emit enabledChanged();
|
|
|
|
|
emit errorOccured(m_error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeBuildConfiguration::error() const
|
|
|
|
|
{
|
|
|
|
|
return m_error;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
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)
|
2016-02-03 13:52:50 +01:00
|
|
|
{ }
|
2010-01-07 18:17:24 +01:00
|
|
|
|
2013-07-24 12:42:24 +02:00
|
|
|
int CMakeBuildConfigurationFactory::priority(const ProjectExplorer::Target *parent) const
|
2010-01-07 18:17:24 +01:00
|
|
|
{
|
2013-07-24 12:42:24 +02:00
|
|
|
return canHandle(parent) ? 0 : -1;
|
2010-01-07 18:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
2013-07-22 15:53:57 +02:00
|
|
|
QList<ProjectExplorer::BuildInfo *> CMakeBuildConfigurationFactory::availableBuilds(const ProjectExplorer::Target *parent) const
|
2010-01-07 18:17:24 +01:00
|
|
|
{
|
2013-07-22 15:53:57 +02:00
|
|
|
QList<ProjectExplorer::BuildInfo *> result;
|
2010-01-07 18:17:24 +01:00
|
|
|
|
2015-09-10 16:17:38 +02:00
|
|
|
for (int type = BuildTypeNone; type != BuildTypeLast; ++type) {
|
|
|
|
|
CMakeBuildInfo *info = createBuildInfo(parent->kit(),
|
|
|
|
|
parent->project()->projectDirectory().toString(),
|
|
|
|
|
BuildType(type));
|
|
|
|
|
result << info;
|
|
|
|
|
}
|
2013-08-13 10:52:57 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-24 12:42:24 +02:00
|
|
|
int CMakeBuildConfigurationFactory::priority(const ProjectExplorer::Kit *k, const QString &projectPath) const
|
2013-08-13 10:52:57 +02:00
|
|
|
{
|
2015-02-04 09:32:46 +01:00
|
|
|
Utils::MimeDatabase mdb;
|
|
|
|
|
if (k && mdb.mimeTypeForFile(projectPath).matchesName(QLatin1String(Constants::CMAKEPROJECTMIMETYPE)))
|
|
|
|
|
return 0;
|
|
|
|
|
return -1;
|
2013-08-13 10:52:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ProjectExplorer::BuildInfo *> CMakeBuildConfigurationFactory::availableSetups(const ProjectExplorer::Kit *k,
|
|
|
|
|
const QString &projectPath) const
|
|
|
|
|
{
|
|
|
|
|
QList<ProjectExplorer::BuildInfo *> result;
|
2015-01-31 21:05:34 +02:00
|
|
|
const FileName projectPathName = FileName::fromString(projectPath);
|
2015-09-10 16:17:38 +02:00
|
|
|
for (int type = BuildTypeNone; type != BuildTypeLast; ++type) {
|
|
|
|
|
CMakeBuildInfo *info = createBuildInfo(k,
|
|
|
|
|
ProjectExplorer::Project::projectDirectory(projectPathName).toString(),
|
|
|
|
|
BuildType(type));
|
|
|
|
|
if (type == BuildTypeNone) {
|
|
|
|
|
//: The name of the build configuration created by default for a cmake project.
|
|
|
|
|
info->displayName = tr("Default");
|
|
|
|
|
} else {
|
|
|
|
|
info->displayName = info->typeName;
|
|
|
|
|
}
|
2015-10-22 17:26:33 +02:00
|
|
|
info->buildDirectory
|
|
|
|
|
= shadowBuildDirectory(projectPathName, k, info->displayName, info->buildType);
|
2015-09-10 16:17:38 +02:00
|
|
|
result << info;
|
|
|
|
|
}
|
2013-07-22 15:53:57 +02:00
|
|
|
return result;
|
2010-01-18 12:11:04 +01:00
|
|
|
}
|
|
|
|
|
|
2013-07-22 15:53:57 +02:00
|
|
|
ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer::Target *parent,
|
|
|
|
|
const ProjectExplorer::BuildInfo *info) const
|
2010-01-18 12:11:04 +01:00
|
|
|
{
|
2013-07-22 15:53:57 +02:00
|
|
|
QTC_ASSERT(info->factory() == this, return 0);
|
|
|
|
|
QTC_ASSERT(info->kitId == parent->kit()->id(), return 0);
|
|
|
|
|
QTC_ASSERT(!info->displayName.isEmpty(), return 0);
|
2010-01-18 12:11:04 +01:00
|
|
|
|
2013-07-22 15:53:57 +02:00
|
|
|
CMakeBuildInfo copy(*static_cast<const CMakeBuildInfo *>(info));
|
2012-07-04 13:00:10 +02:00
|
|
|
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2015-01-31 21:05:34 +02:00
|
|
|
if (copy.buildDirectory.isEmpty()) {
|
|
|
|
|
copy.buildDirectory = shadowBuildDirectory(project->projectFilePath(), parent->kit(),
|
2015-10-22 17:26:33 +02:00
|
|
|
copy.displayName, info->buildType);
|
2015-01-31 21:05:34 +02:00
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2016-01-07 15:22:53 +01:00
|
|
|
auto bc = new CMakeBuildConfiguration(parent);
|
2013-07-22 15:53:57 +02:00
|
|
|
bc->setDisplayName(copy.displayName);
|
|
|
|
|
bc->setDefaultDisplayName(copy.displayName);
|
2010-01-07 18:17:24 +01:00
|
|
|
|
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
|
|
|
|
2016-01-07 12:33:52 +01:00
|
|
|
auto buildStep = new CMakeBuildStep(buildSteps);
|
|
|
|
|
buildSteps->insertStep(0, buildStep);
|
2010-07-16 14:00:41 +02:00
|
|
|
|
2016-01-07 12:33:52 +01:00
|
|
|
auto cleanStep = new CMakeBuildStep(cleanSteps);
|
|
|
|
|
cleanSteps->insertStep(0, cleanStep);
|
|
|
|
|
cleanStep->setBuildTarget(CMakeBuildStep::cleanTarget(), true);
|
2010-01-07 18:17:24 +01:00
|
|
|
|
2015-09-10 16:17:38 +02:00
|
|
|
bc->setBuildDirectory(copy.buildDirectory);
|
2016-02-03 13:52:50 +01:00
|
|
|
bc->setCMakeConfiguration(copy.configuration);
|
2010-01-07 18:17:24 +01:00
|
|
|
|
|
|
|
|
// Default to all
|
2012-11-21 23:54:06 +02:00
|
|
|
if (project->hasBuildTarget(QLatin1String("all")))
|
2016-01-07 12:33:52 +01:00
|
|
|
buildStep->setBuildTarget(QLatin1String("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
|
|
|
{
|
2013-07-22 15:53:57 +02:00
|
|
|
if (!canHandle(parent))
|
|
|
|
|
return false;
|
|
|
|
|
return source->id() == Constants::CMAKE_BC_ID;
|
2010-01-18 12:11:04 +01:00
|
|
|
}
|
|
|
|
|
|
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;
|
2016-01-20 12:19:16 +01:00
|
|
|
auto 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
|
|
|
{
|
2013-07-22 15:53:57 +02:00
|
|
|
if (!canHandle(parent))
|
|
|
|
|
return false;
|
|
|
|
|
return ProjectExplorer::idFromMap(map) == Constants::CMAKE_BC_ID;
|
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;
|
2016-01-07 15:22:53 +01:00
|
|
|
auto 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
|
|
|
|
|
{
|
2013-07-22 15:53:57 +02:00
|
|
|
QTC_ASSERT(t, return false);
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-22 15:53:57 +02:00
|
|
|
CMakeBuildInfo *CMakeBuildConfigurationFactory::createBuildInfo(const ProjectExplorer::Kit *k,
|
2015-09-10 16:17:38 +02:00
|
|
|
const QString &sourceDir,
|
|
|
|
|
BuildType buildType) const
|
2013-07-22 15:53:57 +02:00
|
|
|
{
|
2016-01-20 12:19:16 +01:00
|
|
|
auto info = new CMakeBuildInfo(this);
|
2013-07-22 15:53:57 +02:00
|
|
|
info->kitId = k->id();
|
|
|
|
|
info->sourceDirectory = sourceDir;
|
2016-02-03 13:52:50 +01:00
|
|
|
info->configuration = CMakeConfigurationKitInformation::configuration(k);
|
|
|
|
|
|
|
|
|
|
CMakeConfigItem buildTypeItem;
|
2015-09-10 16:17:38 +02:00
|
|
|
switch (buildType) {
|
|
|
|
|
case BuildTypeNone:
|
|
|
|
|
info->typeName = tr("Build");
|
|
|
|
|
break;
|
|
|
|
|
case BuildTypeDebug:
|
2016-02-03 13:52:50 +01:00
|
|
|
buildTypeItem = { CMakeConfigItem("CMAKE_BUILD_TYPE", "Debug") };
|
2015-09-10 16:17:38 +02:00
|
|
|
info->typeName = tr("Debug");
|
2015-10-22 17:26:33 +02:00
|
|
|
info->buildType = BuildConfiguration::Debug;
|
2015-09-10 16:17:38 +02:00
|
|
|
break;
|
|
|
|
|
case BuildTypeRelease:
|
2016-02-03 13:52:50 +01:00
|
|
|
buildTypeItem = { CMakeConfigItem("CMAKE_BUILD_TYPE", "Release") };
|
2015-09-10 16:17:38 +02:00
|
|
|
info->typeName = tr("Release");
|
2015-10-22 17:26:33 +02:00
|
|
|
info->buildType = BuildConfiguration::Release;
|
2015-09-10 16:17:38 +02:00
|
|
|
break;
|
|
|
|
|
case BuildTypeMinSizeRel:
|
2016-02-03 13:52:50 +01:00
|
|
|
buildTypeItem = { CMakeConfigItem("CMAKE_BUILD_TYPE", "MinSizeRel") };
|
2015-09-10 16:17:38 +02:00
|
|
|
info->typeName = tr("Minimum Size Release");
|
2015-10-22 17:26:33 +02:00
|
|
|
info->buildType = BuildConfiguration::Release;
|
2015-09-10 16:17:38 +02:00
|
|
|
break;
|
|
|
|
|
case BuildTypeRelWithDebInfo:
|
2016-02-03 13:52:50 +01:00
|
|
|
buildTypeItem = { CMakeConfigItem("CMAKE_BUILD_TYPE", "RelWithDebInfo") };
|
2015-09-10 16:17:38 +02:00
|
|
|
info->typeName = tr("Release with Debug Information");
|
2015-10-22 17:26:33 +02:00
|
|
|
info->buildType = BuildConfiguration::Profile;
|
2015-09-10 16:17:38 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
QTC_CHECK(false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-07-22 15:53:57 +02:00
|
|
|
|
2016-02-03 13:52:50 +01:00
|
|
|
if (!buildTypeItem.isNull())
|
|
|
|
|
info->configuration.append(buildTypeItem);
|
|
|
|
|
|
2013-07-22 15:53:57 +02:00
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-03 16:12:00 +01:00
|
|
|
ProjectExplorer::BuildConfiguration::BuildType CMakeBuildConfiguration::buildType() const
|
|
|
|
|
{
|
|
|
|
|
QString cmakeBuildType;
|
2013-08-16 17:45:16 +02:00
|
|
|
QFile cmakeCache(buildDirectory().toString() + QLatin1String("/CMakeCache.txt"));
|
2011-03-03 16:12:00 +01:00
|
|
|
if (cmakeCache.open(QIODevice::ReadOnly)) {
|
|
|
|
|
while (!cmakeCache.atEnd()) {
|
2012-11-21 23:54:06 +02:00
|
|
|
QByteArray line = cmakeCache.readLine();
|
2011-03-03 16:12:00 +01:00
|
|
|
if (line.startsWith("CMAKE_BUILD_TYPE")) {
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (int pos = line.indexOf('='))
|
2012-11-21 23:54:06 +02:00
|
|
|
cmakeBuildType = QString::fromLocal8Bit(line.mid(pos + 1).trimmed());
|
2011-03-03 16:12:00 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cmakeCache.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cover all common CMake build types
|
2012-11-21 23:54:06 +02:00
|
|
|
if (cmakeBuildType.compare(QLatin1String("Release"), Qt::CaseInsensitive) == 0
|
2015-02-20 15:10:56 +01:00
|
|
|
|| cmakeBuildType.compare(QLatin1String("MinSizeRel"), Qt::CaseInsensitive) == 0) {
|
2011-03-03 16:12:00 +01:00
|
|
|
return Release;
|
2012-11-21 23:54:06 +02:00
|
|
|
} else if (cmakeBuildType.compare(QLatin1String("Debug"), Qt::CaseInsensitive) == 0
|
2015-02-20 15:10:56 +01:00
|
|
|
|| cmakeBuildType.compare(QLatin1String("DebugFull"), Qt::CaseInsensitive) == 0) {
|
2011-03-03 16:12:00 +01:00
|
|
|
return Debug;
|
2015-02-20 15:10:56 +01:00
|
|
|
} else if (cmakeBuildType.compare(QLatin1String("RelWithDebInfo"), Qt::CaseInsensitive) == 0) {
|
|
|
|
|
return Profile;
|
2011-03-03 16:12:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Unknown;
|
|
|
|
|
}
|
2012-10-02 17:46:12 +02:00
|
|
|
|
2014-10-22 09:16:55 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace CMakeProjectManager
|