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

769 lines
28 KiB
C++
Raw Normal View History

/****************************************************************************
2008-12-02 12:01:29 +01:00
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
2010-12-17 16:01:08 +01:00
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
2008-12-02 14:09:21 +01:00
2008-12-02 12:01:29 +01:00
#include "cmakeproject.h"
#include "cmakebuildconfiguration.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 "makestep.h"
#include "cmakeopenprojectwizard.h"
#include "cmakecbpparser.h"
#include "cmakefile.h"
#include "cmakeprojectmanager.h"
2008-12-02 14:09:21 +01:00
#include <projectexplorer/projectexplorerconstants.h>
2011-02-28 16:50:14 +01:00
#include <projectexplorer/headerpath.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/buildtargetinfo.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/deployconfiguration.h>
#include <projectexplorer/deploymentdata.h>
#include <qtsupport/customexecutablerunconfiguration.h>
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/uicodemodelsupport.h>
#include <cpptools/cppmodelmanager.h>
#include <extensionsystem/pluginmanager.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>
#include <coreplugin/icore.h>
#include <coreplugin/infobar.h>
#include <coreplugin/editormanager/editormanager.h>
2008-12-02 14:09:21 +01:00
#include <QDebug>
#include <QDir>
#include <QFileSystemWatcher>
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 make we need to call
// 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)
: m_manager(manager),
m_activeTarget(0),
m_fileName(fileName),
m_rootNode(new CMakeProjectNode(fileName)),
m_watcher(new QFileSystemWatcher(this))
2008-12-02 12:01:29 +01:00
{
setId(Constants::CMAKEPROJECT_ID);
setProjectContext(Core::Context(CMakeProjectManager::Constants::PROJECTCONTEXT));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
m_projectName = fileName.parentDir().fileName();
2008-12-02 12:01:29 +01:00
m_file = new CMakeFile(this, fileName);
connect(this, SIGNAL(buildTargetsChanged()),
this, SLOT(updateRunConfigurations()));
connect(m_watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString)));
}
CMakeProject::~CMakeProject()
{
m_codeModelFuture.cancel();
delete m_rootNode;
}
void CMakeProject::fileChanged(const QString &fileName)
2009-11-26 14:43:27 +01:00
{
Q_UNUSED(fileName)
2009-11-26 14:43:27 +01:00
parseCMakeLists();
}
void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
{
if (!bc)
return;
CMakeBuildConfiguration *cmakebc = static_cast<CMakeBuildConfiguration *>(bc);
// Pop up a dialog asking the user to rerun cmake
QString cbpFile = CMakeManager::findCbpFile(QDir(bc->buildDirectory().toString()));
QFileInfo cbpFileFi(cbpFile);
CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing;
if (!cbpFileFi.exists()) {
mode = CMakeOpenProjectWizard::NeedToCreate;
} else {
foreach (const FileName &file, m_watchedFiles) {
if (file.toFileInfo().lastModified() > cbpFileFi.lastModified()) {
mode = CMakeOpenProjectWizard::NeedToUpdate;
break;
}
}
}
if (mode != CMakeOpenProjectWizard::Nothing) {
CMakeBuildInfo info(cmakebc);
CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, mode, &info);
if (copw.exec() == QDialog::Accepted)
cmakebc->setUseNinja(copw.useNinja()); // NeedToCreate can change the Ninja setting
}
// reparse
parseCMakeLists();
}
void CMakeProject::activeTargetWasChanged(Target *target)
{
if (m_activeTarget) {
disconnect(m_activeTarget, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
this, SLOT(changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
}
m_activeTarget = target;
if (!m_activeTarget)
return;
connect(m_activeTarget, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
this, SLOT(changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
changeActiveBuildConfiguration(m_activeTarget->activeBuildConfiguration());
}
void CMakeProject::changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory)
{
bc->setBuildDirectory(FileName::fromString(newBuildDirectory));
parseCMakeLists();
}
QStringList CMakeProject::getCXXFlagsFor(const CMakeBuildTarget &buildTarget)
{
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 =
return line.mid(11).trimmed().split(QLatin1Char(' '), QString::SkipEmptyParts);
}
}
}
}
// 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
if (!buildTargets().empty()) {
QString buildNinjaFile = QDir::fromNativeSeparators(buildTargets().at(0).workingDirectory);
buildNinjaFile += QLatin1String("/build.ninja");
QFile buildNinja(buildNinjaFile);
if (buildNinja.exists()) {
buildNinja.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream stream(&buildNinja);
bool targetFound = false;
bool cxxFound = false;
QString targetSearchPattern = QString::fromLatin1("target %1").arg(buildTarget.title);
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(QLatin1String("#"))) {
if (!line.startsWith(QLatin1String("# Object build statements for"))) continue;
targetFound = line.endsWith(targetSearchPattern);
} else if (targetFound && line.startsWith(QLatin1String("build"))) {
cxxFound = line.indexOf(QLatin1String("CXX_COMPILER")) != -1;
} else if (cxxFound && line.startsWith(QLatin1String("FLAGS ="))) {
// Skip past =
return line.mid(7).trimmed().split(QLatin1Char(' '), QString::SkipEmptyParts);
}
}
}
}
return QStringList();
}
bool CMakeProject::parseCMakeLists()
{
if (!activeTarget() ||
!activeTarget()->activeBuildConfiguration()) {
return false;
}
CMakeBuildConfiguration *activeBC = static_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments())
if (isProjectFile(document->filePath()))
document->infoBar()->removeInfo("CMakeEditor.RunCMake");
// Find cbp file
QString cbpFile = CMakeManager::findCbpFile(activeBC->buildDirectory().toString());
if (cbpFile.isEmpty()) {
emit buildTargetsChanged();
return false;
}
Kit *k = activeTarget()->kit();
// setFolderName
m_rootNode->setDisplayName(QFileInfo(cbpFile).completeBaseName());
CMakeCbpParser cbpparser;
// Parsing
//qDebug()<<"Parsing file "<<cbpFile;
if (!cbpparser.parseCbpFile(k,cbpFile, projectDirectory().toString())) {
2010-02-02 12:03:50 +01:00
// TODO report error
emit buildTargetsChanged();
return false;
2010-02-02 12:03:50 +01:00
}
foreach (const QString &file, m_watcher->files())
if (file != cbpFile)
m_watcher->removePath(file);
// how can we ensure that it is completely written?
m_watcher->addPath(cbpFile);
2010-02-02 12:03:50 +01:00
m_projectName = cbpparser.projectName();
m_rootNode->setDisplayName(cbpparser.projectName());
2010-02-02 12:03:50 +01:00
//qDebug()<<"Building Tree";
QList<ProjectExplorer::FileNode *> fileList = cbpparser.fileList();
QSet<FileName> projectFiles;
2010-02-02 12:03:50 +01:00
if (cbpparser.hasCMakeFiles()) {
fileList.append(cbpparser.cmakeFileList());
foreach (const ProjectExplorer::FileNode *node, cbpparser.cmakeFileList())
2010-02-02 12:03:50 +01:00
projectFiles.insert(node->path());
} else {
// Manually add the CMakeLists.txt file
FileName cmakeListTxt = projectDirectory().appendPath(QLatin1String("CMakeLists.txt"));
bool generated = false;
fileList.append(new ProjectExplorer::FileNode(cmakeListTxt, ProjectExplorer::ProjectFileType, generated));
2010-02-02 12:03:50 +01:00
projectFiles.insert(cmakeListTxt);
}
2010-02-02 12:03:50 +01:00
m_watchedFiles = projectFiles;
2010-02-02 12:03:50 +01:00
m_files.clear();
foreach (ProjectExplorer::FileNode *fn, fileList)
m_files.append(fn->path().toString());
2010-02-02 12:03:50 +01:00
m_files.sort();
2008-12-02 12:01:29 +01:00
2010-02-02 12:03:50 +01:00
buildTree(m_rootNode, fileList);
2010-02-02 12:03:50 +01:00
//qDebug()<<"Adding Targets";
m_buildTargets = cbpparser.buildTargets();
// qDebug()<<"Printing targets";
// foreach (CMakeBuildTarget ct, m_buildTargets) {
// qDebug()<<ct.title<<" with executable:"<<ct.executable;
// qDebug()<<"WD:"<<ct.workingDirectory;
// qDebug()<<ct.makeCommand<<ct.makeCleanCommand;
// qDebug()<<"";
// }
updateApplicationAndDeploymentTargets();
createUiCodeModelSupport();
ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k);
if (!tc) {
emit buildTargetsChanged();
emit fileListChanged();
return true;
}
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(k)) {
if (qtVersion->qtVersion() < QtSupport::QtVersionNumber(5,0,0))
activeQtVersion = CppTools::ProjectPart::Qt4;
else
activeQtVersion = CppTools::ProjectPart::Qt5;
}
ppBuilder.setQtVersion(activeQtVersion);
foreach (const CMakeBuildTarget &cbt, m_buildTargets) {
// This explicitly adds -I. to the include paths
QStringList includePaths = cbt.includeFiles;
includePaths += projectDirectory().toString();
ppBuilder.setIncludePaths(includePaths);
ppBuilder.setCFlags(getCXXFlagsFor(cbt));
ppBuilder.setCxxFlags(getCXXFlagsFor(cbt));
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 buildTargetsChanged();
emit fileListChanged();
emit activeBC->emitBuildTypeChanged();
return true;
2008-12-02 12:01:29 +01:00
}
bool CMakeProject::isProjectFile(const FileName &fileName)
{
return m_watchedFiles.contains(fileName);
}
QList<CMakeBuildTarget> CMakeProject::buildTargets() const
{
return m_buildTargets;
}
QStringList CMakeProject::buildTargetTitles(bool runnable) const
2008-12-02 12:01:29 +01:00
{
QStringList results;
foreach (const CMakeBuildTarget &ct, m_buildTargets) {
if (runnable && (ct.executable.isEmpty() || ct.targetType != ExecutableType))
continue;
results << ct.title;
}
return results;
2008-12-02 12:01:29 +01:00
}
bool CMakeProject::hasBuildTarget(const QString &title) const
{
foreach (const CMakeBuildTarget &ct, m_buildTargets) {
if (ct.title == title)
return true;
}
return false;
}
void CMakeProject::gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list)
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->path() < b->path();
}
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) {
// qDebug()<<"added"<<fn->path();
2008-12-02 12:01:29 +01:00
// Get relative path to rootNode
QString parentDir = fn->path().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();
// qDebug()<<"removed"<<fn->path();
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->path().parentDir();
QDir rootParentDir(path.toString());
QString relativePath = rootParentDir.relativeFilePath(directory);
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->path() == 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
ProjectExplorer::FolderNode *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 m_projectName;
2008-12-02 12:01:29 +01:00
}
Core::IDocument *CMakeProject::document() const
2008-12-02 12:01:29 +01:00
{
return m_file;
}
IProjectManager *CMakeProject::projectManager() const
2008-12-02 12:01:29 +01:00
{
return m_manager;
}
ProjectExplorer::ProjectNode *CMakeProject::rootProjectNode() const
{
return m_rootNode;
}
QStringList CMakeProject::files(FilesMode fileMode) const
{
Q_UNUSED(fileMode)
2008-12-02 12:01:29 +01:00
return m_files;
}
bool CMakeProject::fromMap(const QVariantMap &map)
2008-12-02 12:01:29 +01:00
{
if (!Project::fromMap(map))
return false;
2008-12-02 12:01:29 +01:00
bool hasUserFile = activeTarget();
if (!hasUserFile) {
CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, projectDirectory().toString(), Environment::systemEnvironment());
if (copw.exec() != QDialog::Accepted)
return false;
Kit *k = copw.kit();
Target *t = new Target(this, k);
CMakeBuildConfiguration *bc(new CMakeBuildConfiguration(t));
bc->setDefaultDisplayName(QLatin1String("all"));
bc->setUseNinja(copw.useNinja());
bc->setBuildDirectory(FileName::fromString(copw.buildDirectory()));
ProjectExplorer::BuildStepList *buildSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
ProjectExplorer::BuildStepList *cleanSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
// Now create a standard build configuration
buildSteps->insertStep(0, new MakeStep(buildSteps));
MakeStep *cleanMakeStep = new MakeStep(cleanSteps);
cleanSteps->insertStep(0, cleanMakeStep);
cleanMakeStep->setAdditionalArguments(QLatin1String("clean"));
cleanMakeStep->setClean(true);
t->addBuildConfiguration(bc);
t->updateDefaultDeployConfigurations();
addTarget(t);
} else {
// We have a user file, but we could still be missing the cbp file
// or simply run createXml with the saved settings
CMakeBuildConfiguration *activeBC = qobject_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
if (!activeBC)
return false;
QString cbpFile = CMakeManager::findCbpFile(QDir(activeBC->buildDirectory().toString()));
QFileInfo cbpFileFi(cbpFile);
CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing;
if (!cbpFileFi.exists())
mode = CMakeOpenProjectWizard::NeedToCreate;
else if (cbpFileFi.lastModified() < m_fileName.toFileInfo().lastModified())
mode = CMakeOpenProjectWizard::NeedToUpdate;
if (mode != CMakeOpenProjectWizard::Nothing) {
CMakeBuildInfo info(activeBC);
CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, mode, &info);
if (copw.exec() != QDialog::Accepted)
return false;
else
activeBC->setUseNinja(copw.useNinja());
}
}
parseCMakeLists();
m_activeTarget = activeTarget();
if (m_activeTarget)
connect(m_activeTarget, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
this, SLOT(changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
connect(this, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
this, SLOT(activeTargetWasChanged(ProjectExplorer::Target*)));
return true;
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, m_buildTargets)
if (ct.title == title)
return ct;
return CMakeBuildTarget();
}
QString CMakeProject::uiHeaderFile(const QString &uiFile)
{
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())
updateRunConfigurations(t);
}
// TODO Compare with updateDefaultRunConfigurations();
void CMakeProject::updateRunConfigurations(Target *t)
{
// *Update* runconfigurations:
QMultiMap<QString, CMakeRunConfiguration*> existingRunConfigurations;
QList<ProjectExplorer::RunConfiguration *> toRemove;
foreach (ProjectExplorer::RunConfiguration *rc, t->runConfigurations()) {
if (CMakeRunConfiguration* cmakeRC = qobject_cast<CMakeRunConfiguration *>(rc))
existingRunConfigurations.insert(cmakeRC->title(), cmakeRC);
QtSupport::CustomExecutableRunConfiguration *ceRC =
qobject_cast<QtSupport::CustomExecutableRunConfiguration *>(rc);
if (ceRC && !ceRC->isConfigured())
toRemove << rc;
}
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);
}
existingRunConfigurations.remove(ct.title);
} else {
// Does not exist yet
Core::Id id = CMakeRunConfigurationFactory::idFromBuildTarget(ct.title);
CMakeRunConfiguration *rc = new CMakeRunConfiguration(t, id, ct.executable,
ct.workingDirectory, ct.title);
t->addRunConfiguration(rc);
}
}
QMultiMap<QString, CMakeRunConfiguration *>::const_iterator it =
existingRunConfigurations.constBegin();
for ( ; it != existingRunConfigurations.constEnd(); ++it) {
CMakeRunConfiguration *rc = it.value();
// The executables for those runconfigurations aren't build by the current buildconfiguration
// We just set a disable flag and show that in the display name
rc->setEnabled(false);
// removeRunConfiguration(rc);
}
foreach (ProjectExplorer::RunConfiguration *rc, toRemove)
t->removeRunConfiguration(rc);
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();
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, m_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, m_files) {
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();
}