2009-03-10 14:20:07 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2009-03-10 14:20:07 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2009-03-10 14:20:07 +01:00
|
|
|
**
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2009-03-10 14:20:07 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
**
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2009-03-10 14:20:07 +01:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "genericproject.h"
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2009-11-23 12:11:48 +01:00
|
|
|
#include "genericbuildconfiguration.h"
|
2010-02-08 15:50:06 +01:00
|
|
|
#include "genericprojectconstants.h"
|
|
|
|
#include "generictarget.h"
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2011-08-18 13:46:52 +02:00
|
|
|
#include <projectexplorer/abi.h>
|
2010-03-11 17:47:09 +01:00
|
|
|
#include <projectexplorer/buildenvironmentwidget.h>
|
2011-02-28 16:50:14 +01:00
|
|
|
#include <projectexplorer/headerpath.h>
|
2010-04-27 10:58:36 +02:00
|
|
|
#include <projectexplorer/customexecutablerunconfiguration.h>
|
2011-02-01 18:36:00 +01:00
|
|
|
#include <projectexplorer/toolchainmanager.h>
|
2009-03-10 14:20:07 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2012-03-14 10:25:55 +01:00
|
|
|
#include <cpptools/ModelManagerInterface.h>
|
2009-03-10 14:20:07 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2009-03-18 13:33:00 +01:00
|
|
|
#include <utils/pathchooser.h>
|
2011-04-12 08:20:54 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2009-03-10 14:20:07 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2011-04-12 12:17:19 +02:00
|
|
|
#include <coreplugin/icontext.h>
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
|
|
|
#include <QProcessEnvironment>
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QComboBox>
|
2009-03-10 14:20:07 +01:00
|
|
|
|
|
|
|
using namespace GenericProjectManager;
|
|
|
|
using namespace GenericProjectManager::Internal;
|
2009-09-24 16:02:02 +02:00
|
|
|
using namespace ProjectExplorer;
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2009-03-12 14:34:01 +01:00
|
|
|
namespace {
|
2010-01-19 16:33:44 +01:00
|
|
|
const char * const TOOLCHAIN_KEY("GenericProjectManager.GenericProject.Toolchain");
|
2009-03-12 14:34:01 +01:00
|
|
|
} // end of anonymous namespace
|
|
|
|
|
2009-03-18 13:33:00 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GenericProject
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-03-10 14:20:07 +01:00
|
|
|
GenericProject::GenericProject(Manager *manager, const QString &fileName)
|
2009-03-18 12:18:59 +01:00
|
|
|
: m_manager(manager),
|
|
|
|
m_fileName(fileName),
|
|
|
|
m_toolChain(0)
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2011-04-12 12:17:19 +02:00
|
|
|
setProjectContext(Core::Context(GenericProjectManager::Constants::PROJECTCONTEXT));
|
|
|
|
setProjectLanguage(Core::Context(ProjectExplorer::Constants::LANG_CXX));
|
|
|
|
|
2009-03-18 12:18:59 +01:00
|
|
|
QFileInfo fileInfo(m_fileName);
|
2009-03-16 11:49:57 +01:00
|
|
|
QDir dir = fileInfo.dir();
|
|
|
|
|
2009-03-20 16:13:46 +01:00
|
|
|
m_projectName = fileInfo.completeBaseName();
|
2009-03-19 16:33:44 +01:00
|
|
|
m_filesFileName = QFileInfo(dir, m_projectName + QLatin1String(".files")).absoluteFilePath();
|
|
|
|
m_includesFileName = QFileInfo(dir, m_projectName + QLatin1String(".includes")).absoluteFilePath();
|
|
|
|
m_configFileName = QFileInfo(dir, m_projectName + QLatin1String(".config")).absoluteFilePath();
|
2009-03-16 11:49:57 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
m_creatorIDocument = new GenericProjectFile(this, m_fileName, GenericProject::Everything);
|
|
|
|
m_filesIDocument = new GenericProjectFile(this, m_filesFileName, GenericProject::Files);
|
|
|
|
m_includesIDocument = new GenericProjectFile(this, m_includesFileName, GenericProject::Configuration);
|
|
|
|
m_configIDocument = new GenericProjectFile(this, m_configFileName, GenericProject::Configuration);
|
2011-11-07 17:03:10 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::DocumentManager::addDocument(m_creatorIDocument);
|
|
|
|
Core::DocumentManager::addDocument(m_filesIDocument);
|
|
|
|
Core::DocumentManager::addDocument(m_includesIDocument);
|
|
|
|
Core::DocumentManager::addDocument(m_configIDocument);
|
2011-11-07 17:03:10 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
m_rootNode = new GenericProjectNode(this, m_creatorIDocument);
|
2009-03-16 11:08:07 +01:00
|
|
|
|
2009-03-18 12:18:59 +01:00
|
|
|
m_manager->registerProject(this);
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GenericProject::~GenericProject()
|
|
|
|
{
|
2010-04-22 18:57:43 +02:00
|
|
|
m_codeModelFuture.cancel();
|
2009-03-18 12:18:59 +01:00
|
|
|
m_manager->unregisterProject(this);
|
2009-03-16 11:08:07 +01:00
|
|
|
|
2009-03-18 12:18:59 +01:00
|
|
|
delete m_rootNode;
|
2011-02-01 18:36:00 +01:00
|
|
|
// do not delete m_toolChain
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
GenericTarget *GenericProject::activeTarget() const
|
2009-09-24 16:02:02 +02:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
return static_cast<GenericTarget *>(Project::activeTarget());
|
2009-09-24 16:02:02 +02:00
|
|
|
}
|
|
|
|
|
2009-03-16 11:49:57 +01:00
|
|
|
QString GenericProject::filesFileName() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
return m_filesFileName;
|
|
|
|
}
|
2009-03-16 11:49:57 +01:00
|
|
|
|
|
|
|
QString GenericProject::includesFileName() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
return m_includesFileName;
|
|
|
|
}
|
2009-03-16 11:49:57 +01:00
|
|
|
|
|
|
|
QString GenericProject::configFileName() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
return m_configFileName;
|
|
|
|
}
|
2009-03-16 11:49:57 +01:00
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
static QStringList readLines(const QString &absoluteFileName)
|
2009-03-16 11:08:07 +01:00
|
|
|
{
|
|
|
|
QStringList lines;
|
|
|
|
|
|
|
|
QFile file(absoluteFileName);
|
|
|
|
if (file.open(QFile::ReadOnly)) {
|
|
|
|
QTextStream stream(&file);
|
|
|
|
|
|
|
|
forever {
|
|
|
|
QString line = stream.readLine();
|
|
|
|
if (line.isNull())
|
|
|
|
break;
|
|
|
|
|
|
|
|
lines.append(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
2010-02-10 16:38:50 +01:00
|
|
|
bool GenericProject::saveRawFileList(const QStringList &rawFileList)
|
2009-06-29 18:04:29 +02:00
|
|
|
{
|
2009-06-29 18:42:59 +02:00
|
|
|
// Make sure we can open the file for writing
|
2011-03-30 15:15:15 +02:00
|
|
|
Utils::FileSaver saver(filesFileName(), QIODevice::Text);
|
|
|
|
if (!saver.hasError()) {
|
|
|
|
QTextStream stream(saver.file());
|
|
|
|
foreach (const QString &filePath, rawFileList)
|
|
|
|
stream << filePath << QLatin1Char('\n');
|
|
|
|
saver.setResult(&stream);
|
|
|
|
}
|
2012-01-24 15:36:40 +01:00
|
|
|
if (!saver.finalize(Core::ICore::mainWindow()))
|
2009-06-29 18:42:59 +02:00
|
|
|
return false;
|
|
|
|
refresh(GenericProject::Files);
|
|
|
|
return true;
|
2009-06-29 18:04:29 +02:00
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
2009-06-30 14:07:07 +02:00
|
|
|
bool GenericProject::addFiles(const QStringList &filePaths)
|
|
|
|
{
|
2010-02-10 16:38:50 +01:00
|
|
|
QStringList newList = m_rawFileList;
|
|
|
|
|
|
|
|
QDir baseDir(QFileInfo(m_fileName).dir());
|
|
|
|
foreach (const QString &filePath, filePaths)
|
|
|
|
newList.append(baseDir.relativeFilePath(filePath));
|
2009-06-30 14:07:07 +02:00
|
|
|
|
2010-02-10 16:38:50 +01:00
|
|
|
return saveRawFileList(newList);
|
2009-06-30 14:07:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GenericProject::removeFiles(const QStringList &filePaths)
|
|
|
|
{
|
2010-02-10 16:38:50 +01:00
|
|
|
QStringList newList = m_rawFileList;
|
2009-06-30 15:00:30 +02:00
|
|
|
|
2010-02-10 16:38:50 +01:00
|
|
|
foreach (const QString &filePath, filePaths) {
|
|
|
|
QHash<QString, QString>::iterator i = m_rawListEntries.find(filePath);
|
|
|
|
if (i != m_rawListEntries.end())
|
|
|
|
newList.removeOne(i.value());
|
2009-06-30 15:00:30 +02:00
|
|
|
}
|
2009-06-30 14:07:07 +02:00
|
|
|
|
2010-02-10 16:38:50 +01:00
|
|
|
return saveRawFileList(newList);
|
2009-06-30 14:07:07 +02:00
|
|
|
}
|
|
|
|
|
2011-06-20 11:57:20 +02:00
|
|
|
bool GenericProject::setFiles(const QStringList &filePaths)
|
|
|
|
{
|
|
|
|
QStringList newList;
|
|
|
|
QDir baseDir(QFileInfo(m_fileName).dir());
|
|
|
|
foreach (const QString &filePath, filePaths)
|
|
|
|
newList.append(baseDir.relativeFilePath(filePath));
|
|
|
|
|
|
|
|
return saveRawFileList(newList);
|
|
|
|
}
|
|
|
|
|
2011-10-24 21:42:11 +02:00
|
|
|
bool GenericProject::renameFile(const QString &filePath, const QString &newFilePath)
|
|
|
|
{
|
|
|
|
QStringList newList = m_rawFileList;
|
|
|
|
|
|
|
|
QHash<QString, QString>::iterator i = m_rawListEntries.find(filePath);
|
|
|
|
if (i != m_rawListEntries.end()) {
|
|
|
|
int index = newList.indexOf(i.value());
|
|
|
|
if (index != -1) {
|
|
|
|
QDir baseDir(QFileInfo(m_fileName).dir());
|
|
|
|
newList.replace(index, baseDir.relativeFilePath(newFilePath));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return saveRawFileList(newList);
|
|
|
|
}
|
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
void GenericProject::parseProject(RefreshOptions options)
|
2009-03-12 15:07:54 +01:00
|
|
|
{
|
2010-02-10 16:38:50 +01:00
|
|
|
if (options & Files) {
|
|
|
|
m_rawListEntries.clear();
|
|
|
|
m_rawFileList = readLines(filesFileName());
|
2010-02-11 16:42:23 +01:00
|
|
|
m_files = processEntries(m_rawFileList, &m_rawListEntries);
|
2010-02-10 16:38:50 +01:00
|
|
|
}
|
2009-03-16 11:49:57 +01:00
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
if (options & Configuration) {
|
2010-02-11 16:42:23 +01:00
|
|
|
m_projectIncludePaths = processEntries(readLines(includesFileName()));
|
2009-03-16 11:08:07 +01:00
|
|
|
|
2010-02-10 17:28:53 +01:00
|
|
|
// TODO: Possibly load some configuration from the project file
|
|
|
|
//QSettings projectInfo(m_fileName, QSettings::IniFormat);
|
2009-03-16 12:42:16 +01:00
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
m_defines.clear();
|
2009-03-16 12:42:16 +01:00
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
QFile configFile(configFileName());
|
|
|
|
if (configFile.open(QFile::ReadOnly))
|
|
|
|
m_defines = configFile.readAll();
|
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
if (options & Files)
|
|
|
|
emit fileListChanged();
|
2009-03-12 15:07:54 +01:00
|
|
|
}
|
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
void GenericProject::refresh(RefreshOptions options)
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2009-03-19 17:58:56 +01:00
|
|
|
QSet<QString> oldFileList;
|
|
|
|
if (!(options & Configuration))
|
|
|
|
oldFileList = m_files.toSet();
|
2009-03-16 11:08:07 +01:00
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
parseProject(options);
|
|
|
|
|
|
|
|
if (options & Files)
|
|
|
|
m_rootNode->refresh();
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2010-12-03 13:49:35 +01:00
|
|
|
CPlusPlus::CppModelManagerInterface *modelManager =
|
2011-01-04 18:50:18 +01:00
|
|
|
CPlusPlus::CppModelManagerInterface::instance();
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2011-03-10 22:47:49 +01:00
|
|
|
if (modelManager) {
|
2010-12-03 13:49:35 +01:00
|
|
|
CPlusPlus::CppModelManagerInterface::ProjectInfo pinfo = modelManager->projectInfo(this);
|
2012-02-16 15:09:56 +01:00
|
|
|
pinfo.clearProjectParts();
|
|
|
|
CPlusPlus::CppModelManagerInterface::ProjectPart::Ptr part(
|
|
|
|
new CPlusPlus::CppModelManagerInterface::ProjectPart);
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2011-03-10 22:47:49 +01:00
|
|
|
if (m_toolChain) {
|
2012-02-16 15:09:56 +01:00
|
|
|
part->defines = m_toolChain->predefinedMacros(QStringList());
|
|
|
|
part->defines += '\n';
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2011-03-10 22:47:49 +01:00
|
|
|
foreach (const HeaderPath &headerPath, m_toolChain->systemHeaderPaths()) {
|
|
|
|
if (headerPath.kind() == HeaderPath::FrameworkHeaderPath)
|
2012-02-16 15:09:56 +01:00
|
|
|
part->frameworkPaths.append(headerPath.path());
|
2011-03-10 22:47:49 +01:00
|
|
|
else
|
2012-02-16 15:09:56 +01:00
|
|
|
part->includePaths.append(headerPath.path());
|
2011-03-10 22:47:49 +01:00
|
|
|
}
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
2012-02-16 15:09:56 +01:00
|
|
|
part->includePaths += allIncludePaths();
|
|
|
|
part->defines += m_defines;
|
2009-03-10 14:20:07 +01:00
|
|
|
|
|
|
|
// ### add _defines.
|
2012-02-16 15:09:56 +01:00
|
|
|
part->sourceFiles = files();
|
|
|
|
part->sourceFiles += generated();
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
QStringList filesToUpdate;
|
|
|
|
|
|
|
|
if (options & Configuration) {
|
2012-02-16 15:09:56 +01:00
|
|
|
filesToUpdate = part->sourceFiles;
|
2009-03-19 17:58:56 +01:00
|
|
|
filesToUpdate.append(QLatin1String("<configuration>")); // XXX don't hardcode configuration file name
|
2010-04-22 18:57:43 +02:00
|
|
|
// Full update, if there's a code model update, cancel it
|
|
|
|
m_codeModelFuture.cancel();
|
2009-03-19 17:58:56 +01:00
|
|
|
} else if (options & Files) {
|
|
|
|
// Only update files that got added to the list
|
|
|
|
QSet<QString> newFileList = m_files.toSet();
|
|
|
|
newFileList.subtract(oldFileList);
|
|
|
|
filesToUpdate.append(newFileList.toList());
|
|
|
|
}
|
2009-03-18 11:32:45 +01:00
|
|
|
|
2012-02-16 15:09:56 +01:00
|
|
|
pinfo.appendProjectPart(part);
|
|
|
|
|
2009-03-10 14:20:07 +01:00
|
|
|
modelManager->updateProjectInfo(pinfo);
|
2010-04-22 18:57:43 +02:00
|
|
|
m_codeModelFuture = modelManager->updateSourceFiles(filesToUpdate);
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-10 16:38:50 +01:00
|
|
|
/**
|
2010-02-11 16:42:23 +01:00
|
|
|
* Expands environment variables in the given \a string when they are written
|
|
|
|
* like $$(VARIABLE).
|
|
|
|
*/
|
|
|
|
static void expandEnvironmentVariables(const QProcessEnvironment &env, QString &string)
|
|
|
|
{
|
|
|
|
const static QRegExp candidate(QLatin1String("\\$\\$\\((.+)\\)"));
|
|
|
|
|
|
|
|
int index = candidate.indexIn(string);
|
|
|
|
while (index != -1) {
|
|
|
|
const QString value = env.value(candidate.cap(1));
|
|
|
|
|
|
|
|
string.replace(index, candidate.matchedLength(), value);
|
|
|
|
index += value.length();
|
|
|
|
|
|
|
|
index = candidate.indexIn(string, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expands environment variables and converts the path from relative to the
|
|
|
|
* project to an absolute path.
|
|
|
|
*
|
2010-02-10 16:38:50 +01:00
|
|
|
* The \a map variable is an optional argument that will map the returned
|
2010-02-11 16:42:23 +01:00
|
|
|
* absolute paths back to their original \a entries.
|
2010-02-10 16:38:50 +01:00
|
|
|
*/
|
2010-02-11 16:42:23 +01:00
|
|
|
QStringList GenericProject::processEntries(const QStringList &paths,
|
|
|
|
QHash<QString, QString> *map) const
|
2009-03-12 15:07:54 +01:00
|
|
|
{
|
2010-02-11 16:42:23 +01:00
|
|
|
const QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
2009-03-18 12:18:59 +01:00
|
|
|
const QDir projectDir(QFileInfo(m_fileName).dir());
|
2010-02-11 16:42:23 +01:00
|
|
|
|
2009-03-12 15:07:54 +01:00
|
|
|
QStringList absolutePaths;
|
2010-02-10 16:38:50 +01:00
|
|
|
foreach (const QString &path, paths) {
|
2010-02-11 16:42:23 +01:00
|
|
|
QString trimmedPath = path.trimmed();
|
|
|
|
if (trimmedPath.isEmpty())
|
2010-02-10 16:38:50 +01:00
|
|
|
continue;
|
|
|
|
|
2010-02-11 16:42:23 +01:00
|
|
|
expandEnvironmentVariables(env, trimmedPath);
|
|
|
|
|
|
|
|
const QString absPath = QFileInfo(projectDir, trimmedPath).absoluteFilePath();
|
2010-02-10 16:38:50 +01:00
|
|
|
absolutePaths.append(absPath);
|
|
|
|
if (map)
|
2010-02-11 16:42:23 +01:00
|
|
|
map->insert(absPath, trimmedPath);
|
2009-03-12 15:07:54 +01:00
|
|
|
}
|
|
|
|
absolutePaths.removeDuplicates();
|
|
|
|
return absolutePaths;
|
|
|
|
}
|
|
|
|
|
2009-03-13 15:12:54 +01:00
|
|
|
QStringList GenericProject::allIncludePaths() const
|
|
|
|
{
|
|
|
|
QStringList paths;
|
2009-03-18 12:18:59 +01:00
|
|
|
paths += m_includePaths;
|
|
|
|
paths += m_projectIncludePaths;
|
2009-03-13 15:12:54 +01:00
|
|
|
paths.removeDuplicates();
|
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList GenericProject::projectIncludePaths() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
return m_projectIncludePaths;
|
|
|
|
}
|
2009-03-13 15:12:54 +01:00
|
|
|
|
2009-03-12 15:07:54 +01:00
|
|
|
QStringList GenericProject::files() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
return m_files;
|
|
|
|
}
|
2009-03-12 15:07:54 +01:00
|
|
|
|
|
|
|
QStringList GenericProject::generated() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
return m_generated;
|
|
|
|
}
|
2009-03-12 15:07:54 +01:00
|
|
|
|
|
|
|
QStringList GenericProject::includePaths() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
return m_includePaths;
|
|
|
|
}
|
2009-03-12 15:07:54 +01:00
|
|
|
|
|
|
|
void GenericProject::setIncludePaths(const QStringList &includePaths)
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
m_includePaths = includePaths;
|
|
|
|
}
|
2009-03-12 15:07:54 +01:00
|
|
|
|
2009-03-16 12:42:16 +01:00
|
|
|
QByteArray GenericProject::defines() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
return m_defines;
|
|
|
|
}
|
2009-03-12 15:07:54 +01:00
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
void GenericProject::setToolChain(ToolChain *tc)
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2011-02-01 18:36:00 +01:00
|
|
|
if (m_toolChain == tc)
|
|
|
|
return;
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
m_toolChain = tc;
|
2011-03-10 23:09:37 +01:00
|
|
|
refresh(Configuration);
|
|
|
|
|
2011-07-12 12:58:16 +00:00
|
|
|
foreach (Target *t, targets()) {
|
|
|
|
foreach (BuildConfiguration *bc, t->buildConfigurations())
|
|
|
|
bc->setToolChain(tc);
|
|
|
|
}
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
emit toolChainChanged(m_toolChain);
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
ToolChain *GenericProject::toolChain() const
|
2009-03-18 14:35:35 +01:00
|
|
|
{
|
|
|
|
return m_toolChain;
|
|
|
|
}
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString GenericProject::displayName() const
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2009-03-18 12:18:59 +01:00
|
|
|
return m_projectName;
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
2012-03-15 17:17:40 +01:00
|
|
|
Core::Id GenericProject::id() const
|
2010-01-22 15:59:44 +01:00
|
|
|
{
|
2012-03-15 17:17:40 +01:00
|
|
|
return Core::Id(Constants::GENERICPROJECT_ID);
|
2010-01-22 15:59:44 +01:00
|
|
|
}
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::IDocument *GenericProject::document() const
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2012-02-14 16:43:51 +01:00
|
|
|
return m_creatorIDocument;
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
IProjectManager *GenericProject::projectManager() const
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2009-03-18 12:18:59 +01:00
|
|
|
return m_manager;
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
QList<BuildConfigWidget*> GenericProject::subConfigWidgets()
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2011-02-01 18:36:00 +01:00
|
|
|
QList<BuildConfigWidget*> list;
|
2010-03-11 17:47:09 +01:00
|
|
|
list << new BuildEnvironmentWidget;
|
|
|
|
return list;
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
2009-03-12 13:50:43 +01:00
|
|
|
GenericProjectNode *GenericProject::rootProjectNode() const
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2009-03-18 12:18:59 +01:00
|
|
|
return m_rootNode;
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList GenericProject::files(FilesMode fileMode) const
|
|
|
|
{
|
2009-07-29 09:11:37 +02:00
|
|
|
Q_UNUSED(fileMode)
|
2009-03-18 12:18:59 +01:00
|
|
|
return m_files; // ### TODO: handle generated files here.
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
QStringList GenericProject::buildTargets() const
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
|
|
|
QStringList targets;
|
|
|
|
targets.append(QLatin1String("all"));
|
|
|
|
targets.append(QLatin1String("clean"));
|
|
|
|
return targets;
|
|
|
|
}
|
|
|
|
|
2010-01-19 16:33:44 +01:00
|
|
|
QVariantMap GenericProject::toMap() const
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2010-01-19 16:33:44 +01:00
|
|
|
QVariantMap map(Project::toMap());
|
2011-02-01 18:36:00 +01:00
|
|
|
map.insert(QLatin1String(TOOLCHAIN_KEY), m_toolChain ? m_toolChain->id() : QString());
|
2010-01-19 16:33:44 +01:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GenericProject::fromMap(const QVariantMap &map)
|
|
|
|
{
|
|
|
|
if (!Project::fromMap(map))
|
|
|
|
return false;
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2010-04-27 10:58:36 +02:00
|
|
|
// Sanity check: We need both a buildconfiguration and a runconfiguration!
|
|
|
|
QList<Target *> targetList = targets();
|
|
|
|
foreach (Target *t, targetList) {
|
|
|
|
if (!t->activeBuildConfiguration()) {
|
|
|
|
removeTarget(t);
|
|
|
|
delete t;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!t->activeRunConfiguration())
|
2011-02-01 18:36:00 +01:00
|
|
|
t->addRunConfiguration(new CustomExecutableRunConfiguration(t));
|
2010-04-27 10:58:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add default setup:
|
2010-12-06 16:15:41 +01:00
|
|
|
if (targets().isEmpty()) {
|
|
|
|
GenericTargetFactory *factory =
|
|
|
|
ExtensionSystem::PluginManager::instance()->getObject<GenericTargetFactory>();
|
2012-03-15 17:17:40 +01:00
|
|
|
addTarget(factory->create(this, Core::Id(GENERIC_DESKTOP_TARGET_ID)));
|
2010-12-06 16:15:41 +01:00
|
|
|
}
|
2009-03-12 12:26:32 +01:00
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
QString id = map.value(QLatin1String(TOOLCHAIN_KEY)).toString();
|
2011-03-10 23:09:37 +01:00
|
|
|
const ToolChainManager *toolChainManager = ToolChainManager::instance();
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
if (!id.isNull()) {
|
2011-03-10 23:09:37 +01:00
|
|
|
setToolChain(toolChainManager->findToolChain(id));
|
2011-02-01 18:36:00 +01:00
|
|
|
} else {
|
2011-04-13 12:01:54 +02:00
|
|
|
ProjectExplorer::Abi abi = ProjectExplorer::Abi::hostAbi();
|
|
|
|
abi = ProjectExplorer::Abi(abi.architecture(), abi.os(), ProjectExplorer::Abi::UnknownFlavor,
|
|
|
|
abi.binaryFormat(), abi.wordWidth() == 32 ? 32 : 0);
|
|
|
|
QList<ToolChain *> tcs = toolChainManager->findToolChains(abi);
|
2011-02-01 18:36:00 +01:00
|
|
|
if (tcs.isEmpty())
|
2011-03-10 23:09:37 +01:00
|
|
|
tcs = toolChainManager->toolChains();
|
2011-02-01 18:36:00 +01:00
|
|
|
if (!tcs.isEmpty())
|
|
|
|
setToolChain(tcs.at(0));
|
|
|
|
}
|
2009-03-13 15:12:54 +01:00
|
|
|
|
|
|
|
setIncludePaths(allIncludePaths());
|
2009-03-12 12:26:32 +01:00
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
refresh(Everything);
|
2009-07-03 16:46:01 +02:00
|
|
|
return true;
|
2009-03-12 12:26:32 +01:00
|
|
|
}
|
|
|
|
|
2009-03-10 14:20:07 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GenericBuildSettingsWidget
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
2009-03-18 13:33:00 +01:00
|
|
|
|
2010-12-06 12:45:05 +01:00
|
|
|
GenericBuildSettingsWidget::GenericBuildSettingsWidget(GenericTarget *target)
|
2011-02-01 18:36:00 +01:00
|
|
|
: m_target(target), m_toolChainChooser(0), m_buildConfiguration(0)
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
|
|
|
QFormLayout *fl = new QFormLayout(this);
|
2009-07-23 16:40:15 +02:00
|
|
|
fl->setContentsMargins(0, -1, 0, -1);
|
|
|
|
fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
2009-03-12 14:34:01 +01:00
|
|
|
|
|
|
|
// build directory
|
2009-10-05 11:06:05 +02:00
|
|
|
m_pathChooser = new Utils::PathChooser(this);
|
2009-03-18 12:18:59 +01:00
|
|
|
m_pathChooser->setEnabled(true);
|
2010-12-06 12:45:05 +01:00
|
|
|
m_pathChooser->setBaseDirectory(m_target->genericProject()->projectDirectory());
|
2009-03-18 12:18:59 +01:00
|
|
|
fl->addRow(tr("Build directory:"), m_pathChooser);
|
2009-06-19 17:55:47 +02:00
|
|
|
connect(m_pathChooser, SIGNAL(changed(QString)), this, SLOT(buildDirectoryChanged()));
|
2009-03-12 13:50:43 +01:00
|
|
|
|
2009-03-12 14:34:01 +01:00
|
|
|
// tool chain
|
2011-02-01 18:36:00 +01:00
|
|
|
m_toolChainChooser = new QComboBox;
|
|
|
|
m_toolChainChooser->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
updateToolChainList();
|
|
|
|
|
|
|
|
fl->addRow(tr("Tool chain:"), m_toolChainChooser);
|
|
|
|
connect(m_toolChainChooser, SIGNAL(activated(int)), this, SLOT(toolChainSelected(int)));
|
|
|
|
connect(m_target->genericProject(), SIGNAL(toolChainChanged(ProjectExplorer::ToolChain*)),
|
|
|
|
this, SLOT(toolChainChanged(ProjectExplorer::ToolChain*)));
|
2011-03-10 23:08:54 +01:00
|
|
|
connect(ProjectExplorer::ToolChainManager::instance(), SIGNAL(toolChainAdded(ProjectExplorer::ToolChain*)),
|
2011-02-01 18:36:00 +01:00
|
|
|
this, SLOT(updateToolChainList()));
|
2011-03-10 23:08:54 +01:00
|
|
|
connect(ProjectExplorer::ToolChainManager::instance(), SIGNAL(toolChainRemoved(ProjectExplorer::ToolChain*)),
|
2011-02-01 18:36:00 +01:00
|
|
|
this, SLOT(updateToolChainList()));
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GenericBuildSettingsWidget::~GenericBuildSettingsWidget()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
QString GenericBuildSettingsWidget::displayName() const
|
|
|
|
{ return tr("Generic Manager"); }
|
|
|
|
|
2009-11-24 15:36:31 +01:00
|
|
|
void GenericBuildSettingsWidget::init(BuildConfiguration *bc)
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2009-11-25 18:50:20 +01:00
|
|
|
m_buildConfiguration = static_cast<GenericBuildConfiguration *>(bc);
|
2010-03-15 16:15:36 +01:00
|
|
|
m_pathChooser->setPath(m_buildConfiguration->rawBuildDirectory());
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GenericBuildSettingsWidget::buildDirectoryChanged()
|
|
|
|
{
|
2010-09-24 12:39:25 +02:00
|
|
|
m_buildConfiguration->setBuildDirectory(m_pathChooser->rawPath());
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
2009-08-21 15:59:17 +02:00
|
|
|
void GenericBuildSettingsWidget::toolChainSelected(int index)
|
|
|
|
{
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
ToolChain *tc = static_cast<ToolChain *>(m_toolChainChooser->itemData(index).value<void *>());
|
|
|
|
m_target->genericProject()->setToolChain(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenericBuildSettingsWidget::toolChainChanged(ProjectExplorer::ToolChain *tc)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < m_toolChainChooser->count(); ++i) {
|
|
|
|
ToolChain * currentTc = static_cast<ToolChain *>(m_toolChainChooser->itemData(i).value<void *>());
|
|
|
|
if (currentTc != tc)
|
|
|
|
continue;
|
|
|
|
m_toolChainChooser->setCurrentIndex(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenericBuildSettingsWidget::updateToolChainList()
|
|
|
|
{
|
|
|
|
m_toolChainChooser->clear();
|
|
|
|
|
|
|
|
QList<ToolChain *> tcs = ToolChainManager::instance()->toolChains();
|
|
|
|
if (!m_target->genericProject()->toolChain()) {
|
2011-03-16 17:59:43 +01:00
|
|
|
m_toolChainChooser->addItem(tr("<Invalid tool chain>"), qVariantFromValue(static_cast<void *>(0)));
|
2011-02-01 18:36:00 +01:00
|
|
|
m_toolChainChooser->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
foreach (ToolChain *tc, tcs) {
|
|
|
|
m_toolChainChooser->addItem(tc->displayName(), qVariantFromValue(static_cast<void *>(tc)));
|
|
|
|
if (m_target->genericProject()->toolChain()
|
|
|
|
&& m_target->genericProject()->toolChain()->id() == tc->id())
|
|
|
|
m_toolChainChooser->setCurrentIndex(m_toolChainChooser->count() - 1);
|
|
|
|
}
|
2009-08-21 15:59:17 +02:00
|
|
|
}
|
|
|
|
|
2009-03-10 14:20:07 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GenericProjectFile
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
2009-03-18 13:33:00 +01:00
|
|
|
|
2011-11-07 17:03:10 +01:00
|
|
|
GenericProjectFile::GenericProjectFile(GenericProject *parent, QString fileName, GenericProject::RefreshOptions options)
|
2012-02-14 16:43:51 +01:00
|
|
|
: Core::IDocument(parent),
|
2009-03-18 12:18:59 +01:00
|
|
|
m_project(parent),
|
2011-11-07 17:03:10 +01:00
|
|
|
m_fileName(fileName),
|
|
|
|
m_options(options)
|
2009-03-10 14:20:07 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
GenericProjectFile::~GenericProjectFile()
|
|
|
|
{ }
|
|
|
|
|
2011-05-10 20:43:03 +02:00
|
|
|
bool GenericProjectFile::save(QString *, const QString &, bool)
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString GenericProjectFile::fileName() const
|
|
|
|
{
|
2009-03-18 12:18:59 +01:00
|
|
|
return m_fileName;
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString GenericProjectFile::defaultPath() const
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString GenericProjectFile::suggestedFileName() const
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString GenericProjectFile::mimeType() const
|
|
|
|
{
|
|
|
|
return Constants::GENERICMIMETYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GenericProjectFile::isModified() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GenericProjectFile::isSaveAsAllowed() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-11 14:13:38 +02:00
|
|
|
void GenericProjectFile::rename(const QString &newName)
|
|
|
|
{
|
|
|
|
// Can't happen
|
|
|
|
Q_UNUSED(newName);
|
2011-07-29 12:00:11 +02:00
|
|
|
QTC_CHECK(false);
|
2010-05-11 14:13:38 +02:00
|
|
|
}
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::IDocument::ReloadBehavior GenericProjectFile::reloadBehavior(ChangeTrigger state, ChangeType type) const
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2010-03-19 10:28:05 +01:00
|
|
|
Q_UNUSED(state)
|
|
|
|
Q_UNUSED(type)
|
|
|
|
return BehaviorSilent;
|
|
|
|
}
|
|
|
|
|
2011-04-04 15:24:13 +02:00
|
|
|
bool GenericProjectFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
|
2010-03-19 10:28:05 +01:00
|
|
|
{
|
2011-04-04 15:24:13 +02:00
|
|
|
Q_UNUSED(errorString)
|
2010-03-19 10:28:05 +01:00
|
|
|
Q_UNUSED(flag)
|
2011-11-07 17:03:10 +01:00
|
|
|
if (type == TypePermissions)
|
|
|
|
return true;
|
|
|
|
m_project->refresh(m_options);
|
2011-04-04 15:24:13 +02:00
|
|
|
return true;
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|