Files
qt-creator/src/plugins/cmakeprojectmanager/cmakeproject.cpp

782 lines
28 KiB
C++
Raw Normal View History

/****************************************************************************
2008-12-02 12:01:29 +01:00
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator.
2008-12-02 12:01:29 +01:00
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and 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.
**
** 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
**
****************************************************************************/
2008-12-02 14:09:21 +01:00
2008-12-02 12:01:29 +01:00
#include "cmakeproject.h"
#include "builddirmanager.h"
#include "cmakebuildconfiguration.h"
#include "cmakebuildstep.h"
#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"
#include "cmakefile.h"
#include "cmakeprojectmanager.h"
2008-12-02 14:09:21 +01:00
#include <coreplugin/icore.h>
#include <cpptools/cppmodelmanager.h>
#include <cpptools/projectinfo.h>
#include <cpptools/projectpartbuilder.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/buildtargetinfo.h>
#include <projectexplorer/deployconfiguration.h>
#include <projectexplorer/deploymentdata.h>
#include <projectexplorer/headerpath.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <qtsupport/baseqtversion.h>
#include <qtsupport/customexecutablerunconfiguration.h>
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/uicodemodelsupport.h>
#include <utils/algorithm.h>
2008-12-09 15:25:01 +01:00
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <utils/hostosinfo.h>
2008-12-02 14:09:21 +01:00
#include <QDir>
#include <QFileSystemWatcher>
#include <QTemporaryDir>
2008-12-02 12:01:29 +01:00
using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
using namespace ProjectExplorer;
using namespace Utils;
// QtCreator CMake Generator wishlist:
// Which make targets we need to build to get all executables
// What is the actual compiler executable
// DEFINES
// Open Questions
// Who sets up the environment for cl.exe ? INCLUDEPATH and so on
/*!
\class CMakeProject
*/
CMakeProject::CMakeProject(CMakeManager *manager, const FileName &fileName)
2008-12-02 12:01:29 +01:00
{
setId(Constants::CMAKEPROJECT_ID);
setProjectManager(manager);
setDocument(new CMakeFile(fileName));
setRootProjectNode(new CMakeProjectNode(fileName));
setProjectContext(Core::Context(CMakeProjectManager::Constants::PROJECTCONTEXT));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
rootProjectNode()->setDisplayName(fileName.parentDir().fileName());
connect(this, &CMakeProject::buildDirectoryDataAvailable, this, &CMakeProject::updateRunConfigurations);
connect(this, &Project::activeTargetChanged, this, &CMakeProject::activeTargetHasChanged);
connect(this, &CMakeProject::environmentChanged, this, [this]() {
BuildConfiguration *bc = nullptr;
if (activeTarget())
bc = activeTarget()->activeBuildConfiguration();
changeActiveBuildConfiguration(bc); // Does a clean reset of the builddirmanager
});
connect(this, &Project::addedTarget, this, [this](Target *t) {
connect(t, &Target::kitChanged, this, &CMakeProject::handleKitChanges);
});
}
CMakeProject::~CMakeProject()
{
setRootProjectNode(nullptr);
m_codeModelFuture.cancel();
delete m_buildDirManager;
}
void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
{
if (m_buildDirManager) {
m_buildDirManager->disconnect();
m_buildDirManager->deleteLater();
}
m_buildDirManager = nullptr;
Kit *k = nullptr;
CMakeConfig config;
Utils::FileName buildDir;
CMakeBuildConfiguration *cmakebc = qobject_cast<CMakeBuildConfiguration *>(bc);
if (!cmakebc) {
k = KitManager::defaultKit();
config = CMakeConfigurationKitInformation::configuration(k);
} else {
k = cmakebc->target()->kit();
config = cmakebc->cmakeConfiguration();
buildDir = cmakebc->buildDirectory();
}
if (k) {
m_buildDirManager = new Internal::BuildDirManager(projectDirectory(), k, config,
cmakebc->environment(), buildDir);
connect(m_buildDirManager, &BuildDirManager::parsingStarted,
this, &CMakeProject::parsingStarted);
connect(m_buildDirManager, &BuildDirManager::dataAvailable,
this, &CMakeProject::parseCMakeOutput);
connect(m_buildDirManager, &BuildDirManager::errorOccured,
cmakebc, &CMakeBuildConfiguration::setError);
}
}
void CMakeProject::activeTargetHasChanged(Target *target)
{
if (m_activeTarget) {
disconnect(m_activeTarget, &Target::activeBuildConfigurationChanged,
this, &CMakeProject::changeActiveBuildConfiguration);
}
m_activeTarget = target;
if (!m_activeTarget)
return;
connect(m_activeTarget, &Target::activeBuildConfigurationChanged,
this, &CMakeProject::changeActiveBuildConfiguration);
changeActiveBuildConfiguration(m_activeTarget->activeBuildConfiguration());
}
void CMakeProject::changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory)
{
bc->setBuildDirectory(FileName::fromString(newBuildDirectory));
if (activeTarget() && activeTarget()->activeBuildConfiguration() == bc)
changeActiveBuildConfiguration(bc);
}
void CMakeProject::handleKitChanges()
{
const Target *t = qobject_cast<Target *>(sender());
if (t && t != activeTarget())
return;
changeActiveBuildConfiguration(t->activeBuildConfiguration()); // force proper refresh
}
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)
{
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 =
cache.insert(buildTarget.title,
line.mid(11).trimmed().split(QLatin1Char(' '),
QString::SkipEmptyParts));
return true;
}
}
}
}
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;
// 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
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();
}
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);
}
} 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));
}
}
return !cache.isEmpty();
}
void CMakeProject::parseCMakeOutput()
{
QTC_ASSERT(m_buildDirManager, return);
QTC_ASSERT(activeTarget() && activeTarget()->activeBuildConfiguration(), return);
auto activeBC = static_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
rootProjectNode()->setDisplayName(m_buildDirManager->projectName());
buildTree(static_cast<CMakeProjectNode *>(rootProjectNode()), m_buildDirManager->files());
m_buildDirManager->clearFiles(); // Some of the FileNodes in files() were deleted!
updateApplicationAndDeploymentTargets();
createUiCodeModelSupport();
ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(m_buildDirManager->kit());
if (!tc) {
emit buildDirectoryDataAvailable(activeBC);
emit fileListChanged();
return;
}
CppTools::CppModelManager *modelmanager = CppTools::CppModelManager::instance();
CppTools::ProjectInfo pinfo(this);
CppTools::ProjectPartBuilder ppBuilder(pinfo);
CppTools::ProjectPart::QtVersion activeQtVersion = CppTools::ProjectPart::NoQt;
if (QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(m_buildDirManager->kit())) {
if (qtVersion->qtVersion() < QtSupport::QtVersionNumber(5,0,0))
activeQtVersion = CppTools::ProjectPart::Qt4;
else
activeQtVersion = CppTools::ProjectPart::Qt5;
}
ppBuilder.setQtVersion(activeQtVersion);
QHash<QString, QStringList> targetDataCache;
foreach (const CMakeBuildTarget &cbt, buildTargets()) {
// This explicitly adds -I. to the include paths
QStringList includePaths = cbt.includeFiles;
includePaths += projectDirectory().toString();
ppBuilder.setIncludePaths(includePaths);
QStringList cxxflags = getCXXFlagsFor(cbt, targetDataCache);
ppBuilder.setCFlags(cxxflags);
ppBuilder.setCxxFlags(cxxflags);
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
}
m_codeModelFuture.cancel();
pinfo.finish();
m_codeModelFuture = modelmanager->updateProjectInfo(pinfo);
emit displayNameChanged();
emit buildDirectoryDataAvailable(activeBC);
emit fileListChanged();
emit activeBC->emitBuildTypeChanged();
2008-12-02 12:01:29 +01:00
}
bool CMakeProject::needsConfiguration() const
{
return targets().isEmpty();
}
bool CMakeProject::requiresTargetPanel() const
{
return !targets().isEmpty();
}
bool CMakeProject::supportsKit(Kit *k, QString *errorMessage) const
{
if (!CMakeKitInformation::cmakeTool(k)) {
if (errorMessage)
*errorMessage = tr("No cmake tool set.");
return false;
}
return true;
}
void CMakeProject::runCMake()
{
if (m_buildDirManager && !m_buildDirManager->isBusy())
m_buildDirManager->forceReparse();
}
bool CMakeProject::isParsing() const
{
return m_buildDirManager && m_buildDirManager->isBusy();
}
QList<ConfigModel::DataItem> CMakeProject::currentCMakeConfiguration() const
{
if (!m_buildDirManager || m_buildDirManager->isBusy())
return QList<ConfigModel::DataItem>();
const QList<CMakeConfigItem> cmakeItems = m_buildDirManager->configuration();
return Utils::transform(cmakeItems, [](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 CMakeProject::setCurrentCMakeConfiguration(const QList<ConfigModel::DataItem> &items)
{
if (!m_buildDirManager || m_buildDirManager->isBusy())
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:
QTC_ASSERT(activeTarget(), return);
QTC_ASSERT(activeTarget()->activeBuildConfiguration(), return);
auto bc = static_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
QTC_ASSERT(bc, return);
const CMakeConfig config = bc->cmakeConfiguration() + newConfig;
bc->setCMakeConfiguration(config);
m_buildDirManager->setInputConfiguration(config);
}
bool CMakeProject::isProjectFile(const FileName &fileName)
{
if (!m_buildDirManager)
return false;
return m_buildDirManager->isProjectFile(fileName);
}
QList<CMakeBuildTarget> CMakeProject::buildTargets() const
{
if (!m_buildDirManager)
return QList<CMakeBuildTarget>();
return m_buildDirManager->buildTargets();
}
QStringList CMakeProject::buildTargetTitles(bool runnable) const
2008-12-02 12:01:29 +01:00
{
const QList<CMakeBuildTarget> targets
= runnable ? Utils::filtered(buildTargets(),
[](const CMakeBuildTarget &ct) {
return !ct.executable.isEmpty() && ct.targetType == ExecutableType;
})
: buildTargets();
return Utils::transform(targets, [](const CMakeBuildTarget &ct) { return ct.title; });
2008-12-02 12:01:29 +01:00
}
bool CMakeProject::hasBuildTarget(const QString &title) const
{
return Utils::anyOf(buildTargets(), [title](const CMakeBuildTarget &ct) { return ct.title == title; });
}
void CMakeProject::gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list) const
2008-12-02 12:01:29 +01:00
{
foreach (ProjectExplorer::FolderNode *folder, parent->subFolderNodes())
gatherFileNodes(folder, list);
foreach (ProjectExplorer::FileNode *file, parent->fileNodes())
list.append(file);
}
bool sortNodesByPath(Node *a, Node *b)
{
return a->filePath() < b->filePath();
}
void CMakeProject::buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> newList)
{
// Gather old list
QList<ProjectExplorer::FileNode *> oldList;
gatherFileNodes(rootNode, oldList);
Utils::sort(oldList, sortNodesByPath);
Utils::sort(newList, sortNodesByPath);
QList<ProjectExplorer::FileNode *> added;
QList<ProjectExplorer::FileNode *> deleted;
ProjectExplorer::compareSortedLists(oldList, newList, deleted, added, sortNodesByPath);
qDeleteAll(ProjectExplorer::subtractSortedList(newList, added, sortNodesByPath));
// add added nodes
foreach (ProjectExplorer::FileNode *fn, added) {
2008-12-02 12:01:29 +01:00
// Get relative path to rootNode
QString parentDir = fn->filePath().toFileInfo().absolutePath();
2008-12-02 12:01:29 +01:00
ProjectExplorer::FolderNode *folder = findOrCreateFolder(rootNode, parentDir);
folder->addFileNodes(QList<ProjectExplorer::FileNode *>()<< fn);
2008-12-02 12:01:29 +01:00
}
2010-01-11 10:22:55 +01:00
// remove old file nodes and check whether folder nodes can be removed
foreach (ProjectExplorer::FileNode *fn, deleted) {
ProjectExplorer::FolderNode *parent = fn->parentFolderNode();
parent->removeFileNodes(QList<ProjectExplorer::FileNode *>() << fn);
// Check for empty parent
while (parent->subFolderNodes().isEmpty() && parent->fileNodes().isEmpty()) {
ProjectExplorer::FolderNode *grandparent = parent->parentFolderNode();
grandparent->removeFolderNodes(QList<ProjectExplorer::FolderNode *>() << parent);
parent = grandparent;
if (parent == rootNode)
break;
}
}
2008-12-02 12:01:29 +01:00
}
ProjectExplorer::FolderNode *CMakeProject::findOrCreateFolder(CMakeProjectNode *rootNode, QString directory)
{
FileName path = rootNode->filePath().parentDir();
QDir rootParentDir(path.toString());
QString relativePath = rootParentDir.relativeFilePath(directory);
if (relativePath == QLatin1String("."))
relativePath.clear();
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) {
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()) {
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
auto tmp = new ProjectExplorer::FolderNode(path);
tmp->setDisplayName(part);
parent->addFolderNodes(QList<ProjectExplorer::FolderNode *>() << tmp);
2008-12-02 12:01:29 +01:00
parent = tmp;
}
}
return parent;
}
QString CMakeProject::displayName() const
2008-12-02 12:01:29 +01:00
{
return rootProjectNode()->displayName();
2008-12-02 12:01:29 +01:00
}
QStringList CMakeProject::files(FilesMode fileMode) const
{
QStringList result;
if (m_buildDirManager) {
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;
}
});
result = Utils::transform(nodes, [fileMode](const FileNode* fn) { return fn->filePath().toString(); });
}
return result;
2008-12-02 12:01:29 +01:00
}
Project::RestoreResult CMakeProject::fromMap(const QVariantMap &map, QString *errorMessage)
2008-12-02 12:01:29 +01:00
{
RestoreResult result = Project::fromMap(map, errorMessage);
if (result != RestoreResult::Ok)
return result;
2008-12-02 12:01:29 +01:00
m_activeTarget = activeTarget();
if (m_activeTarget) {
connect(m_activeTarget, &Target::activeBuildConfigurationChanged,
this, &CMakeProject::changeActiveBuildConfiguration);
if (BuildConfiguration *bc = m_activeTarget->activeBuildConfiguration())
changeActiveBuildConfiguration(bc);
}
return RestoreResult::Ok;
2008-12-02 12:01:29 +01:00
}
bool CMakeProject::setupTarget(Target *t)
{
t->updateDefaultBuildConfigurations();
if (t->buildConfigurations().isEmpty())
return false;
t->updateDefaultDeployConfigurations();
return true;
}
CMakeBuildTarget CMakeProject::buildTargetForTitle(const QString &title)
{
foreach (const CMakeBuildTarget &ct, buildTargets())
if (ct.title == title)
return ct;
return CMakeBuildTarget();
}
QString CMakeProject::uiHeaderFile(const QString &uiFile)
{
if (!activeTarget())
return QString();
QFileInfo fi(uiFile);
FileName project = projectDirectory();
FileName baseDirectory = FileName::fromString(fi.absolutePath());
while (baseDirectory.isChildOf(project)) {
FileName cmakeListsTxt = baseDirectory;
cmakeListsTxt.appendPath(QLatin1String("CMakeLists.txt"));
if (cmakeListsTxt.exists())
break;
QDir dir(baseDirectory.toString());
dir.cdUp();
baseDirectory = FileName::fromString(dir.absolutePath());
}
QDir srcDirRoot = QDir(project.toString());
QString relativePath = srcDirRoot.relativeFilePath(baseDirectory.toString());
QDir buildDir = QDir(activeTarget()->activeBuildConfiguration()->buildDirectory().toString());
QString uiHeaderFilePath = buildDir.absoluteFilePath(relativePath);
uiHeaderFilePath += QLatin1String("/ui_");
uiHeaderFilePath += fi.completeBaseName();
uiHeaderFilePath += QLatin1String(".h");
return QDir::cleanPath(uiHeaderFilePath);
}
void CMakeProject::updateRunConfigurations()
{
foreach (Target *t, targets())
updateTargetRunConfigurations(t);
}
// TODO Compare with updateDefaultRunConfigurations();
void CMakeProject::updateTargetRunConfigurations(Target *t)
{
// create new and remove obsolete RCs using the factories
t->updateDefaultRunConfigurations();
// *Update* runconfigurations:
QMultiMap<QString, CMakeRunConfiguration*> existingRunConfigurations;
foreach (ProjectExplorer::RunConfiguration *rc, t->runConfigurations()) {
if (CMakeRunConfiguration* cmakeRC = qobject_cast<CMakeRunConfiguration *>(rc))
existingRunConfigurations.insert(cmakeRC->title(), cmakeRC);
}
foreach (const CMakeBuildTarget &ct, buildTargets()) {
if (ct.targetType != ExecutableType)
continue;
if (ct.executable.isEmpty())
continue;
QList<CMakeRunConfiguration *> list = existingRunConfigurations.values(ct.title);
if (!list.isEmpty()) {
// Already exists, so override the settings...
foreach (CMakeRunConfiguration *rc, list) {
rc->setExecutable(ct.executable);
rc->setBaseWorkingDirectory(ct.workingDirectory);
rc->setEnabled(true);
}
}
}
if (t->runConfigurations().isEmpty()) {
// Oh no, no run configuration,
// create a custom executable run configuration
t->addRunConfiguration(new QtSupport::CustomExecutableRunConfiguration(t));
}
}
void CMakeProject::updateApplicationAndDeploymentTargets()
{
Target *t = activeTarget();
if (!t)
return;
QFile deploymentFile;
QTextStream deploymentStream;
QString deploymentPrefix;
QDir sourceDir(t->project()->projectDirectory().toString());
QDir buildDir(t->activeBuildConfiguration()->buildDirectory().toString());
deploymentFile.setFileName(sourceDir.filePath(QLatin1String("QtCreatorDeployment.txt")));
// 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")));
if (deploymentFile.open(QFile::ReadOnly | QFile::Text)) {
deploymentStream.setDevice(&deploymentFile);
deploymentPrefix = deploymentStream.readLine();
if (!deploymentPrefix.endsWith(QLatin1Char('/')))
deploymentPrefix.append(QLatin1Char('/'));
}
BuildTargetInfoList appTargetList;
DeploymentData deploymentData;
foreach (const CMakeBuildTarget &ct, buildTargets()) {
if (ct.executable.isEmpty())
continue;
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) {
// TODO: Put a path to corresponding .cbp file into projectFilePath?
appTargetList.list << BuildTargetInfo(ct.title,
FileName::fromString(ct.executable),
FileName::fromString(ct.executable));
}
}
QString absoluteSourcePath = sourceDir.absolutePath();
if (!absoluteSourcePath.endsWith(QLatin1Char('/')))
absoluteSourcePath.append(QLatin1Char('/'));
if (deploymentStream.device()) {
while (!deploymentStream.atEnd()) {
QString line = deploymentStream.readLine();
if (!line.contains(QLatin1Char(':')))
continue;
QStringList file = line.split(QLatin1Char(':'));
deploymentData.addFile(absoluteSourcePath + file.at(0), deploymentPrefix + file.at(1));
}
}
t->setApplicationTargets(appTargetList);
t->setDeploymentData(deploymentData);
}
void CMakeProject::createUiCodeModelSupport()
{
QHash<QString, QString> uiFileHash;
// Find all ui files
foreach (const QString &uiFile, files(SourceFiles)) {
if (uiFile.endsWith(QLatin1String(".ui")))
uiFileHash.insert(uiFile, uiHeaderFile(uiFile));
}
QtSupport::UiCodeModelManager::update(this, uiFileHash);
}
void CMakeBuildTarget::clear()
{
executable.clear();
makeCommand.clear();
makeCleanCommand.clear();
workingDirectory.clear();
sourceDirectory.clear();
title.clear();
targetType = ExecutableType;
includeFiles.clear();
compilerOptions.clear();
defines.clear();
}