2008-12-02 12:01:29 +01:00
|
|
|
/***************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2009-01-13 19:21:51 +01:00
|
|
|
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
|
|
|
** Non-Open Source Usage
|
|
|
|
**
|
2008-12-02 12:01:29 +01:00
|
|
|
** Licensees may use this file in accordance with the Qt Beta Version
|
|
|
|
** License Agreement, Agreement version 2.2 provided with the Software or,
|
|
|
|
** alternatively, in accordance with the terms contained in a written
|
2008-12-02 14:17:16 +01:00
|
|
|
** agreement between you and Nokia.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
**
|
2008-12-02 12:01:29 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License versions 2.0 or 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the packaging
|
|
|
|
** of this file. Please review the following information to ensure GNU
|
|
|
|
** General Public Licensing requirements will be met:
|
|
|
|
**
|
|
|
|
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2008-12-02 14:17:16 +01:00
|
|
|
** rights. These rights are described in the Nokia Qt GPL Exception
|
2008-12-16 17:20:00 +01:00
|
|
|
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
|
|
|
***************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cmakeproject.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
|
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"
|
2008-12-05 16:30:26 +01:00
|
|
|
#include "cmakestep.h"
|
|
|
|
#include "makestep.h"
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
#include <cpptools/cppmodelmanagerinterface.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QDebug>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <QtCore/QDir>
|
|
|
|
#include <QtCore/QProcess>
|
2009-01-12 15:10:33 +01:00
|
|
|
#include <QtGui/QFormLayout>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
using namespace CMakeProjectManager;
|
|
|
|
using namespace CMakeProjectManager::Internal;
|
|
|
|
|
2008-12-12 17:22:02 +01:00
|
|
|
|
|
|
|
// QtCreator CMake Generator wishlist:
|
|
|
|
// Which make targets we need to build to get all executables
|
|
|
|
// What is the 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-01-12 15:10:33 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName)
|
|
|
|
: m_manager(manager), m_fileName(fileName), m_rootNode(new CMakeProjectNode(m_fileName))
|
|
|
|
{
|
|
|
|
m_file = new CMakeFile(this, fileName);
|
|
|
|
QDir dir = QFileInfo(m_fileName).absoluteDir();
|
2009-01-12 15:10:33 +01:00
|
|
|
parseCMakeLists(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
CMakeProject::~CMakeProject()
|
|
|
|
{
|
|
|
|
delete m_rootNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO also call this method if the CMakeLists.txt file changed, which is also called if the CMakeList.txt is updated
|
|
|
|
// TODO make this function work even if it is reparsing
|
|
|
|
void CMakeProject::parseCMakeLists(const QDir &directory)
|
|
|
|
{
|
|
|
|
createCbpFile(directory);
|
|
|
|
|
|
|
|
QString cbpFile = findCbpFile(directory);
|
2008-12-02 17:56:21 +01:00
|
|
|
|
|
|
|
CMakeCbpParser cbpparser;
|
2009-01-12 15:10:33 +01:00
|
|
|
qDebug()<<"Parsing file "<<cbpFile;
|
2008-12-02 17:56:21 +01:00
|
|
|
if (cbpparser.parseCbpFile(cbpFile)) {
|
2009-01-15 14:48:28 +00:00
|
|
|
m_projectName = cbpparser.projectName();
|
2009-01-12 15:10:33 +01:00
|
|
|
qDebug()<<"Building Tree";
|
2008-12-09 14:13:29 +01:00
|
|
|
// TODO do a intelligent updating of the tree
|
2008-12-02 17:56:21 +01:00
|
|
|
buildTree(m_rootNode, cbpparser.fileList());
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (ProjectExplorer::FileNode *fn, cbpparser.fileList())
|
2008-12-02 12:01:29 +01:00
|
|
|
m_files.append(fn->path());
|
|
|
|
m_files.sort();
|
|
|
|
|
2009-01-12 15:10:33 +01:00
|
|
|
qDebug()<<"Adding Targets";
|
2008-12-09 14:13:29 +01:00
|
|
|
m_targets = cbpparser.targets();
|
|
|
|
qDebug()<<"Printing targets";
|
|
|
|
foreach(CMakeTarget ct, m_targets) {
|
|
|
|
qDebug()<<ct.title<<" with executable:"<<ct.executable;
|
|
|
|
qDebug()<<"WD:"<<ct.workingDirectory;
|
|
|
|
qDebug()<<ct.makeCommand<<ct.makeCleanCommand;
|
|
|
|
qDebug()<<"";
|
|
|
|
}
|
|
|
|
|
2009-01-12 15:10:33 +01:00
|
|
|
qDebug()<<"Updating CodeModel";
|
2008-12-02 12:01:29 +01:00
|
|
|
CppTools::CppModelManagerInterface *modelmanager = ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>();
|
|
|
|
if (modelmanager) {
|
2008-12-08 10:44:56 +01:00
|
|
|
CppTools::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this);
|
|
|
|
pinfo.includePaths = cbpparser.includeFiles();
|
2008-12-02 17:56:21 +01:00
|
|
|
// TODO we only want C++ files, not all other stuff that might be in the project
|
2008-12-08 10:44:56 +01:00
|
|
|
pinfo.sourceFiles = m_files;
|
2008-12-02 12:01:29 +01:00
|
|
|
// TODO defines
|
2008-12-09 14:13:29 +01:00
|
|
|
// TODO gcc preprocessor files
|
2008-12-08 10:44:56 +01:00
|
|
|
modelmanager->updateProjectInfo(pinfo);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// TODO report error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-12 15:10:33 +01:00
|
|
|
QStringList CMakeProject::targets() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-12 15:10:33 +01:00
|
|
|
QStringList results;
|
|
|
|
foreach(const CMakeTarget &ct, m_targets)
|
|
|
|
results << ct.title;
|
|
|
|
return results;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeProject::findCbpFile(const QDir &directory)
|
|
|
|
{
|
|
|
|
// Find the cbp file
|
|
|
|
// TODO the cbp file is named like the project() command in the CMakeList.txt file
|
|
|
|
// so this method below could find the wrong cbp file, if the user changes the project()
|
|
|
|
// name
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (const QString &cbpFile , directory.entryList()) {
|
|
|
|
if (cbpFile.endsWith(".cbp"))
|
2008-12-02 12:01:29 +01:00
|
|
|
return directory.path() + "/" + cbpFile;
|
|
|
|
}
|
|
|
|
return QString::null;
|
|
|
|
}
|
|
|
|
|
2008-12-12 17:22:02 +01:00
|
|
|
void CMakeProject::createCbpFile(const QDir &directory)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2008-12-09 14:13:29 +01:00
|
|
|
// We create a cbp file, only if we didn't find a cbp file in the base directory
|
|
|
|
// Yet that can still override cbp files in subdirectories
|
|
|
|
// And we are creating tons of files in the source directories
|
|
|
|
// All of that is not really nice.
|
|
|
|
// The mid term plan is to move away from the CodeBlocks Generator and use our own
|
|
|
|
// QtCreator generator, which actually can be very similar to the CodeBlock Generator
|
|
|
|
|
|
|
|
// TODO we need to pass on the same paremeters as the cmakestep
|
2009-01-12 15:10:33 +01:00
|
|
|
qDebug()<<"Creating cbp file";
|
2008-12-09 14:13:29 +01:00
|
|
|
QProcess cmake;
|
|
|
|
cmake.setWorkingDirectory(directory.absolutePath());
|
|
|
|
cmake.start("cmake", QStringList() << "-GCodeBlocks - Unix Makefiles");
|
2009-01-12 15:10:33 +01:00
|
|
|
cmake.waitForFinished(-1);
|
|
|
|
qDebug()<<"cmake output: \n"<<cmake.readAll();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeProject::buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list)
|
|
|
|
{
|
|
|
|
//m_rootNode->addFileNodes(fileList, m_rootNode);
|
|
|
|
qSort(list.begin(), list.end(), ProjectExplorer::ProjectNode::sortNodesByPath);
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (ProjectExplorer::FileNode *fn, list) {
|
2008-12-02 12:01:29 +01:00
|
|
|
// Get relative path to rootNode
|
|
|
|
QString parentDir = QFileInfo(fn->path()).absolutePath();
|
|
|
|
ProjectExplorer::FolderNode *folder = findOrCreateFolder(rootNode, parentDir);
|
|
|
|
rootNode->addFileNodes(QList<ProjectExplorer::FileNode *>()<< fn, folder);
|
|
|
|
}
|
|
|
|
//m_rootNode->addFileNodes(list, rootNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::FolderNode *CMakeProject::findOrCreateFolder(CMakeProjectNode *rootNode, QString directory)
|
|
|
|
{
|
|
|
|
QString relativePath = QDir(QFileInfo(rootNode->path()).path()).relativeFilePath(directory);
|
|
|
|
QStringList parts = relativePath.split("/");
|
|
|
|
ProjectExplorer::FolderNode *parent = rootNode;
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (const QString &part, parts) {
|
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()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
if (QFileInfo(folder->path()).fileName() == part) {
|
|
|
|
// yeah found something :)
|
|
|
|
parent = folder;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
// No FolderNode yet, so create it
|
|
|
|
ProjectExplorer::FolderNode *tmp = new ProjectExplorer::FolderNode(part);
|
|
|
|
rootNode->addFolderNodes(QList<ProjectExplorer::FolderNode *>() << tmp, parent);
|
|
|
|
parent = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeProject::name() const
|
|
|
|
{
|
2009-01-15 14:48:28 +00:00
|
|
|
return m_projectName;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Core::IFile *CMakeProject::file() const
|
|
|
|
{
|
|
|
|
return m_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::IProjectManager *CMakeProject::projectManager() const
|
|
|
|
{
|
|
|
|
return m_manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Core::IFile *> CMakeProject::dependencies()
|
|
|
|
{
|
|
|
|
return QList<Core::IFile *>();
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<ProjectExplorer::Project *> CMakeProject::dependsOn()
|
|
|
|
{
|
|
|
|
return QList<Project *>();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMakeProject::isApplication() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::Environment CMakeProject::environment(const QString &buildConfiguration) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(buildConfiguration)
|
|
|
|
//TODO
|
|
|
|
return ProjectExplorer::Environment::systemEnvironment();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeProject::buildDirectory(const QString &buildConfiguration) const
|
|
|
|
{
|
2009-01-12 15:10:33 +01:00
|
|
|
QString buildDirectory = value(buildConfiguration, "buildDirectory").toString();
|
|
|
|
if (buildDirectory.isEmpty())
|
|
|
|
buildDirectory = QFileInfo(m_fileName).absolutePath();
|
|
|
|
return buildDirectory;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::BuildStepConfigWidget *CMakeProject::createConfigWidget()
|
|
|
|
{
|
2009-01-12 15:10:33 +01:00
|
|
|
return new CMakeBuildSettingsWidget(this);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<ProjectExplorer::BuildStepConfigWidget*> CMakeProject::subConfigWidgets()
|
|
|
|
{
|
|
|
|
return QList<ProjectExplorer::BuildStepConfigWidget*>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method is called for new build configurations
|
|
|
|
// You should probably set some default values in this method
|
|
|
|
void CMakeProject::newBuildConfiguration(const QString &buildConfiguration)
|
|
|
|
{
|
2009-01-12 15:10:33 +01:00
|
|
|
// Default to all
|
|
|
|
makeStep()->setBuildTarget(buildConfiguration, "all", true);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::ProjectNode *CMakeProject::rootProjectNode() const
|
|
|
|
{
|
|
|
|
return m_rootNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList CMakeProject::files(FilesMode fileMode) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(fileMode);
|
|
|
|
// TODO
|
|
|
|
return m_files;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeProject::saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer)
|
|
|
|
{
|
|
|
|
// TODO
|
2008-12-09 14:13:29 +01:00
|
|
|
Project::saveSettingsImpl(writer);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
2009-01-12 15:10:33 +01:00
|
|
|
MakeStep *CMakeProject::makeStep() const
|
|
|
|
{
|
|
|
|
foreach (ProjectExplorer::BuildStep *bs, buildSteps()) {
|
|
|
|
MakeStep *ms = qobject_cast<MakeStep *>(bs);
|
|
|
|
if (ms)
|
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMakeStep *CMakeProject::cmakeStep() const
|
|
|
|
{
|
|
|
|
foreach (ProjectExplorer::BuildStep *bs, buildSteps()) {
|
|
|
|
if (CMakeStep *cs = qobject_cast<CMakeStep *>(bs))
|
|
|
|
return cs;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader)
|
|
|
|
{
|
|
|
|
// TODO
|
2008-12-09 14:13:29 +01:00
|
|
|
Project::restoreSettingsImpl(reader);
|
2008-12-05 16:30:26 +01:00
|
|
|
if (buildConfigurations().isEmpty()) {
|
|
|
|
// No build configuration, adding those
|
|
|
|
CMakeStep *cmakeStep = new CMakeStep(this);
|
|
|
|
MakeStep *makeStep = new MakeStep(this);
|
|
|
|
|
|
|
|
insertBuildStep(0, cmakeStep);
|
|
|
|
insertBuildStep(1, makeStep);
|
|
|
|
|
2009-01-12 15:10:33 +01:00
|
|
|
addBuildConfiguration("all");
|
|
|
|
setActiveBuildConfiguration("all");
|
|
|
|
makeStep->setBuildTarget("all", "all", true);
|
2008-12-12 17:22:02 +01:00
|
|
|
|
2009-01-12 15:10:33 +01:00
|
|
|
// Create run configurations for m_targets
|
|
|
|
qDebug()<<"Create run configurations of m_targets";
|
2008-12-12 17:22:02 +01:00
|
|
|
bool setActive = false;
|
2008-12-09 14:13:29 +01:00
|
|
|
foreach(const CMakeTarget &ct, m_targets) {
|
2009-01-12 17:51:50 +01:00
|
|
|
if (ct.executable.isEmpty())
|
|
|
|
continue;
|
2008-12-09 14:13:29 +01:00
|
|
|
QSharedPointer<ProjectExplorer::RunConfiguration> rc(new CMakeRunConfiguration(this, ct.executable, ct.workingDirectory));
|
|
|
|
addRunConfiguration(rc);
|
2008-12-12 17:22:02 +01:00
|
|
|
// The first one gets the honour of beeing the active one
|
|
|
|
if (!setActive) {
|
|
|
|
setActiveRunConfiguration(rc);
|
|
|
|
setActive = true;
|
|
|
|
}
|
2008-12-09 14:13:29 +01:00
|
|
|
}
|
|
|
|
|
2008-12-05 16:30:26 +01:00
|
|
|
}
|
|
|
|
// Restoring is fine
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CMakeFile::CMakeFile(CMakeProject *parent, QString fileName)
|
|
|
|
: Core::IFile(parent), m_project(parent), m_fileName(fileName)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMakeFile::save(const QString &fileName)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
// Once we have an texteditor open for this file, we probably do
|
|
|
|
// need to implement this, don't we.
|
|
|
|
Q_UNUSED(fileName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeFile::fileName() const
|
|
|
|
{
|
|
|
|
return m_fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeFile::defaultPath() const
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeFile::suggestedFileName() const
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeFile::mimeType() const
|
|
|
|
{
|
|
|
|
return Constants::CMAKEMIMETYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CMakeFile::isModified() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMakeFile::isReadOnly() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMakeFile::isSaveAsAllowed() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeFile::modified(ReloadBehavior *behavior)
|
|
|
|
{
|
|
|
|
Q_UNUSED(behavior);
|
|
|
|
}
|
|
|
|
|
2009-01-12 15:10:33 +01:00
|
|
|
CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeProject *project)
|
|
|
|
: m_project(project)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-12 15:10:33 +01:00
|
|
|
QFormLayout *fl = new QFormLayout(this);
|
|
|
|
setLayout(fl);
|
|
|
|
m_pathChooser = new Core::Utils::PathChooser(this);
|
|
|
|
m_pathChooser->setEnabled(false);
|
|
|
|
// TODO currently doesn't work
|
|
|
|
// since creating the cbp file also creates makefiles
|
|
|
|
// and then cmake builds in that directory instead of shadow building
|
|
|
|
// We need our own generator for that to work
|
|
|
|
connect(m_pathChooser, SIGNAL(changed()), this, SLOT(buildDirectoryChanged()));
|
|
|
|
fl->addRow("Build directory:", m_pathChooser);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeBuildSettingsWidget::displayName() const
|
|
|
|
{
|
|
|
|
return "CMake";
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeBuildSettingsWidget::init(const QString &buildConfiguration)
|
|
|
|
{
|
2009-01-12 15:10:33 +01:00
|
|
|
m_buildConfiguration = buildConfiguration;
|
|
|
|
m_pathChooser->setPath(m_project->buildDirectory(buildConfiguration));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2008-12-02 17:56:21 +01:00
|
|
|
|
2009-01-12 15:10:33 +01:00
|
|
|
void CMakeBuildSettingsWidget::buildDirectoryChanged()
|
|
|
|
{
|
|
|
|
m_project->setValue(m_buildConfiguration, "buildDirectory", m_pathChooser->path());
|
|
|
|
}
|
|
|
|
|
|
|
|
/////
|
|
|
|
// CMakeCbpParser
|
|
|
|
////
|
|
|
|
|
2008-12-02 17:56:21 +01:00
|
|
|
bool CMakeCbpParser::parseCbpFile(const QString &fileName)
|
|
|
|
{
|
|
|
|
QFile fi(fileName);
|
|
|
|
if (fi.exists() && fi.open(QFile::ReadOnly)) {
|
|
|
|
setDevice(&fi);
|
|
|
|
|
2008-12-09 11:07:24 +01:00
|
|
|
while (!atEnd()) {
|
2008-12-02 17:56:21 +01:00
|
|
|
readNext();
|
|
|
|
if (name() == "CodeBlocks_project_file") {
|
|
|
|
parseCodeBlocks_project_file();
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fi.close();
|
|
|
|
m_includeFiles.sort();
|
|
|
|
m_includeFiles.removeDuplicates();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseCodeBlocks_project_file()
|
|
|
|
{
|
2008-12-09 11:07:24 +01:00
|
|
|
while (!atEnd()) {
|
2008-12-02 17:56:21 +01:00
|
|
|
readNext();
|
|
|
|
if (isEndElement()) {
|
|
|
|
return;
|
|
|
|
} else if (name() == "Project") {
|
|
|
|
parseProject();
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseProject()
|
|
|
|
{
|
2008-12-09 11:07:24 +01:00
|
|
|
while (!atEnd()) {
|
2008-12-02 17:56:21 +01:00
|
|
|
readNext();
|
|
|
|
if (isEndElement()) {
|
|
|
|
return;
|
2009-01-15 14:48:28 +00:00
|
|
|
} else if (name() == "Option") {
|
|
|
|
parseOption();
|
2008-12-02 17:56:21 +01:00
|
|
|
} else if (name() == "Unit") {
|
|
|
|
parseUnit();
|
|
|
|
} else if (name() == "Build") {
|
|
|
|
parseBuild();
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseBuild()
|
|
|
|
{
|
2008-12-09 11:07:24 +01:00
|
|
|
while (!atEnd()) {
|
2008-12-02 17:56:21 +01:00
|
|
|
readNext();
|
|
|
|
if (isEndElement()) {
|
|
|
|
return;
|
|
|
|
} else if (name() == "Target") {
|
|
|
|
parseTarget();
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseTarget()
|
|
|
|
{
|
2008-12-08 12:24:31 +01:00
|
|
|
m_targetType = false;
|
2008-12-09 14:13:29 +01:00
|
|
|
m_target.clear();
|
|
|
|
|
|
|
|
if (attributes().hasAttribute("title"))
|
|
|
|
m_target.title = attributes().value("title").toString();
|
2008-12-09 14:33:09 +01:00
|
|
|
while (!atEnd()) {
|
2008-12-02 17:56:21 +01:00
|
|
|
readNext();
|
|
|
|
if (isEndElement()) {
|
2009-01-12 17:51:50 +01:00
|
|
|
if (m_targetType || m_target.title == "all" || m_target.title == "install") {
|
2008-12-09 14:13:29 +01:00
|
|
|
m_targets.append(m_target);
|
2008-12-08 12:24:31 +01:00
|
|
|
}
|
2008-12-02 17:56:21 +01:00
|
|
|
return;
|
|
|
|
} else if (name() == "Compiler") {
|
|
|
|
parseCompiler();
|
2008-12-08 12:24:31 +01:00
|
|
|
} else if (name() == "Option") {
|
|
|
|
parseTargetOption();
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseTargetOption()
|
|
|
|
{
|
|
|
|
if (attributes().hasAttribute("output"))
|
2008-12-09 14:13:29 +01:00
|
|
|
m_target.executable = attributes().value("output").toString();
|
2008-12-08 12:24:31 +01:00
|
|
|
else if (attributes().hasAttribute("type") && attributes().value("type") == "1")
|
|
|
|
m_targetType = true;
|
2008-12-09 14:13:29 +01:00
|
|
|
else if (attributes().hasAttribute("working_dir"))
|
|
|
|
m_target.workingDirectory = attributes().value("working_dir").toString();
|
2008-12-09 14:33:09 +01:00
|
|
|
while (!atEnd()) {
|
2008-12-09 14:13:29 +01:00
|
|
|
readNext();
|
|
|
|
if (isEndElement()) {
|
|
|
|
return;
|
|
|
|
} else if (name() == "MakeCommand") {
|
|
|
|
parseMakeCommand();
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 14:48:28 +00:00
|
|
|
QString CMakeCbpParser::projectName() const
|
|
|
|
{
|
|
|
|
return m_projectName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseOption()
|
|
|
|
{
|
|
|
|
if (attributes().hasAttribute("title"))
|
|
|
|
m_projectName = attributes().value("title").toString();
|
|
|
|
if(isStartElement())
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
|
2008-12-09 14:13:29 +01:00
|
|
|
void CMakeCbpParser::parseMakeCommand()
|
|
|
|
{
|
2008-12-09 14:33:09 +01:00
|
|
|
while (!atEnd()) {
|
2008-12-09 14:13:29 +01:00
|
|
|
readNext();
|
|
|
|
if (isEndElement()) {
|
|
|
|
return;
|
|
|
|
} else if (name() == "Build") {
|
|
|
|
parseTargetBuild();
|
|
|
|
} else if (name() == "Clean") {
|
|
|
|
parseTargetClean();
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseTargetBuild()
|
|
|
|
{
|
|
|
|
if (attributes().hasAttribute("command"))
|
|
|
|
m_target.makeCommand = attributes().value("command").toString();
|
2008-12-09 14:33:09 +01:00
|
|
|
while (!atEnd()) {
|
2008-12-09 14:13:29 +01:00
|
|
|
readNext();
|
|
|
|
if (isEndElement()) {
|
|
|
|
return;
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseTargetClean()
|
|
|
|
{
|
|
|
|
if (attributes().hasAttribute("command"))
|
|
|
|
m_target.makeCleanCommand = attributes().value("command").toString();
|
2008-12-09 14:33:09 +01:00
|
|
|
while (!atEnd()) {
|
2008-12-08 12:24:31 +01:00
|
|
|
readNext();
|
|
|
|
if (isEndElement()) {
|
|
|
|
return;
|
2008-12-02 17:56:21 +01:00
|
|
|
} else if (isStartElement()) {
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseCompiler()
|
|
|
|
{
|
2008-12-09 11:07:24 +01:00
|
|
|
while (!atEnd()) {
|
2008-12-02 17:56:21 +01:00
|
|
|
readNext();
|
|
|
|
if (isEndElement()) {
|
|
|
|
return;
|
|
|
|
} else if (name() == "Add") {
|
|
|
|
parseAdd();
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseAdd()
|
|
|
|
{
|
|
|
|
m_includeFiles.append(attributes().value("directory").toString());
|
2008-12-09 11:07:24 +01:00
|
|
|
while (!atEnd()) {
|
2008-12-02 17:56:21 +01:00
|
|
|
readNext();
|
|
|
|
if (isEndElement()) {
|
|
|
|
return;
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseUnit()
|
|
|
|
{
|
|
|
|
//qDebug()<<stream.attributes().value("filename");
|
|
|
|
QString fileName = attributes().value("filename").toString();
|
|
|
|
if (!fileName.endsWith(".rule"))
|
|
|
|
m_fileList.append( new ProjectExplorer::FileNode(fileName, ProjectExplorer::SourceType, false));
|
2008-12-09 11:07:24 +01:00
|
|
|
while (!atEnd()) {
|
2008-12-02 17:56:21 +01:00
|
|
|
readNext();
|
|
|
|
if (isEndElement()) {
|
|
|
|
return;
|
|
|
|
} else if (isStartElement()) {
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeCbpParser::parseUnknownElement()
|
|
|
|
{
|
2008-12-17 15:51:48 +01:00
|
|
|
Q_ASSERT(isStartElement());
|
2008-12-02 17:56:21 +01:00
|
|
|
|
|
|
|
while (!atEnd()) {
|
|
|
|
readNext();
|
|
|
|
|
|
|
|
if (isEndElement())
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (isStartElement())
|
|
|
|
parseUnknownElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<ProjectExplorer::FileNode *> CMakeCbpParser::fileList()
|
|
|
|
{
|
|
|
|
return m_fileList;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList CMakeCbpParser::includeFiles()
|
|
|
|
{
|
|
|
|
return m_includeFiles;
|
|
|
|
}
|
2008-12-09 14:13:29 +01:00
|
|
|
|
|
|
|
QList<CMakeTarget> CMakeCbpParser::targets()
|
|
|
|
{
|
|
|
|
return m_targets;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeTarget::clear()
|
|
|
|
{
|
|
|
|
executable = QString::null;
|
|
|
|
makeCommand = QString::null;
|
|
|
|
makeCleanCommand = QString::null;
|
|
|
|
workingDirectory = QString::null;
|
|
|
|
title = QString::null;
|
|
|
|
}
|
|
|
|
|