2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +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-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +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-02 14:17:16 +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-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cmakeproject.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
|
|
|
|
|
#include "cmakebuildconfiguration.h"
|
2016-01-06 15:51:44 +01:00
|
|
|
#include "cmakekitinformation.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cmakeprojectconstants.h"
|
|
|
|
|
#include "cmakeprojectnodes.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
#include "cmakerunconfiguration.h"
|
2015-03-10 10:22:38 +01:00
|
|
|
#include "cmakeprojectmanager.h"
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2016-10-06 11:31:23 +02:00
|
|
|
#include <cpptools/generatedcodemodelsupport.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <cpptools/projectinfo.h>
|
|
|
|
|
#include <cpptools/projectpartbuilder.h>
|
2013-07-07 23:49:13 +02:00
|
|
|
#include <projectexplorer/buildtargetinfo.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <projectexplorer/deploymentdata.h>
|
|
|
|
|
#include <projectexplorer/headerpath.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2010-11-01 14:14:17 +01:00
|
|
|
#include <projectexplorer/toolchain.h>
|
2013-01-17 15:12:46 +01:00
|
|
|
#include <qtsupport/baseqtversion.h>
|
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2016-10-06 11:31:15 +02:00
|
|
|
#include <texteditor/textdocument.h>
|
2016-04-18 13:06:41 +02:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2016-10-06 11:31:23 +02:00
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2012-11-19 14:18:14 +01:00
|
|
|
#include <utils/stringutils.h>
|
2013-01-01 18:18:03 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
2016-06-14 17:43:11 +02:00
|
|
|
#include <QSet>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-09-24 16:02:02 +02:00
|
|
|
using namespace ProjectExplorer;
|
2015-02-01 18:44:47 +02:00
|
|
|
using namespace Utils;
|
2008-12-12 17:22:02 +01:00
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
namespace CMakeProjectManager {
|
|
|
|
|
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2008-12-12 17:22:02 +01:00
|
|
|
// QtCreator CMake Generator wishlist:
|
|
|
|
|
// Which make targets we need to build to get all executables
|
|
|
|
|
// What is the actual compiler executable
|
|
|
|
|
// DEFINES
|
|
|
|
|
|
2009-09-24 16:02:02 +02:00
|
|
|
/*!
|
|
|
|
|
\class CMakeProject
|
|
|
|
|
*/
|
2016-01-20 12:19:16 +01:00
|
|
|
CMakeProject::CMakeProject(CMakeManager *manager, const FileName &fileName)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-10-06 11:31:23 +02:00
|
|
|
setId(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
|
2016-01-08 11:31:06 +01:00
|
|
|
setProjectManager(manager);
|
2016-10-06 11:31:15 +02:00
|
|
|
setDocument(new TextEditor::TextDocument);
|
|
|
|
|
document()->setFilePath(fileName);
|
2016-06-27 14:49:35 +02:00
|
|
|
|
2016-10-06 11:31:23 +02:00
|
|
|
setRootProjectNode(new CMakeProjectNode(FileName::fromString(fileName.toFileInfo().absolutePath())));
|
2011-04-12 12:17:19 +02:00
|
|
|
setProjectContext(Core::Context(CMakeProjectManager::Constants::PROJECTCONTEXT));
|
2013-05-28 13:19:32 +02:00
|
|
|
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
|
2011-04-12 12:17:19 +02:00
|
|
|
|
2016-01-08 12:49:00 +01:00
|
|
|
rootProjectNode()->setDisplayName(fileName.parentDir().fileName());
|
2016-03-31 15:07:58 +02:00
|
|
|
|
|
|
|
|
connect(this, &CMakeProject::activeTargetChanged, this, &CMakeProject::handleActiveTargetChanged);
|
2009-01-12 15:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeProject::~CMakeProject()
|
|
|
|
|
{
|
2016-01-20 12:19:16 +01:00
|
|
|
setRootProjectNode(nullptr);
|
2010-04-22 18:57:43 +02:00
|
|
|
m_codeModelFuture.cancel();
|
2016-01-15 16:12:54 +01:00
|
|
|
qDeleteAll(m_extraCompilers);
|
2009-09-24 16:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-30 11:29:32 +02:00
|
|
|
void CMakeProject::updateProjectData()
|
2009-01-12 15:10:33 +01:00
|
|
|
{
|
2016-02-24 18:00:24 +01:00
|
|
|
auto cmakeBc = qobject_cast<CMakeBuildConfiguration *>(sender());
|
|
|
|
|
QTC_ASSERT(cmakeBc, return);
|
2016-04-01 16:18:03 +02:00
|
|
|
|
|
|
|
|
Target *t = activeTarget();
|
|
|
|
|
if (!t || t->activeBuildConfiguration() != cmakeBc)
|
2016-02-24 18:00:24 +01:00
|
|
|
return;
|
2016-04-01 16:18:03 +02:00
|
|
|
Kit *k = t->kit();
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2016-10-06 11:31:27 +02:00
|
|
|
cmakeBc->generateProjectTree(static_cast<CMakeProjectNode *>(rootProjectNode()));
|
2008-12-09 14:13:29 +01:00
|
|
|
|
2013-07-07 23:49:13 +02:00
|
|
|
updateApplicationAndDeploymentTargets();
|
2016-04-01 16:22:07 +02:00
|
|
|
updateTargetRunConfigurations(t);
|
2010-09-24 13:17:43 +02:00
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
createGeneratedCodeModelSupport();
|
2009-02-11 12:14:51 +01:00
|
|
|
|
2016-10-06 11:31:23 +02:00
|
|
|
ToolChain *tc = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx);
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!tc) {
|
2012-07-17 15:56:43 +02:00
|
|
|
emit fileListChanged();
|
2016-01-20 12:19:16 +01:00
|
|
|
return;
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2015-02-15 23:13:28 +02:00
|
|
|
CppTools::CppModelManager *modelmanager = CppTools::CppModelManager::instance();
|
|
|
|
|
CppTools::ProjectInfo pinfo(this);
|
|
|
|
|
CppTools::ProjectPartBuilder ppBuilder(pinfo);
|
|
|
|
|
|
2015-04-21 09:08:07 +03:00
|
|
|
CppTools::ProjectPart::QtVersion activeQtVersion = CppTools::ProjectPart::NoQt;
|
2016-04-01 16:18:03 +02:00
|
|
|
if (QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(k)) {
|
2015-04-21 09:08:07 +03:00
|
|
|
if (qtVersion->qtVersion() < QtSupport::QtVersionNumber(5,0,0))
|
|
|
|
|
activeQtVersion = CppTools::ProjectPart::Qt4;
|
|
|
|
|
else
|
|
|
|
|
activeQtVersion = CppTools::ProjectPart::Qt5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ppBuilder.setQtVersion(activeQtVersion);
|
|
|
|
|
|
2016-10-10 10:22:06 +02:00
|
|
|
const QSet<Core::Id> languages = cmakeBc->updateCodeModel(ppBuilder);
|
|
|
|
|
for (const auto &lid : languages)
|
|
|
|
|
setProjectLanguage(lid, true);
|
2013-04-28 16:23:01 +04:00
|
|
|
|
2015-02-15 23:13:28 +02:00
|
|
|
m_codeModelFuture.cancel();
|
|
|
|
|
pinfo.finish();
|
|
|
|
|
m_codeModelFuture = modelmanager->updateProjectInfo(pinfo);
|
|
|
|
|
|
2016-04-18 13:06:41 +02:00
|
|
|
updateQmlJSCodeModel();
|
|
|
|
|
|
2014-07-14 17:39:46 +02:00
|
|
|
emit displayNameChanged();
|
2010-09-27 20:34:22 +01:00
|
|
|
emit fileListChanged();
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
emit cmakeBc->emitBuildTypeChanged();
|
2016-10-20 13:18:54 +02:00
|
|
|
|
|
|
|
|
emit parsingFinished();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-18 13:06:41 +02:00
|
|
|
void CMakeProject::updateQmlJSCodeModel()
|
|
|
|
|
{
|
|
|
|
|
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
|
|
|
|
|
QTC_ASSERT(modelManager, return);
|
|
|
|
|
|
|
|
|
|
if (!activeTarget() || !activeTarget()->activeBuildConfiguration())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QmlJS::ModelManagerInterface::ProjectInfo projectInfo =
|
|
|
|
|
modelManager->defaultProjectInfoForProject(this);
|
|
|
|
|
|
|
|
|
|
projectInfo.importPaths.clear();
|
|
|
|
|
|
|
|
|
|
QString cmakeImports;
|
|
|
|
|
CMakeBuildConfiguration *bc = qobject_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
|
|
|
|
|
if (!bc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const QList<ConfigModel::DataItem> &cm = bc->completeCMakeConfiguration();
|
|
|
|
|
foreach (const ConfigModel::DataItem &di, cm) {
|
|
|
|
|
if (di.key.contains(QStringLiteral("QML_IMPORT_PATH"))) {
|
|
|
|
|
cmakeImports = di.value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-06 11:31:25 +02:00
|
|
|
foreach (const QString &cmakeImport, CMakeConfigItem::cmakeSplitValue(cmakeImports))
|
2016-04-18 13:06:41 +02:00
|
|
|
projectInfo.importPaths.maybeInsert(FileName::fromString(cmakeImport),QmlJS::Dialect::Qml);
|
|
|
|
|
|
|
|
|
|
modelManager->updateProjectInfo(projectInfo, this);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-10 16:17:38 +02:00
|
|
|
bool CMakeProject::needsConfiguration() const
|
|
|
|
|
{
|
|
|
|
|
return targets().isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeProject::requiresTargetPanel() const
|
|
|
|
|
{
|
2015-09-16 16:33:33 +02:00
|
|
|
return !targets().isEmpty();
|
2015-09-10 16:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-01 16:22:07 +02:00
|
|
|
bool CMakeProject::knowsAllBuildExecutables() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 15:51:44 +01:00
|
|
|
bool CMakeProject::supportsKit(Kit *k, QString *errorMessage) const
|
|
|
|
|
{
|
|
|
|
|
if (!CMakeKitInformation::cmakeTool(k)) {
|
|
|
|
|
if (errorMessage)
|
|
|
|
|
*errorMessage = tr("No cmake tool set.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-20 12:19:16 +01:00
|
|
|
void CMakeProject::runCMake()
|
|
|
|
|
{
|
2016-02-24 18:00:24 +01:00
|
|
|
CMakeBuildConfiguration *bc = nullptr;
|
|
|
|
|
if (activeTarget())
|
|
|
|
|
bc = qobject_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
|
2016-01-20 12:19:16 +01:00
|
|
|
|
2016-10-06 11:31:27 +02:00
|
|
|
if (bc)
|
|
|
|
|
bc->runCMake();
|
2011-03-31 17:43:48 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
QList<CMakeBuildTarget> CMakeProject::buildTargets() const
|
|
|
|
|
{
|
2016-10-06 11:31:27 +02:00
|
|
|
CMakeBuildConfiguration *bc = nullptr;
|
|
|
|
|
if (activeTarget())
|
|
|
|
|
bc = qobject_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
|
|
|
|
|
|
|
|
|
|
return bc ? bc->buildTargets() : QList<CMakeBuildTarget>();
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-16 14:18:39 +01:00
|
|
|
QStringList CMakeProject::buildTargetTitles(bool runnable) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-01-05 15:19:11 +01:00
|
|
|
const QList<CMakeBuildTarget> targets
|
2016-10-06 11:31:23 +02:00
|
|
|
= runnable ? filtered(buildTargets(),
|
|
|
|
|
[](const CMakeBuildTarget &ct) {
|
|
|
|
|
return !ct.executable.isEmpty() && ct.targetType == ExecutableType;
|
|
|
|
|
})
|
2016-01-20 12:19:16 +01:00
|
|
|
: buildTargets();
|
2016-10-06 11:31:23 +02:00
|
|
|
return transform(targets, [](const CMakeBuildTarget &ct) { return ct.title; });
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-02 12:01:11 +01:00
|
|
|
bool CMakeProject::hasBuildTarget(const QString &title) const
|
2010-01-14 15:38:31 +01:00
|
|
|
{
|
2016-10-06 11:31:23 +02:00
|
|
|
return anyOf(buildTargets(), [title](const CMakeBuildTarget &ct) { return ct.title == title; });
|
2010-01-14 15:38:31 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString CMakeProject::displayName() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-01-08 12:49:00 +01:00
|
|
|
return rootProjectNode()->displayName();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList CMakeProject::files(FilesMode fileMode) const
|
|
|
|
|
{
|
2016-10-06 11:31:23 +02:00
|
|
|
const QList<FileNode *> nodes = filtered(rootProjectNode()->recursiveFileNodes(),
|
|
|
|
|
[fileMode](const FileNode *fn) {
|
2016-02-24 18:00:24 +01:00
|
|
|
const bool isGenerated = fn->isGenerated();
|
|
|
|
|
switch (fileMode)
|
|
|
|
|
{
|
2016-10-06 11:31:23 +02:00
|
|
|
case Project::SourceFiles:
|
2016-02-24 18:00:24 +01:00
|
|
|
return !isGenerated;
|
2016-10-06 11:31:23 +02:00
|
|
|
case Project::GeneratedFiles:
|
2016-02-24 18:00:24 +01:00
|
|
|
return isGenerated;
|
2016-10-06 11:31:23 +02:00
|
|
|
case Project::AllFiles:
|
2016-02-24 18:00:24 +01:00
|
|
|
default:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-10-06 11:31:23 +02:00
|
|
|
return transform(nodes, [fileMode](const FileNode* fn) { return fn->filePath().toString(); });
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-05-18 16:57:29 +02:00
|
|
|
Project::RestoreResult CMakeProject::fromMap(const QVariantMap &map, QString *errorMessage)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-05-18 16:57:29 +02:00
|
|
|
RestoreResult result = Project::fromMap(map, errorMessage);
|
|
|
|
|
if (result != RestoreResult::Ok)
|
|
|
|
|
return result;
|
|
|
|
|
return RestoreResult::Ok;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-10-02 17:46:19 +02:00
|
|
|
bool CMakeProject::setupTarget(Target *t)
|
|
|
|
|
{
|
2013-07-07 23:49:13 +02:00
|
|
|
t->updateDefaultBuildConfigurations();
|
2014-07-31 16:36:46 +02:00
|
|
|
if (t->buildConfigurations().isEmpty())
|
|
|
|
|
return false;
|
2013-07-07 23:49:13 +02:00
|
|
|
t->updateDefaultDeployConfigurations();
|
2012-10-02 17:46:19 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
void CMakeProject::handleActiveTargetChanged()
|
|
|
|
|
{
|
|
|
|
|
if (m_connectedTarget) {
|
|
|
|
|
disconnect(m_connectedTarget, &Target::activeBuildConfigurationChanged,
|
|
|
|
|
this, &CMakeProject::handleActiveBuildConfigurationChanged);
|
2016-03-31 15:07:58 +02:00
|
|
|
disconnect(m_connectedTarget, &Target::kitChanged,
|
|
|
|
|
this, &CMakeProject::handleActiveBuildConfigurationChanged);
|
2016-02-24 18:00:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_connectedTarget = activeTarget();
|
|
|
|
|
|
|
|
|
|
if (m_connectedTarget) {
|
|
|
|
|
connect(m_connectedTarget, &Target::activeBuildConfigurationChanged,
|
|
|
|
|
this, &CMakeProject::handleActiveBuildConfigurationChanged);
|
2016-03-31 15:07:58 +02:00
|
|
|
connect(m_connectedTarget, &Target::kitChanged,
|
|
|
|
|
this, &CMakeProject::handleActiveBuildConfigurationChanged);
|
2016-02-24 18:00:24 +01:00
|
|
|
}
|
2016-03-31 15:07:58 +02:00
|
|
|
|
|
|
|
|
handleActiveBuildConfigurationChanged();
|
2016-02-24 18:00:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeProject::handleActiveBuildConfigurationChanged()
|
|
|
|
|
{
|
|
|
|
|
if (!activeTarget() || !activeTarget()->activeBuildConfiguration())
|
|
|
|
|
return;
|
|
|
|
|
auto activeBc = qobject_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
|
|
|
|
|
|
|
|
|
|
foreach (Target *t, targets()) {
|
|
|
|
|
foreach (BuildConfiguration *bc, t->buildConfigurations()) {
|
|
|
|
|
auto i = qobject_cast<CMakeBuildConfiguration *>(bc);
|
|
|
|
|
QTC_ASSERT(i, continue);
|
|
|
|
|
if (i == activeBc)
|
2016-03-31 15:07:58 +02:00
|
|
|
i->maybeForceReparse();
|
2016-02-24 18:00:24 +01:00
|
|
|
else
|
|
|
|
|
i->resetData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeProject::handleParsingStarted()
|
|
|
|
|
{
|
|
|
|
|
if (activeTarget() && activeTarget()->activeBuildConfiguration() == sender())
|
|
|
|
|
emit parsingStarted();
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-02 12:01:11 +01:00
|
|
|
CMakeBuildTarget CMakeProject::buildTargetForTitle(const QString &title)
|
2009-04-06 17:01:26 +02:00
|
|
|
{
|
2016-01-20 12:19:16 +01:00
|
|
|
foreach (const CMakeBuildTarget &ct, buildTargets())
|
2009-04-06 17:01:26 +02:00
|
|
|
if (ct.title == title)
|
|
|
|
|
return ct;
|
2010-02-02 12:01:11 +01:00
|
|
|
return CMakeBuildTarget();
|
2009-04-06 17:01:26 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
QStringList CMakeProject::filesGeneratedFrom(const QString &sourceFile) const
|
2010-09-24 13:17:43 +02:00
|
|
|
{
|
2015-09-10 16:17:38 +02:00
|
|
|
if (!activeTarget())
|
2016-01-15 16:12:54 +01:00
|
|
|
return QStringList();
|
|
|
|
|
QFileInfo fi(sourceFile);
|
2015-02-01 18:44:47 +02:00
|
|
|
FileName project = projectDirectory();
|
|
|
|
|
FileName baseDirectory = FileName::fromString(fi.absolutePath());
|
2013-01-08 17:21:18 +01:00
|
|
|
|
|
|
|
|
while (baseDirectory.isChildOf(project)) {
|
2015-02-01 18:44:47 +02:00
|
|
|
FileName cmakeListsTxt = baseDirectory;
|
2016-10-06 11:31:23 +02:00
|
|
|
cmakeListsTxt.appendPath("CMakeLists.txt");
|
2014-10-24 13:15:54 +02:00
|
|
|
if (cmakeListsTxt.exists())
|
2013-01-08 17:21:18 +01:00
|
|
|
break;
|
|
|
|
|
QDir dir(baseDirectory.toString());
|
|
|
|
|
dir.cdUp();
|
2015-02-01 18:44:47 +02:00
|
|
|
baseDirectory = FileName::fromString(dir.absolutePath());
|
2013-01-08 17:21:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDir srcDirRoot = QDir(project.toString());
|
|
|
|
|
QString relativePath = srcDirRoot.relativeFilePath(baseDirectory.toString());
|
2013-08-16 17:45:16 +02:00
|
|
|
QDir buildDir = QDir(activeTarget()->activeBuildConfiguration()->buildDirectory().toString());
|
2016-01-15 16:12:54 +01:00
|
|
|
QString generatedFilePath = buildDir.absoluteFilePath(relativePath);
|
2013-01-08 17:21:18 +01:00
|
|
|
|
2016-10-06 11:31:23 +02:00
|
|
|
if (fi.suffix() == "ui") {
|
|
|
|
|
generatedFilePath += "/ui_";
|
2016-01-15 16:12:54 +01:00
|
|
|
generatedFilePath += fi.completeBaseName();
|
2016-10-06 11:31:23 +02:00
|
|
|
generatedFilePath += ".h";
|
2016-01-15 16:12:54 +01:00
|
|
|
return QStringList(QDir::cleanPath(generatedFilePath));
|
2016-10-06 11:31:23 +02:00
|
|
|
} else if (fi.suffix() == "scxml") {
|
|
|
|
|
generatedFilePath += "/";
|
2016-01-15 16:58:22 +01:00
|
|
|
generatedFilePath += QDir::cleanPath(fi.completeBaseName());
|
2016-10-06 11:31:23 +02:00
|
|
|
return QStringList({ generatedFilePath + ".h",
|
|
|
|
|
generatedFilePath + ".cpp" });
|
2016-01-15 16:12:54 +01:00
|
|
|
} else {
|
|
|
|
|
// TODO: Other types will be added when adapters for their compilers become available.
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
2010-09-24 13:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-08 14:29:36 +01:00
|
|
|
void CMakeProject::updateTargetRunConfigurations(Target *t)
|
2012-07-17 15:56:43 +02:00
|
|
|
{
|
2016-04-01 16:22:07 +02:00
|
|
|
// *Update* existing runconfigurations (no need to update new ones!):
|
|
|
|
|
QHash<QString, const CMakeBuildTarget *> buildTargetHash;
|
|
|
|
|
const QList<CMakeBuildTarget> buildTargetList = buildTargets();
|
|
|
|
|
foreach (const CMakeBuildTarget &bt, buildTargetList) {
|
|
|
|
|
if (bt.targetType != ExecutableType || bt.executable.isEmpty())
|
|
|
|
|
continue;
|
2015-08-31 14:11:31 +02:00
|
|
|
|
2016-04-01 16:22:07 +02:00
|
|
|
buildTargetHash.insert(bt.title, &bt);
|
2012-07-17 15:56:43 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-01 16:22:07 +02:00
|
|
|
foreach (RunConfiguration *rc, t->runConfigurations()) {
|
|
|
|
|
auto cmakeRc = qobject_cast<CMakeRunConfiguration *>(rc);
|
|
|
|
|
if (!cmakeRc)
|
2012-07-17 15:56:43 +02:00
|
|
|
continue;
|
2016-04-01 16:22:07 +02:00
|
|
|
|
|
|
|
|
auto btIt = buildTargetHash.constFind(cmakeRc->title());
|
|
|
|
|
cmakeRc->setEnabled(btIt != buildTargetHash.constEnd());
|
|
|
|
|
if (btIt != buildTargetHash.constEnd()) {
|
2016-10-13 12:02:52 +02:00
|
|
|
cmakeRc->setExecutable(btIt.value()->executable.toString());
|
2016-04-01 16:22:07 +02:00
|
|
|
cmakeRc->setBaseWorkingDirectory(btIt.value()->workingDirectory);
|
2012-07-17 15:56:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-01 16:22:07 +02:00
|
|
|
// create new and remove obsolete RCs using the factories
|
|
|
|
|
t->updateDefaultRunConfigurations();
|
2012-07-17 15:56:43 +02:00
|
|
|
}
|
|
|
|
|
|
2013-07-07 23:49:13 +02:00
|
|
|
void CMakeProject::updateApplicationAndDeploymentTargets()
|
|
|
|
|
{
|
|
|
|
|
Target *t = activeTarget();
|
2015-09-10 16:17:38 +02:00
|
|
|
if (!t)
|
|
|
|
|
return;
|
2013-07-07 23:49:13 +02:00
|
|
|
|
|
|
|
|
QFile deploymentFile;
|
|
|
|
|
QTextStream deploymentStream;
|
|
|
|
|
QString deploymentPrefix;
|
|
|
|
|
|
2014-11-13 09:26:13 +01:00
|
|
|
QDir sourceDir(t->project()->projectDirectory().toString());
|
|
|
|
|
QDir buildDir(t->activeBuildConfiguration()->buildDirectory().toString());
|
|
|
|
|
|
2016-10-06 11:31:23 +02:00
|
|
|
deploymentFile.setFileName(sourceDir.filePath("QtCreatorDeployment.txt"));
|
2014-11-13 09:26:13 +01:00
|
|
|
// If we don't have a global QtCreatorDeployment.txt check for one created by the active build configuration
|
|
|
|
|
if (!deploymentFile.exists())
|
2016-10-06 11:31:23 +02:00
|
|
|
deploymentFile.setFileName(buildDir.filePath("QtCreatorDeployment.txt"));
|
2013-07-07 23:49:13 +02:00
|
|
|
if (deploymentFile.open(QFile::ReadOnly | QFile::Text)) {
|
|
|
|
|
deploymentStream.setDevice(&deploymentFile);
|
|
|
|
|
deploymentPrefix = deploymentStream.readLine();
|
2016-10-06 11:31:23 +02:00
|
|
|
if (!deploymentPrefix.endsWith('/'))
|
|
|
|
|
deploymentPrefix.append('/');
|
2013-07-07 23:49:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BuildTargetInfoList appTargetList;
|
|
|
|
|
DeploymentData deploymentData;
|
2014-11-13 09:26:13 +01:00
|
|
|
|
2016-01-20 12:19:16 +01:00
|
|
|
foreach (const CMakeBuildTarget &ct, buildTargets()) {
|
2016-08-17 12:45:04 +02:00
|
|
|
if (ct.targetType == UtilityType)
|
2013-07-07 23:49:13 +02:00
|
|
|
continue;
|
|
|
|
|
|
2014-11-06 11:27:24 +01:00
|
|
|
if (ct.targetType == ExecutableType || ct.targetType == DynamicLibraryType)
|
2016-10-13 12:02:52 +02:00
|
|
|
deploymentData.addFile(ct.executable.toString(), deploymentPrefix + buildDir.relativeFilePath(ct.executable.toFileInfo().dir().path()), DeployableFile::TypeExecutable);
|
2014-11-06 11:27:24 +01:00
|
|
|
if (ct.targetType == ExecutableType) {
|
2013-07-07 23:49:13 +02:00
|
|
|
// TODO: Put a path to corresponding .cbp file into projectFilePath?
|
2016-10-13 12:02:52 +02:00
|
|
|
appTargetList.list << BuildTargetInfo(ct.title, ct.executable, ct.executable);
|
2013-07-07 23:49:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString absoluteSourcePath = sourceDir.absolutePath();
|
2016-10-06 11:31:23 +02:00
|
|
|
if (!absoluteSourcePath.endsWith('/'))
|
|
|
|
|
absoluteSourcePath.append('/');
|
2014-06-28 17:23:42 +04:00
|
|
|
if (deploymentStream.device()) {
|
|
|
|
|
while (!deploymentStream.atEnd()) {
|
2014-06-30 13:03:49 +04:00
|
|
|
QString line = deploymentStream.readLine();
|
2016-10-06 11:31:23 +02:00
|
|
|
if (!line.contains(':'))
|
2014-06-30 13:03:49 +04:00
|
|
|
continue;
|
2016-10-06 11:31:23 +02:00
|
|
|
QStringList file = line.split(':');
|
2014-06-28 17:23:42 +04:00
|
|
|
deploymentData.addFile(absoluteSourcePath + file.at(0), deploymentPrefix + file.at(1));
|
|
|
|
|
}
|
2013-07-07 23:49:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t->setApplicationTargets(appTargetList);
|
|
|
|
|
t->setDeploymentData(deploymentData);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
void CMakeProject::createGeneratedCodeModelSupport()
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_extraCompilers);
|
|
|
|
|
m_extraCompilers.clear();
|
2016-10-06 11:31:23 +02:00
|
|
|
QList<ExtraCompilerFactory *> factories =
|
|
|
|
|
ExtraCompilerFactory::extraCompilerFactories();
|
2016-01-15 16:12:54 +01:00
|
|
|
|
|
|
|
|
// Find all files generated by any of the extra compilers, in a rather crude way.
|
|
|
|
|
foreach (const QString &file, files(SourceFiles)) {
|
2016-10-06 11:31:23 +02:00
|
|
|
foreach (ExtraCompilerFactory *factory, factories) {
|
|
|
|
|
if (file.endsWith('.' + factory->sourceTag())) {
|
2016-01-15 16:12:54 +01:00
|
|
|
QStringList generated = filesGeneratedFrom(file);
|
|
|
|
|
if (!generated.isEmpty()) {
|
2016-10-06 11:31:23 +02:00
|
|
|
const FileNameList fileNames = transform(generated,
|
|
|
|
|
[](const QString &s) {
|
2016-01-15 16:12:54 +01:00
|
|
|
return FileName::fromString(s);
|
|
|
|
|
});
|
|
|
|
|
m_extraCompilers.append(factory->create(this, FileName::fromString(file),
|
|
|
|
|
fileNames));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-24 13:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
CppTools::GeneratedCodeModelSupport::update(m_extraCompilers);
|
2010-09-24 13:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-02 12:01:11 +01:00
|
|
|
void CMakeBuildTarget::clear()
|
2008-12-09 14:13:29 +01:00
|
|
|
{
|
2010-02-02 17:09:41 +01:00
|
|
|
executable.clear();
|
|
|
|
|
makeCommand.clear();
|
|
|
|
|
workingDirectory.clear();
|
2014-07-17 19:02:54 +02:00
|
|
|
sourceDirectory.clear();
|
2010-02-02 17:09:41 +01:00
|
|
|
title.clear();
|
2016-08-17 11:13:39 +02:00
|
|
|
targetType = UtilityType;
|
2014-07-17 19:02:54 +02:00
|
|
|
includeFiles.clear();
|
|
|
|
|
compilerOptions.clear();
|
|
|
|
|
defines.clear();
|
2016-10-17 14:03:29 +02:00
|
|
|
files.clear();
|
2008-12-09 14:13:29 +01:00
|
|
|
}
|
2016-02-24 18:00:24 +01:00
|
|
|
|
|
|
|
|
} // namespace CMakeProjectManager
|