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
|
|
|
|
2016-01-20 12:19:16 +01:00
|
|
|
#include "builddirmanager.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
#include "cmakebuildconfiguration.h"
|
2016-01-07 12:33:52 +01:00
|
|
|
#include "cmakebuildstep.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 "cmakefile.h"
|
|
|
|
|
#include "cmakeprojectmanager.h"
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2016-06-27 14:49:35 +02:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
|
|
|
|
#include <cpptools/projectinfo.h>
|
|
|
|
|
#include <cpptools/projectpartbuilder.h>
|
2010-07-16 14:00:41 +02:00
|
|
|
#include <projectexplorer/buildsteplist.h>
|
2013-07-07 23:49:13 +02:00
|
|
|
#include <projectexplorer/buildtargetinfo.h>
|
2016-05-12 17:42:36 +02:00
|
|
|
#include <projectexplorer/customexecutablerunconfiguration.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <projectexplorer/deployconfiguration.h>
|
|
|
|
|
#include <projectexplorer/deploymentdata.h>
|
|
|
|
|
#include <projectexplorer/headerpath.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/kitmanager.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-01-20 12:19:16 +01:00
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
#include <cpptools/generatedcodemodelsupport.h>
|
|
|
|
|
#include <cpptools/cppmodelmanager.h>
|
|
|
|
|
#include <cpptools/projectinfo.h>
|
|
|
|
|
#include <cpptools/projectpartbuilder.h>
|
2016-04-18 13:06:41 +02:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2016-01-15 16:12:54 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
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>
|
2012-03-26 17:31:04 +04:00
|
|
|
#include <QFileSystemWatcher>
|
2016-06-14 17:43:11 +02:00
|
|
|
#include <QSet>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <QTemporaryDir>
|
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
|
|
|
{
|
2013-09-27 16:30:20 +02:00
|
|
|
setId(Constants::CMAKEPROJECT_ID);
|
2016-01-08 11:31:06 +01:00
|
|
|
setProjectManager(manager);
|
2016-06-27 14:49:35 +02:00
|
|
|
setDocument(new Internal::CMakeFile(this, fileName));
|
|
|
|
|
|
2016-01-08 12:49:00 +01:00
|
|
|
setRootProjectNode(new CMakeProjectNode(fileName));
|
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-06-27 14:49:35 +02:00
|
|
|
Core::DocumentManager::addDocument(document());
|
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-08-17 13:44:22 +02:00
|
|
|
qDeleteAll(m_watchedFiles);
|
2016-01-15 16:12:54 +01:00
|
|
|
qDeleteAll(m_extraCompilers);
|
2009-09-24 16:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-15 14:59:19 +01:00
|
|
|
QStringList CMakeProject::getCXXFlagsFor(const CMakeBuildTarget &buildTarget,
|
|
|
|
|
QHash<QString, QStringList> &cache)
|
|
|
|
|
{
|
|
|
|
|
// check cache:
|
|
|
|
|
auto it = cache.constFind(buildTarget.title);
|
|
|
|
|
if (it != cache.constEnd())
|
|
|
|
|
return *it;
|
|
|
|
|
|
|
|
|
|
if (extractCXXFlagsFromMake(buildTarget, cache))
|
|
|
|
|
return cache.value(buildTarget.title);
|
|
|
|
|
|
|
|
|
|
if (extractCXXFlagsFromNinja(buildTarget, cache))
|
|
|
|
|
return cache.value(buildTarget.title);
|
|
|
|
|
|
|
|
|
|
cache.insert(buildTarget.title, QStringList());
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeProject::extractCXXFlagsFromMake(const CMakeBuildTarget &buildTarget,
|
|
|
|
|
QHash<QString, QStringList> &cache)
|
2014-07-17 19:02:54 +02:00
|
|
|
{
|
|
|
|
|
QString makeCommand = QDir::fromNativeSeparators(buildTarget.makeCommand);
|
|
|
|
|
int startIndex = makeCommand.indexOf(QLatin1Char('\"'));
|
|
|
|
|
int endIndex = makeCommand.indexOf(QLatin1Char('\"'), startIndex + 1);
|
|
|
|
|
if (startIndex != -1 && endIndex != -1) {
|
|
|
|
|
startIndex += 1;
|
|
|
|
|
QString makefile = makeCommand.mid(startIndex, endIndex - startIndex);
|
|
|
|
|
int slashIndex = makefile.lastIndexOf(QLatin1Char('/'));
|
|
|
|
|
makefile.truncate(slashIndex);
|
|
|
|
|
makefile.append(QLatin1String("/CMakeFiles/") + buildTarget.title + QLatin1String(".dir/flags.make"));
|
|
|
|
|
QFile file(makefile);
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
|
|
|
|
QTextStream stream(&file);
|
|
|
|
|
while (!stream.atEnd()) {
|
|
|
|
|
QString line = stream.readLine().trimmed();
|
|
|
|
|
if (line.startsWith(QLatin1String("CXX_FLAGS ="))) {
|
|
|
|
|
// Skip past =
|
2016-02-15 14:59:19 +01:00
|
|
|
cache.insert(buildTarget.title,
|
|
|
|
|
line.mid(11).trimmed().split(QLatin1Char(' '),
|
|
|
|
|
QString::SkipEmptyParts));
|
|
|
|
|
return true;
|
2014-07-17 19:02:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-15 14:59:19 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeProject::extractCXXFlagsFromNinja(const CMakeBuildTarget &buildTarget,
|
|
|
|
|
QHash<QString, QStringList> &cache)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(buildTarget)
|
|
|
|
|
if (!cache.isEmpty()) // We fill the cache in one go!
|
|
|
|
|
return false;
|
2014-07-17 19:02:54 +02:00
|
|
|
|
|
|
|
|
// Attempt to find build.ninja file and obtain FLAGS (CXX_FLAGS) from there if no suitable flags.make were
|
|
|
|
|
// found
|
|
|
|
|
// Get "all" target's working directory
|
2016-02-15 14:59:19 +01:00
|
|
|
QByteArray ninjaFile;
|
|
|
|
|
QString buildNinjaFile = QDir::fromNativeSeparators(buildTargets().at(0).workingDirectory);
|
|
|
|
|
buildNinjaFile += QLatin1String("/build.ninja");
|
|
|
|
|
QFile buildNinja(buildNinjaFile);
|
|
|
|
|
if (buildNinja.exists()) {
|
|
|
|
|
buildNinja.open(QIODevice::ReadOnly | QIODevice::Text);
|
|
|
|
|
ninjaFile = buildNinja.readAll();
|
|
|
|
|
buildNinja.close();
|
|
|
|
|
}
|
2015-04-20 15:59:18 +02:00
|
|
|
|
2016-02-15 14:59:19 +01:00
|
|
|
if (ninjaFile.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
QTextStream stream(ninjaFile);
|
|
|
|
|
bool cxxFound = false;
|
|
|
|
|
const QString targetSignature = QLatin1String("# Object build statements for ");
|
|
|
|
|
QString currentTarget;
|
|
|
|
|
|
|
|
|
|
while (!stream.atEnd()) {
|
|
|
|
|
// 1. Look for a block that refers to the current target
|
|
|
|
|
// 2. Look for a build rule which invokes CXX_COMPILER
|
|
|
|
|
// 3. Return the FLAGS definition
|
|
|
|
|
QString line = stream.readLine().trimmed();
|
|
|
|
|
if (line.startsWith(QLatin1Char('#'))) {
|
|
|
|
|
if (line.startsWith(targetSignature)) {
|
|
|
|
|
int pos = line.lastIndexOf(QLatin1Char(' '));
|
|
|
|
|
currentTarget = line.mid(pos + 1);
|
2014-07-17 19:02:54 +02:00
|
|
|
}
|
2016-02-15 14:59:19 +01:00
|
|
|
} else if (!currentTarget.isEmpty() && line.startsWith(QLatin1String("build"))) {
|
|
|
|
|
cxxFound = line.indexOf(QLatin1String("CXX_COMPILER")) != -1;
|
|
|
|
|
} else if (cxxFound && line.startsWith(QLatin1String("FLAGS ="))) {
|
|
|
|
|
// Skip past =
|
|
|
|
|
cache.insert(currentTarget, line.mid(7).trimmed().split(QLatin1Char(' '), QString::SkipEmptyParts));
|
2014-07-17 19:02:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-02-15 14:59:19 +01:00
|
|
|
return !cache.isEmpty();
|
2014-07-17 19:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-20 12:19:16 +01:00
|
|
|
void CMakeProject::parseCMakeOutput()
|
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-02-24 18:00:24 +01:00
|
|
|
BuildDirManager *bdm = cmakeBc->buildDirManager();
|
|
|
|
|
QTC_ASSERT(bdm, return);
|
2009-03-03 17:56:03 +01:00
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
rootProjectNode()->setDisplayName(bdm->projectName());
|
2009-03-13 13:55:59 +01:00
|
|
|
|
2016-06-27 14:49:35 +02:00
|
|
|
// Delete no longer necessary file watcher:
|
|
|
|
|
const QSet<Utils::FileName> currentWatched
|
|
|
|
|
= Utils::transform(m_watchedFiles, [](CMakeFile *cmf) { return cmf->filePath(); });
|
|
|
|
|
const QSet<Utils::FileName> toWatch = bdm->cmakeFiles();
|
|
|
|
|
QSet<Utils::FileName> toDelete = currentWatched;
|
|
|
|
|
toDelete.subtract(toWatch);
|
|
|
|
|
m_watchedFiles = Utils::filtered(m_watchedFiles, [&toDelete](Internal::CMakeFile *cmf) {
|
|
|
|
|
if (toDelete.contains(cmf->filePath())) {
|
|
|
|
|
delete cmf;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Add new file watchers:
|
|
|
|
|
QSet<Utils::FileName> toAdd = toWatch;
|
|
|
|
|
toAdd.subtract(currentWatched);
|
|
|
|
|
foreach (const Utils::FileName &fn, toAdd) {
|
|
|
|
|
CMakeFile *cm = new CMakeFile(this, fn);
|
|
|
|
|
Core::DocumentManager::addDocument(cm);
|
|
|
|
|
m_watchedFiles.insert(cm);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
buildTree(static_cast<CMakeProjectNode *>(rootProjectNode()), bdm->files());
|
|
|
|
|
bdm->clearFiles(); // Some of the FileNodes in files() were deleted!
|
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-07-12 16:27:45 +02:00
|
|
|
ToolChain *tc = ProjectExplorer::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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 17:43:11 +02:00
|
|
|
const Utils::FileName sysroot = ProjectExplorer::SysRootKitInformation::sysRoot(k);
|
|
|
|
|
|
2015-04-21 09:08:07 +03:00
|
|
|
ppBuilder.setQtVersion(activeQtVersion);
|
|
|
|
|
|
2016-02-15 14:59:19 +01:00
|
|
|
QHash<QString, QStringList> targetDataCache;
|
2016-01-20 12:19:16 +01:00
|
|
|
foreach (const CMakeBuildTarget &cbt, buildTargets()) {
|
2016-06-14 17:43:11 +02:00
|
|
|
// CMake shuffles the include paths that it reports via the CodeBlocks generator
|
|
|
|
|
// So remove the toolchain include paths, so that at least those end up in the correct
|
|
|
|
|
// place.
|
|
|
|
|
QStringList cxxflags = getCXXFlagsFor(cbt, targetDataCache);
|
|
|
|
|
QSet<QString> tcIncludes;
|
|
|
|
|
foreach (const HeaderPath &hp, tc->systemHeaderPaths(cxxflags, sysroot)) {
|
|
|
|
|
tcIncludes.insert(hp.path());
|
|
|
|
|
}
|
|
|
|
|
QStringList includePaths;
|
|
|
|
|
foreach (const QString &i, cbt.includeFiles) {
|
|
|
|
|
if (!tcIncludes.contains(i))
|
|
|
|
|
includePaths.append(i);
|
|
|
|
|
}
|
2015-02-15 23:13:28 +02:00
|
|
|
includePaths += projectDirectory().toString();
|
|
|
|
|
ppBuilder.setIncludePaths(includePaths);
|
2015-07-20 12:32:54 +02:00
|
|
|
ppBuilder.setCFlags(cxxflags);
|
|
|
|
|
ppBuilder.setCxxFlags(cxxflags);
|
2015-02-15 23:13:28 +02:00
|
|
|
ppBuilder.setDefines(cbt.defines);
|
|
|
|
|
ppBuilder.setDisplayName(cbt.title);
|
|
|
|
|
|
|
|
|
|
const QList<Core::Id> languages = ppBuilder.createProjectPartsForFiles(cbt.files);
|
|
|
|
|
foreach (Core::Id language, languages)
|
|
|
|
|
setProjectLanguage(language, true);
|
2010-02-02 12:03:50 +01:00
|
|
|
}
|
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();
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (const QString &cmakeImport, cmakeImports.split(QLatin1Char(';'))) {
|
|
|
|
|
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-02-24 18:00:24 +01:00
|
|
|
if (!bc)
|
2016-01-27 10:22:07 +01:00
|
|
|
return;
|
|
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
BuildDirManager *bdm = bc->buildDirManager();
|
2016-05-13 16:19:31 +02:00
|
|
|
if (bdm && !bdm->isParsing()) {
|
|
|
|
|
bdm->checkConfiguration();
|
2016-02-24 18:00:24 +01:00
|
|
|
bdm->forceReparse();
|
2016-05-13 16:19:31 +02:00
|
|
|
}
|
2011-03-31 17:43:48 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
QList<CMakeBuildTarget> CMakeProject::buildTargets() const
|
|
|
|
|
{
|
2016-02-24 18:00:24 +01:00
|
|
|
BuildDirManager *bdm = nullptr;
|
|
|
|
|
if (activeTarget() && activeTarget()->activeBuildConfiguration())
|
|
|
|
|
bdm = static_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration())->buildDirManager();
|
|
|
|
|
if (!bdm)
|
2016-01-20 12:19:16 +01:00
|
|
|
return QList<CMakeBuildTarget>();
|
2016-02-24 18:00:24 +01:00
|
|
|
return bdm->buildTargets();
|
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-01-20 12:19:16 +01:00
|
|
|
= runnable ? Utils::filtered(buildTargets(),
|
2016-01-05 15:19:11 +01:00
|
|
|
[](const CMakeBuildTarget &ct) {
|
|
|
|
|
return !ct.executable.isEmpty() && ct.targetType == ExecutableType;
|
|
|
|
|
})
|
2016-01-20 12:19:16 +01:00
|
|
|
: buildTargets();
|
2016-01-05 15:19:11 +01:00
|
|
|
return Utils::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-01-20 12:19:16 +01:00
|
|
|
return Utils::anyOf(buildTargets(), [title](const CMakeBuildTarget &ct) { return ct.title == title; });
|
2010-01-14 15:38:31 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-15 15:50:26 +01:00
|
|
|
void CMakeProject::gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-12-01 14:03:15 +01:00
|
|
|
foreach (ProjectExplorer::FolderNode *folder, parent->subFolderNodes())
|
2009-03-26 17:36:58 +01:00
|
|
|
gatherFileNodes(folder, list);
|
2011-12-01 14:03:15 +01:00
|
|
|
foreach (ProjectExplorer::FileNode *file, parent->fileNodes())
|
2009-03-26 17:36:58 +01:00
|
|
|
list.append(file);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-04 11:49:37 +02:00
|
|
|
bool sortNodesByPath(Node *a, Node *b)
|
|
|
|
|
{
|
2015-10-29 17:53:47 +01:00
|
|
|
return a->filePath() < b->filePath();
|
2012-05-04 11:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
2009-03-26 17:36:58 +01:00
|
|
|
void CMakeProject::buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> newList)
|
|
|
|
|
{
|
|
|
|
|
// Gather old list
|
|
|
|
|
QList<ProjectExplorer::FileNode *> oldList;
|
|
|
|
|
gatherFileNodes(rootNode, oldList);
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(oldList, sortNodesByPath);
|
|
|
|
|
Utils::sort(newList, sortNodesByPath);
|
2009-03-26 17:36:58 +01:00
|
|
|
|
|
|
|
|
QList<ProjectExplorer::FileNode *> added;
|
|
|
|
|
QList<ProjectExplorer::FileNode *> deleted;
|
|
|
|
|
|
2014-02-10 16:05:35 +01:00
|
|
|
ProjectExplorer::compareSortedLists(oldList, newList, deleted, added, sortNodesByPath);
|
2009-03-26 17:36:58 +01:00
|
|
|
|
2014-02-10 16:05:35 +01:00
|
|
|
qDeleteAll(ProjectExplorer::subtractSortedList(newList, added, sortNodesByPath));
|
2009-03-26 17:36:58 +01:00
|
|
|
|
|
|
|
|
// add added nodes
|
|
|
|
|
foreach (ProjectExplorer::FileNode *fn, added) {
|
2008-12-02 12:01:29 +01:00
|
|
|
// Get relative path to rootNode
|
2015-10-29 17:53:47 +01:00
|
|
|
QString parentDir = fn->filePath().toFileInfo().absolutePath();
|
2008-12-02 12:01:29 +01:00
|
|
|
ProjectExplorer::FolderNode *folder = findOrCreateFolder(rootNode, parentDir);
|
2014-02-18 19:49:55 +01:00
|
|
|
folder->addFileNodes(QList<ProjectExplorer::FileNode *>()<< fn);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-03-26 17:36:58 +01:00
|
|
|
|
2010-01-11 10:22:55 +01:00
|
|
|
// remove old file nodes and check whether folder nodes can be removed
|
2009-03-26 17:36:58 +01:00
|
|
|
foreach (ProjectExplorer::FileNode *fn, deleted) {
|
|
|
|
|
ProjectExplorer::FolderNode *parent = fn->parentFolderNode();
|
2014-02-18 19:49:55 +01:00
|
|
|
parent->removeFileNodes(QList<ProjectExplorer::FileNode *>() << fn);
|
2009-03-26 17:36:58 +01:00
|
|
|
// Check for empty parent
|
|
|
|
|
while (parent->subFolderNodes().isEmpty() && parent->fileNodes().isEmpty()) {
|
|
|
|
|
ProjectExplorer::FolderNode *grandparent = parent->parentFolderNode();
|
2014-02-18 19:49:55 +01:00
|
|
|
grandparent->removeFolderNodes(QList<ProjectExplorer::FolderNode *>() << parent);
|
2009-03-26 17:36:58 +01:00
|
|
|
parent = grandparent;
|
|
|
|
|
if (parent == rootNode)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::FolderNode *CMakeProject::findOrCreateFolder(CMakeProjectNode *rootNode, QString directory)
|
|
|
|
|
{
|
2015-10-29 17:53:47 +01:00
|
|
|
FileName path = rootNode->filePath().parentDir();
|
2015-02-02 00:37:38 +02:00
|
|
|
QDir rootParentDir(path.toString());
|
|
|
|
|
QString relativePath = rootParentDir.relativeFilePath(directory);
|
2015-08-31 17:35:50 +02:00
|
|
|
if (relativePath == QLatin1String("."))
|
|
|
|
|
relativePath.clear();
|
2010-02-01 12:43:56 +01:00
|
|
|
QStringList parts = relativePath.split(QLatin1Char('/'), QString::SkipEmptyParts);
|
2008-12-02 12:01:29 +01:00
|
|
|
ProjectExplorer::FolderNode *parent = rootNode;
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (const QString &part, parts) {
|
2015-02-02 00:37:38 +02:00
|
|
|
path.appendPath(part);
|
2008-12-02 12:01:29 +01:00
|
|
|
// Find folder in subFolders
|
|
|
|
|
bool found = false;
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (ProjectExplorer::FolderNode *folder, parent->subFolderNodes()) {
|
2015-10-29 17:53:47 +01:00
|
|
|
if (folder->filePath() == path) {
|
2008-12-02 12:01:29 +01:00
|
|
|
// yeah found something :)
|
|
|
|
|
parent = folder;
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found) {
|
|
|
|
|
// No FolderNode yet, so create it
|
2016-01-07 15:22:53 +01:00
|
|
|
auto tmp = new ProjectExplorer::FolderNode(path);
|
2010-02-24 15:03:54 +01:00
|
|
|
tmp->setDisplayName(part);
|
2014-02-18 19:49:55 +01:00
|
|
|
parent->addFolderNodes(QList<ProjectExplorer::FolderNode *>() << tmp);
|
2008-12-02 12:01:29 +01:00
|
|
|
parent = tmp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
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-02-24 18:00:24 +01:00
|
|
|
QList<FileNode *> nodes;
|
|
|
|
|
gatherFileNodes(rootProjectNode(), nodes);
|
|
|
|
|
nodes = Utils::filtered(nodes, [fileMode](const FileNode *fn) {
|
|
|
|
|
const bool isGenerated = fn->isGenerated();
|
|
|
|
|
switch (fileMode)
|
|
|
|
|
{
|
|
|
|
|
case ProjectExplorer::Project::SourceFiles:
|
|
|
|
|
return !isGenerated;
|
|
|
|
|
case ProjectExplorer::Project::GeneratedFiles:
|
|
|
|
|
return isGenerated;
|
|
|
|
|
case ProjectExplorer::Project::AllFiles:
|
|
|
|
|
default:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return Utils::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-06-27 14:49:35 +02:00
|
|
|
void CMakeProject::handleCmakeFileChanged()
|
|
|
|
|
{
|
|
|
|
|
if (Target *t = activeTarget()) {
|
|
|
|
|
if (auto bc = qobject_cast<CMakeBuildConfiguration *>(t->activeBuildConfiguration())) {
|
|
|
|
|
bc->cmakeFilesChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2013-01-08 17:21:18 +01:00
|
|
|
cmakeListsTxt.appendPath(QLatin1String("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-01-15 16:12:54 +01:00
|
|
|
if (fi.suffix() == QLatin1String("ui")) {
|
|
|
|
|
generatedFilePath += QLatin1String("/ui_");
|
|
|
|
|
generatedFilePath += fi.completeBaseName();
|
|
|
|
|
generatedFilePath += QLatin1String(".h");
|
|
|
|
|
return QStringList(QDir::cleanPath(generatedFilePath));
|
2016-01-15 16:58:22 +01:00
|
|
|
} else if (fi.suffix() == QLatin1String("scxml")) {
|
|
|
|
|
generatedFilePath += QLatin1String("/");
|
|
|
|
|
generatedFilePath += QDir::cleanPath(fi.completeBaseName());
|
|
|
|
|
return QStringList({generatedFilePath + QLatin1String(".h"),
|
|
|
|
|
generatedFilePath + QLatin1String(".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()) {
|
|
|
|
|
cmakeRc->setExecutable(btIt.value()->executable);
|
|
|
|
|
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());
|
|
|
|
|
|
2013-07-07 23:49:13 +02:00
|
|
|
deploymentFile.setFileName(sourceDir.filePath(QLatin1String("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())
|
|
|
|
|
deploymentFile.setFileName(buildDir.filePath(QLatin1String("QtCreatorDeployment.txt")));
|
2013-07-07 23:49:13 +02:00
|
|
|
if (deploymentFile.open(QFile::ReadOnly | QFile::Text)) {
|
|
|
|
|
deploymentStream.setDevice(&deploymentFile);
|
|
|
|
|
deploymentPrefix = deploymentStream.readLine();
|
|
|
|
|
if (!deploymentPrefix.endsWith(QLatin1Char('/')))
|
|
|
|
|
deploymentPrefix.append(QLatin1Char('/'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()) {
|
2013-07-07 23:49:13 +02:00
|
|
|
if (ct.executable.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
2014-11-06 11:27:24 +01:00
|
|
|
if (ct.targetType == ExecutableType || ct.targetType == DynamicLibraryType)
|
|
|
|
|
deploymentData.addFile(ct.executable, deploymentPrefix + buildDir.relativeFilePath(QFileInfo(ct.executable).dir().path()), DeployableFile::TypeExecutable);
|
|
|
|
|
if (ct.targetType == ExecutableType) {
|
2013-07-07 23:49:13 +02:00
|
|
|
// TODO: Put a path to corresponding .cbp file into projectFilePath?
|
2014-08-07 15:53:54 +02:00
|
|
|
appTargetList.list << BuildTargetInfo(ct.title,
|
2015-02-01 18:44:47 +02:00
|
|
|
FileName::fromString(ct.executable),
|
|
|
|
|
FileName::fromString(ct.executable));
|
2013-07-07 23:49:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString absoluteSourcePath = sourceDir.absolutePath();
|
|
|
|
|
if (!absoluteSourcePath.endsWith(QLatin1Char('/')))
|
|
|
|
|
absoluteSourcePath.append(QLatin1Char('/'));
|
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();
|
|
|
|
|
if (!line.contains(QLatin1Char(':')))
|
|
|
|
|
continue;
|
|
|
|
|
QStringList file = line.split(QLatin1Char(':'));
|
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();
|
|
|
|
|
QList<ProjectExplorer::ExtraCompilerFactory *> factories =
|
|
|
|
|
ProjectExplorer::ExtraCompilerFactory::extraCompilerFactories();
|
|
|
|
|
|
|
|
|
|
// Find all files generated by any of the extra compilers, in a rather crude way.
|
|
|
|
|
foreach (const QString &file, files(SourceFiles)) {
|
|
|
|
|
foreach (ProjectExplorer::ExtraCompilerFactory *factory, factories) {
|
|
|
|
|
if (file.endsWith(QLatin1Char('.') + factory->sourceTag())) {
|
|
|
|
|
QStringList generated = filesGeneratedFrom(file);
|
|
|
|
|
if (!generated.isEmpty()) {
|
|
|
|
|
const FileNameList fileNames = Utils::transform(generated,
|
|
|
|
|
[](const QString &s) {
|
|
|
|
|
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();
|
|
|
|
|
makeCleanCommand.clear();
|
|
|
|
|
workingDirectory.clear();
|
2014-07-17 19:02:54 +02:00
|
|
|
sourceDirectory.clear();
|
2010-02-02 17:09:41 +01:00
|
|
|
title.clear();
|
2014-11-06 11:27:24 +01:00
|
|
|
targetType = ExecutableType;
|
2014-07-17 19:02:54 +02:00
|
|
|
includeFiles.clear();
|
|
|
|
|
compilerOptions.clear();
|
|
|
|
|
defines.clear();
|
2008-12-09 14:13:29 +01:00
|
|
|
}
|
2016-02-24 18:00:24 +01:00
|
|
|
|
|
|
|
|
} // namespace CMakeProjectManager
|