2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** 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.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** 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.
|
|
|
|
|
**
|
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-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"
|
2009-03-09 18:13:19 +01:00
|
|
|
#include "cmakeopenprojectwizard.h"
|
2015-03-10 10:22:38 +01:00
|
|
|
#include "cmakecbpparser.h"
|
|
|
|
|
#include "cmakefile.h"
|
|
|
|
|
#include "cmakeprojectmanager.h"
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2009-02-16 13:12:12 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2011-02-28 16:50:14 +01:00
|
|
|
#include <projectexplorer/headerpath.h>
|
2010-07-16 14:00:41 +02:00
|
|
|
#include <projectexplorer/buildsteplist.h>
|
2010-09-24 13:17:43 +02:00
|
|
|
#include <projectexplorer/buildmanager.h>
|
2013-07-07 23:49:13 +02:00
|
|
|
#include <projectexplorer/buildtargetinfo.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/kitmanager.h>
|
2010-11-01 14:14:17 +01:00
|
|
|
#include <projectexplorer/toolchain.h>
|
2015-03-10 10:22:38 +01:00
|
|
|
|
2012-10-02 17:46:19 +02:00
|
|
|
#include <projectexplorer/deployconfiguration.h>
|
2013-07-07 23:49:13 +02:00
|
|
|
#include <projectexplorer/deploymentdata.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <qtsupport/customexecutablerunconfiguration.h>
|
2013-01-17 15:12:46 +01:00
|
|
|
#include <qtsupport/baseqtversion.h>
|
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2013-07-09 16:41:57 +02:00
|
|
|
#include <qtsupport/uicodemodelsupport.h>
|
2014-09-15 00:12:27 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2016-01-12 12:51:33 +01:00
|
|
|
#include <cpptools/projectinfo.h>
|
|
|
|
|
#include <cpptools/projectpartbuilder.h>
|
2009-01-23 16:57:38 +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>
|
2009-01-23 16:57:38 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2011-05-06 12:48:44 +02:00
|
|
|
#include <coreplugin/infobar.h>
|
2010-09-24 13:17:43 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDir>
|
2012-03-26 17:31:04 +04:00
|
|
|
#include <QFileSystemWatcher>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace CMakeProjectManager;
|
|
|
|
|
using namespace CMakeProjectManager::Internal;
|
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
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
2009-09-24 16:02:02 +02:00
|
|
|
/*!
|
|
|
|
|
\class CMakeProject
|
|
|
|
|
*/
|
2016-01-08 11:31:06 +01:00
|
|
|
CMakeProject::CMakeProject(CMakeManager *manager, const FileName &fileName) :
|
|
|
|
|
m_watcher(new QFileSystemWatcher(this))
|
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-01-08 11:09:37 +01:00
|
|
|
setDocument(new CMakeFile(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-01-08 12:49:00 +01:00
|
|
|
rootProjectNode()->setDisplayName(fileName.parentDir().fileName());
|
2013-06-25 17:17:20 +02:00
|
|
|
|
2016-01-08 14:29:36 +01:00
|
|
|
connect(this, &CMakeProject::buildTargetsChanged, this, &CMakeProject::updateRunConfigurations);
|
|
|
|
|
connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &CMakeProject::fileChanged);
|
2009-01-12 15:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeProject::~CMakeProject()
|
|
|
|
|
{
|
2010-04-22 18:57:43 +02:00
|
|
|
m_codeModelFuture.cancel();
|
2009-01-12 15:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
void CMakeProject::fileChanged(const QString &fileName)
|
2009-11-26 14:43:27 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
Q_UNUSED(fileName)
|
2009-11-26 14:43:27 +01:00
|
|
|
|
2012-07-17 15:56:43 +02:00
|
|
|
parseCMakeLists();
|
2009-09-24 16:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
|
2009-05-18 18:07:52 +02:00
|
|
|
{
|
2012-10-16 17:19:59 +02:00
|
|
|
if (!bc)
|
2010-02-08 15:50:06 +01:00
|
|
|
return;
|
|
|
|
|
|
2012-07-13 17:41:05 +02:00
|
|
|
CMakeBuildConfiguration *cmakebc = static_cast<CMakeBuildConfiguration *>(bc);
|
2009-12-03 19:45:09 +01:00
|
|
|
|
2009-05-18 18:07:52 +02:00
|
|
|
// Pop up a dialog asking the user to rerun cmake
|
2013-08-16 17:45:16 +02:00
|
|
|
QString cbpFile = CMakeManager::findCbpFile(QDir(bc->buildDirectory().toString()));
|
2009-05-18 18:07:52 +02:00
|
|
|
QFileInfo cbpFileFi(cbpFile);
|
2009-09-14 16:09:17 +02:00
|
|
|
CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing;
|
|
|
|
|
if (!cbpFileFi.exists()) {
|
2009-05-26 15:50:27 +02:00
|
|
|
mode = CMakeOpenProjectWizard::NeedToCreate;
|
2009-09-14 16:09:17 +02:00
|
|
|
} else {
|
2015-02-02 00:37:38 +02:00
|
|
|
foreach (const FileName &file, m_watchedFiles) {
|
|
|
|
|
if (file.toFileInfo().lastModified() > cbpFileFi.lastModified()) {
|
2009-09-14 16:09:17 +02:00
|
|
|
mode = CMakeOpenProjectWizard::NeedToUpdate;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-05-18 18:07:52 +02:00
|
|
|
|
2009-05-26 15:50:27 +02:00
|
|
|
if (mode != CMakeOpenProjectWizard::Nothing) {
|
2013-07-22 15:53:57 +02:00
|
|
|
CMakeBuildInfo info(cmakebc);
|
2016-01-07 17:30:49 +01:00
|
|
|
CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), mode, &info);
|
2016-01-07 13:19:29 +01:00
|
|
|
if (copw.exec() == QDialog::Accepted)
|
2015-09-10 16:17:38 +02:00
|
|
|
cmakebc->setInitialArguments(QString());
|
2009-05-18 18:07:52 +02:00
|
|
|
}
|
2012-10-02 17:46:19 +02:00
|
|
|
|
2009-05-18 18:07:52 +02:00
|
|
|
// reparse
|
2012-07-17 15:56:43 +02:00
|
|
|
parseCMakeLists();
|
2009-05-18 18:07:52 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-16 17:19:59 +02:00
|
|
|
void CMakeProject::activeTargetWasChanged(Target *target)
|
2009-03-26 17:36:58 +01:00
|
|
|
{
|
2012-10-16 17:19:59 +02:00
|
|
|
if (m_activeTarget) {
|
2016-01-08 14:29:36 +01:00
|
|
|
disconnect(m_activeTarget, &Target::activeBuildConfigurationChanged,
|
|
|
|
|
this, &CMakeProject::changeActiveBuildConfiguration);
|
2012-10-16 17:19:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_activeTarget = target;
|
|
|
|
|
|
|
|
|
|
if (!m_activeTarget)
|
2009-03-26 17:36:58 +01:00
|
|
|
return;
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2016-01-08 14:29:36 +01:00
|
|
|
connect(m_activeTarget, &Target::activeBuildConfigurationChanged,
|
|
|
|
|
this, &CMakeProject::changeActiveBuildConfiguration);
|
2012-10-16 17:19:59 +02:00
|
|
|
changeActiveBuildConfiguration(m_activeTarget->activeBuildConfiguration());
|
2009-03-26 17:36:58 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-03 19:45:09 +01:00
|
|
|
void CMakeProject::changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory)
|
2009-04-20 14:35:25 +02:00
|
|
|
{
|
2015-02-01 18:44:47 +02:00
|
|
|
bc->setBuildDirectory(FileName::fromString(newBuildDirectory));
|
2012-07-17 15:56:43 +02:00
|
|
|
parseCMakeLists();
|
2009-04-20 14:35:25 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-20 12:32:54 +02:00
|
|
|
QStringList CMakeProject::getCXXFlagsFor(const CMakeBuildTarget &buildTarget, QByteArray *cachedBuildNinja)
|
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 =
|
|
|
|
|
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
|
2015-04-20 15:59:18 +02:00
|
|
|
if (!buildTargets().empty()) {
|
2015-07-20 12:32:54 +02:00
|
|
|
if (cachedBuildNinja->isNull()) {
|
|
|
|
|
QString buildNinjaFile = QDir::fromNativeSeparators(buildTargets().at(0).workingDirectory);
|
|
|
|
|
buildNinjaFile += QLatin1String("/build.ninja");
|
|
|
|
|
QFile buildNinja(buildNinjaFile);
|
|
|
|
|
if (buildNinja.exists()) {
|
|
|
|
|
buildNinja.open(QIODevice::ReadOnly | QIODevice::Text);
|
|
|
|
|
*cachedBuildNinja = buildNinja.readAll();
|
|
|
|
|
buildNinja.close();
|
|
|
|
|
} else {
|
|
|
|
|
*cachedBuildNinja = QByteArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-20 15:59:18 +02:00
|
|
|
|
2015-07-20 12:32:54 +02:00
|
|
|
if (cachedBuildNinja->isEmpty())
|
|
|
|
|
return QStringList();
|
|
|
|
|
|
|
|
|
|
QTextStream stream(cachedBuildNinja);
|
|
|
|
|
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);
|
2014-07-17 19:02:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-20 12:32:54 +02:00
|
|
|
|
2014-07-17 19:02:54 +02:00
|
|
|
}
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-17 15:56:43 +02:00
|
|
|
bool CMakeProject::parseCMakeLists()
|
2009-01-12 15:10:33 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
if (!activeTarget() ||
|
2012-04-24 15:49:09 +02:00
|
|
|
!activeTarget()->activeBuildConfiguration()) {
|
2012-07-17 15:56:43 +02:00
|
|
|
return false;
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2012-07-17 15:56:43 +02:00
|
|
|
CMakeBuildConfiguration *activeBC = static_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
|
2014-05-07 16:25:04 +02:00
|
|
|
foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments())
|
2015-02-02 00:37:38 +02:00
|
|
|
if (isProjectFile(document->filePath()))
|
2013-09-03 11:42:35 +02:00
|
|
|
document->infoBar()->removeInfo("CMakeEditor.RunCMake");
|
2011-03-31 17:43:48 +02:00
|
|
|
|
2009-03-26 17:36:58 +01:00
|
|
|
// Find cbp file
|
2013-08-16 17:45:16 +02:00
|
|
|
QString cbpFile = CMakeManager::findCbpFile(activeBC->buildDirectory().toString());
|
2009-03-26 17:36:58 +01:00
|
|
|
|
2011-11-16 14:15:54 +01:00
|
|
|
if (cbpFile.isEmpty()) {
|
|
|
|
|
emit buildTargetsChanged();
|
2012-07-17 15:56:43 +02:00
|
|
|
return false;
|
2011-11-16 14:15:54 +01:00
|
|
|
}
|
|
|
|
|
|
2015-03-10 15:47:09 +01:00
|
|
|
Kit *k = activeTarget()->kit();
|
|
|
|
|
|
2009-03-26 17:36:58 +01:00
|
|
|
// setFolderName
|
2016-01-08 12:49:00 +01:00
|
|
|
rootProjectNode()->setDisplayName(QFileInfo(cbpFile).completeBaseName());
|
2008-12-02 17:56:21 +01:00
|
|
|
CMakeCbpParser cbpparser;
|
2009-03-26 17:36:58 +01:00
|
|
|
// Parsing
|
|
|
|
|
//qDebug()<<"Parsing file "<<cbpFile;
|
2015-03-10 15:47:09 +01:00
|
|
|
if (!cbpparser.parseCbpFile(k,cbpFile, projectDirectory().toString())) {
|
2010-02-02 12:03:50 +01:00
|
|
|
// TODO report error
|
|
|
|
|
emit buildTargetsChanged();
|
2012-07-17 15:56:43 +02:00
|
|
|
return false;
|
2010-02-02 12:03:50 +01:00
|
|
|
}
|
2009-02-11 12:14:51 +01:00
|
|
|
|
2011-03-31 17:43:48 +02:00
|
|
|
foreach (const QString &file, m_watcher->files())
|
|
|
|
|
if (file != cbpFile)
|
|
|
|
|
m_watcher->removePath(file);
|
|
|
|
|
|
2011-05-10 15:19:38 +02:00
|
|
|
// how can we ensure that it is completely written?
|
2011-03-31 17:43:48 +02:00
|
|
|
m_watcher->addPath(cbpFile);
|
|
|
|
|
|
2016-01-08 12:49:00 +01:00
|
|
|
rootProjectNode()->setDisplayName(cbpparser.projectName());
|
2009-03-03 17:56:03 +01:00
|
|
|
|
2010-02-02 12:03:50 +01:00
|
|
|
//qDebug()<<"Building Tree";
|
|
|
|
|
QList<ProjectExplorer::FileNode *> fileList = cbpparser.fileList();
|
2015-02-02 00:37:38 +02:00
|
|
|
QSet<FileName> projectFiles;
|
2010-02-02 12:03:50 +01:00
|
|
|
if (cbpparser.hasCMakeFiles()) {
|
|
|
|
|
fileList.append(cbpparser.cmakeFileList());
|
2011-12-01 14:03:15 +01:00
|
|
|
foreach (const ProjectExplorer::FileNode *node, cbpparser.cmakeFileList())
|
2015-10-29 17:53:47 +01:00
|
|
|
projectFiles.insert(node->filePath());
|
2010-02-02 12:03:50 +01:00
|
|
|
} else {
|
|
|
|
|
// Manually add the CMakeLists.txt file
|
2015-02-02 00:37:38 +02:00
|
|
|
FileName cmakeListTxt = projectDirectory().appendPath(QLatin1String("CMakeLists.txt"));
|
2010-09-07 17:48:37 +02:00
|
|
|
bool generated = false;
|
|
|
|
|
fileList.append(new ProjectExplorer::FileNode(cmakeListTxt, ProjectExplorer::ProjectFileType, generated));
|
2010-02-02 12:03:50 +01:00
|
|
|
projectFiles.insert(cmakeListTxt);
|
|
|
|
|
}
|
2009-03-13 13:55:59 +01:00
|
|
|
|
2010-02-02 12:03:50 +01:00
|
|
|
m_watchedFiles = projectFiles;
|
2009-09-14 16:09:17 +02:00
|
|
|
|
2010-02-02 12:03:50 +01:00
|
|
|
m_files.clear();
|
|
|
|
|
foreach (ProjectExplorer::FileNode *fn, fileList)
|
2015-10-29 17:53:47 +01:00
|
|
|
m_files.append(fn->filePath().toString());
|
2010-02-02 12:03:50 +01:00
|
|
|
m_files.sort();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-01-08 12:49:00 +01:00
|
|
|
buildTree(static_cast<CMakeProjectNode *>(rootProjectNode()), fileList);
|
2009-03-26 17:36:58 +01:00
|
|
|
|
2010-02-02 12:03:50 +01:00
|
|
|
//qDebug()<<"Adding Targets";
|
|
|
|
|
m_buildTargets = cbpparser.buildTargets();
|
2009-03-16 17:33:05 +01:00
|
|
|
// qDebug()<<"Printing targets";
|
2011-12-01 14:03:15 +01:00
|
|
|
// foreach (CMakeBuildTarget ct, m_buildTargets) {
|
2009-03-16 17:33:05 +01:00
|
|
|
// qDebug()<<ct.title<<" with executable:"<<ct.executable;
|
|
|
|
|
// qDebug()<<"WD:"<<ct.workingDirectory;
|
|
|
|
|
// qDebug()<<ct.makeCommand<<ct.makeCleanCommand;
|
|
|
|
|
// qDebug()<<"";
|
|
|
|
|
// }
|
2008-12-09 14:13:29 +01:00
|
|
|
|
2013-07-07 23:49:13 +02:00
|
|
|
updateApplicationAndDeploymentTargets();
|
2010-09-24 13:17:43 +02:00
|
|
|
|
|
|
|
|
createUiCodeModelSupport();
|
2009-02-11 12:14:51 +01:00
|
|
|
|
2012-09-05 09:59:13 +03:00
|
|
|
ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k);
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!tc) {
|
2012-07-17 15:56:43 +02:00
|
|
|
emit buildTargetsChanged();
|
|
|
|
|
emit fileListChanged();
|
|
|
|
|
return true;
|
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;
|
|
|
|
|
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);
|
|
|
|
|
|
2015-07-20 12:32:54 +02:00
|
|
|
QByteArray cachedBuildNinja;
|
2015-02-15 23:13:28 +02:00
|
|
|
foreach (const CMakeBuildTarget &cbt, m_buildTargets) {
|
|
|
|
|
// This explicitly adds -I. to the include paths
|
|
|
|
|
QStringList includePaths = cbt.includeFiles;
|
|
|
|
|
includePaths += projectDirectory().toString();
|
|
|
|
|
ppBuilder.setIncludePaths(includePaths);
|
2015-07-20 12:32:54 +02:00
|
|
|
QStringList cxxflags = getCXXFlagsFor(cbt, &cachedBuildNinja);
|
|
|
|
|
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);
|
|
|
|
|
|
2014-07-14 17:39:46 +02:00
|
|
|
emit displayNameChanged();
|
2010-02-02 12:01:11 +01:00
|
|
|
emit buildTargetsChanged();
|
2010-09-27 20:34:22 +01:00
|
|
|
emit fileListChanged();
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2014-06-19 15:29:11 +02:00
|
|
|
emit activeBC->emitBuildTypeChanged();
|
|
|
|
|
|
2012-07-17 15:56:43 +02:00
|
|
|
return true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
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-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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-02 00:37:38 +02:00
|
|
|
bool CMakeProject::isProjectFile(const FileName &fileName)
|
2011-03-31 17:43:48 +02:00
|
|
|
{
|
|
|
|
|
return m_watchedFiles.contains(fileName);
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
QList<CMakeBuildTarget> CMakeProject::buildTargets() const
|
|
|
|
|
{
|
|
|
|
|
return m_buildTargets;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
= runnable ? Utils::filtered(m_buildTargets,
|
|
|
|
|
[](const CMakeBuildTarget &ct) {
|
|
|
|
|
return !ct.executable.isEmpty() && ct.targetType == ExecutableType;
|
|
|
|
|
})
|
|
|
|
|
: m_buildTargets;
|
|
|
|
|
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-05 15:19:11 +01:00
|
|
|
return Utils::anyOf(m_buildTargets, [title](const CMakeBuildTarget &ct) { return ct.title == title; });
|
2010-01-14 15:38:31 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-26 17:36:58 +01:00
|
|
|
void CMakeProject::gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list)
|
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) {
|
|
|
|
|
// qDebug()<<"added"<<fn->path();
|
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();
|
|
|
|
|
// qDebug()<<"removed"<<fn->path();
|
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
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(fileMode)
|
2008-12-02 12:01:29 +01:00
|
|
|
return m_files;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-10-02 17:46:19 +02:00
|
|
|
bool hasUserFile = activeTarget();
|
|
|
|
|
if (!hasUserFile) {
|
2015-09-10 16:17:38 +02:00
|
|
|
// Nothing to do, the target setup page will show up
|
2012-10-02 17:46:19 +02:00
|
|
|
} 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());
|
2015-05-18 16:57:29 +02:00
|
|
|
if (!activeBC) {
|
|
|
|
|
*errorMessage = tr("Internal Error: No build configuration found in settings file.");
|
|
|
|
|
return RestoreResult::Error;
|
|
|
|
|
}
|
2013-08-16 17:45:16 +02:00
|
|
|
QString cbpFile = CMakeManager::findCbpFile(QDir(activeBC->buildDirectory().toString()));
|
2012-10-02 17:46:19 +02:00
|
|
|
QFileInfo cbpFileFi(cbpFile);
|
|
|
|
|
|
|
|
|
|
CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing;
|
|
|
|
|
if (!cbpFileFi.exists())
|
|
|
|
|
mode = CMakeOpenProjectWizard::NeedToCreate;
|
2016-01-08 12:12:27 +01:00
|
|
|
else if (cbpFileFi.lastModified() < projectFilePath().toFileInfo().lastModified())
|
2012-10-02 17:46:19 +02:00
|
|
|
mode = CMakeOpenProjectWizard::NeedToUpdate;
|
|
|
|
|
|
|
|
|
|
if (mode != CMakeOpenProjectWizard::Nothing) {
|
2013-07-22 15:53:57 +02:00
|
|
|
CMakeBuildInfo info(activeBC);
|
2016-01-07 17:30:49 +01:00
|
|
|
CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), mode, &info);
|
2016-01-07 13:19:29 +01:00
|
|
|
if (copw.exec() != QDialog::Accepted)
|
2015-05-18 16:57:29 +02:00
|
|
|
return RestoreResult::UserAbort;
|
2016-01-07 13:19:29 +01:00
|
|
|
else
|
2015-09-10 16:17:38 +02:00
|
|
|
activeBC->setInitialArguments(QString());
|
2012-10-02 17:46:19 +02:00
|
|
|
}
|
2009-01-23 16:57:38 +01:00
|
|
|
}
|
2009-06-17 11:56:49 +02:00
|
|
|
|
2012-07-17 15:56:43 +02:00
|
|
|
parseCMakeLists();
|
2009-06-17 11:56:49 +02:00
|
|
|
|
2012-10-16 17:19:59 +02:00
|
|
|
m_activeTarget = activeTarget();
|
|
|
|
|
if (m_activeTarget)
|
2016-01-08 14:29:36 +01:00
|
|
|
connect(m_activeTarget, &Target::activeBuildConfigurationChanged,
|
|
|
|
|
this, &CMakeProject::changeActiveBuildConfiguration);
|
|
|
|
|
connect(this, &Project::activeTargetChanged,
|
|
|
|
|
this, &CMakeProject::activeTargetWasChanged);
|
2012-10-16 17:19:59 +02:00
|
|
|
|
2015-05-18 16:57:29 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-02 12:01:11 +01:00
|
|
|
CMakeBuildTarget CMakeProject::buildTargetForTitle(const QString &title)
|
2009-04-06 17:01:26 +02:00
|
|
|
{
|
2011-12-01 14:03:15 +01:00
|
|
|
foreach (const CMakeBuildTarget &ct, m_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
|
|
|
}
|
|
|
|
|
|
2010-09-24 13:17:43 +02:00
|
|
|
QString CMakeProject::uiHeaderFile(const QString &uiFile)
|
|
|
|
|
{
|
2015-09-10 16:17:38 +02:00
|
|
|
if (!activeTarget())
|
|
|
|
|
return QString();
|
2013-01-08 17:21:18 +01:00
|
|
|
QFileInfo fi(uiFile);
|
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());
|
2010-09-24 13:17:43 +02:00
|
|
|
QString uiHeaderFilePath = buildDir.absoluteFilePath(relativePath);
|
|
|
|
|
uiHeaderFilePath += QLatin1String("/ui_");
|
|
|
|
|
uiHeaderFilePath += fi.completeBaseName();
|
|
|
|
|
uiHeaderFilePath += QLatin1String(".h");
|
2013-01-08 17:21:18 +01:00
|
|
|
|
2010-09-24 13:17:43 +02:00
|
|
|
return QDir::cleanPath(uiHeaderFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-17 15:56:43 +02:00
|
|
|
void CMakeProject::updateRunConfigurations()
|
|
|
|
|
{
|
|
|
|
|
foreach (Target *t, targets())
|
2016-01-08 14:29:36 +01:00
|
|
|
updateTargetRunConfigurations(t);
|
2012-07-17 15:56:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO Compare with updateDefaultRunConfigurations();
|
2016-01-08 14:29:36 +01:00
|
|
|
void CMakeProject::updateTargetRunConfigurations(Target *t)
|
2012-07-17 15:56:43 +02:00
|
|
|
{
|
2015-08-31 14:11:31 +02:00
|
|
|
// create new and remove obsolete RCs using the factories
|
|
|
|
|
t->updateDefaultRunConfigurations();
|
|
|
|
|
|
2012-07-17 15:56:43 +02:00
|
|
|
// *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()) {
|
2014-11-06 11:27:24 +01:00
|
|
|
if (ct.targetType != ExecutableType)
|
2012-07-17 15:56:43 +02:00
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2013-07-07 23:49:13 +02:00
|
|
|
foreach (const CMakeBuildTarget &ct, m_buildTargets) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 13:17:43 +02:00
|
|
|
void CMakeProject::createUiCodeModelSupport()
|
|
|
|
|
{
|
2013-07-11 16:24:51 +02:00
|
|
|
QHash<QString, QString> uiFileHash;
|
2010-09-24 13:17:43 +02:00
|
|
|
|
|
|
|
|
// Find all ui files
|
|
|
|
|
foreach (const QString &uiFile, m_files) {
|
2013-07-11 16:24:51 +02:00
|
|
|
if (uiFile.endsWith(QLatin1String(".ui")))
|
|
|
|
|
uiFileHash.insert(uiFile, uiHeaderFile(uiFile));
|
2010-09-24 13:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-02 11:55:18 +02:00
|
|
|
QtSupport::UiCodeModelManager::update(this, uiFileHash);
|
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
|
|
|
}
|