cmakeproject.cpp 21.2 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
7
8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** Alternatively, 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.
24
**
25
26
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "cmakeproject.h"
dt's avatar
dt committed
31
32
#include "ui_cmakeconfigurewidget.h"
#include "cmakeconfigurewidget.h"
con's avatar
con committed
33
34
#include "cmakeprojectconstants.h"
#include "cmakeprojectnodes.h"
hjk's avatar
hjk committed
35
#include "cmakerunconfiguration.h"
36
37
#include "cmakestep.h"
#include "makestep.h"
hjk's avatar
hjk committed
38

39
#include <projectexplorer/projectexplorerconstants.h>
con's avatar
con committed
40
#include <cpptools/cppmodelmanagerinterface.h>
dt's avatar
dt committed
41
#include <extensionsystem/pluginmanager.h>
hjk's avatar
hjk committed
42
#include <utils/qtcassert.h>
dt's avatar
dt committed
43
#include <coreplugin/icore.h>
hjk's avatar
hjk committed
44

con's avatar
con committed
45
#include <QtCore/QDebug>
hjk's avatar
hjk committed
46
47
#include <QtCore/QDir>
#include <QtCore/QProcess>
48
#include <QtGui/QFormLayout>
dt's avatar
dt committed
49
#include <QtGui/QMainWindow>
con's avatar
con committed
50
51
52
53

using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;

54
55
56
57
58
59
60
61
62
63
64

// 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


65

con's avatar
con committed
66
CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName)
67
68
69
70
    : m_manager(manager),
      m_fileName(fileName),
      m_rootNode(new CMakeProjectNode(m_fileName)),
      m_toolChain(0)
con's avatar
con committed
71
72
{
    m_file = new CMakeFile(this, fileName);
73
74
75
76
77
}

CMakeProject::~CMakeProject()
{
    delete m_rootNode;
78
    delete m_toolChain;
79
80
81
82
}

// 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
dt's avatar
dt committed
83
void CMakeProject::parseCMakeLists()
84
{
85
    ProjectExplorer::ToolChain *newToolChain = 0;
dt's avatar
dt committed
86
87
    QString sourceDirectory = QFileInfo(m_fileName).absolutePath();
    m_manager->createXmlFile(cmakeStep()->userArguments(activeBuildConfiguration()), sourceDirectory, buildDirectory(activeBuildConfiguration()));
88

dt's avatar
dt committed
89
    QString cbpFile = findCbpFile(buildDirectory(activeBuildConfiguration()));
90
    CMakeCbpParser cbpparser;
91
    qDebug()<<"Parsing file "<<cbpFile;
92
    if (cbpparser.parseCbpFile(cbpFile)) {
93
94
95
96
97
98
99
100
101
102
        qDebug()<<"CodeBlocks Compilername"<<cbpparser.compilerName();
        if (cbpparser.compilerName() == "gcc") {
            newToolChain = ProjectExplorer::ToolChain::createGccToolChain("gcc");
        } else if (cbpparser.compilerName() == "msvc8") {
            // TODO hmm
            //newToolChain = ProjectExplorer::ToolChain::createMSVCToolChain("//TODO");
            Q_ASSERT(false);
        } else {
            // TODO hmm?
        }
103
        if (ProjectExplorer::ToolChain::equals(newToolChain, m_toolChain)) {
104
105
106
107
108
109
110
            delete newToolChain;
            newToolChain = 0;
        } else {
            delete m_toolChain;
            m_toolChain = newToolChain;
        }

111
        m_projectName = cbpparser.projectName();
112
        qDebug()<<"Building Tree";
dt's avatar
dt committed
113
        // TODO do a intelligent updating of the tree
114
115
116
117
118
119

        QList<ProjectExplorer::FileNode *> fileList = cbpparser.fileList();
        // Manually add the CMakeLists.txt file
        fileList.append(new ProjectExplorer::FileNode(sourceDirectory + "/CMakeLists.txt", ProjectExplorer::ProjectFileType, false));
        buildTree(m_rootNode, fileList);
        foreach (ProjectExplorer::FileNode *fn, fileList)
con's avatar
con committed
120
121
122
            m_files.append(fn->path());
        m_files.sort();

123
        qDebug()<<"Adding Targets";
dt's avatar
dt committed
124
125
126
127
128
129
130
131
132
        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()<<"";
        }

133
        qDebug()<<"Updating CodeModel";
134
135
136
137
138
139
140
141
142
143
144

        QStringList allIncludePaths;
        QStringList allFrameworkPaths;
        QList<ProjectExplorer::HeaderPath> allHeaderPaths = m_toolChain->systemHeaderPaths();
        foreach (ProjectExplorer::HeaderPath headerPath, allHeaderPaths) {
            if (headerPath.kind() == ProjectExplorer::HeaderPath::FrameworkHeaderPath)
                allFrameworkPaths.append(headerPath.path());
            else
                allIncludePaths.append(headerPath.path());
        }
        allIncludePaths.append(cbpparser.includeFiles());
con's avatar
con committed
145
146
        CppTools::CppModelManagerInterface *modelmanager = ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>();
        if (modelmanager) {
147
            CppTools::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this);
148
            pinfo.includePaths = allIncludePaths;
149
            // TODO we only want C++ files, not all other stuff that might be in the project
150
            pinfo.sourceFiles = m_files;
151
152
            pinfo.defines = m_toolChain->predefinedMacros();
            pinfo.frameworkPaths = allFrameworkPaths;
153
            modelmanager->updateProjectInfo(pinfo);
con's avatar
con committed
154
155
156
        }
    } else {
        // TODO report error
157
158
        delete m_toolChain;
        m_toolChain = 0;
con's avatar
con committed
159
160
161
    }
}

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
QString CMakeProject::buildParser(const QString &buildConfiguration) const
{
    if (!m_toolChain)
        return QString::null;
    if (m_toolChain->type() == ProjectExplorer::ToolChain::GCC
        || m_toolChain->type() == ProjectExplorer::ToolChain::LinuxICC
        || m_toolChain->type() == ProjectExplorer::ToolChain::MinGW) {
        return ProjectExplorer::Constants::BUILD_PARSER_GCC;
    } else if (m_toolChain->type() == ProjectExplorer::ToolChain::MSVC
               || m_toolChain->type() == ProjectExplorer::ToolChain::WINCE) {
        return ProjectExplorer::Constants::BUILD_PARSER_MSVC;
    }
    return QString::null;
}

177
QStringList CMakeProject::targets() const
con's avatar
con committed
178
{
179
180
181
182
    QStringList results;
    foreach(const CMakeTarget &ct, m_targets)
        results << ct.title;
    return results;
con's avatar
con committed
183
184
185
186
187
188
189
190
}

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
hjk's avatar
hjk committed
191
192
    foreach (const QString &cbpFile , directory.entryList()) {
        if (cbpFile.endsWith(".cbp"))
con's avatar
con committed
193
194
195
196
197
198
199
200
201
202
            return directory.path() + "/" + cbpFile;
    }
    return QString::null;
}


void CMakeProject::buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list)
{
    //m_rootNode->addFileNodes(fileList, m_rootNode);
    qSort(list.begin(), list.end(), ProjectExplorer::ProjectNode::sortNodesByPath);
hjk's avatar
hjk committed
203
    foreach (ProjectExplorer::FileNode *fn, list) {
con's avatar
con committed
204
205
206
207
208
209
210
211
212
213
214
        // 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);
215
    QStringList parts = relativePath.split("/", QString::SkipEmptyParts);
con's avatar
con committed
216
    ProjectExplorer::FolderNode *parent = rootNode;
hjk's avatar
hjk committed
217
    foreach (const QString &part, parts) {
con's avatar
con committed
218
219
        // Find folder in subFolders
        bool found = false;
hjk's avatar
hjk committed
220
        foreach (ProjectExplorer::FolderNode *folder, parent->subFolderNodes()) {
con's avatar
con committed
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
            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
{
240
    return m_projectName;
con's avatar
con committed
241
242
}

243
244


con's avatar
con committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
Core::IFile *CMakeProject::file() const
{
    return m_file;
}

ProjectExplorer::IProjectManager *CMakeProject::projectManager() const
{
    return m_manager;
}

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
{
274
275
    QString buildDirectory = value(buildConfiguration, "buildDirectory").toString();
    if (buildDirectory.isEmpty())
276
        buildDirectory = QFileInfo(m_fileName).absolutePath() + "/qtcreator-build";
277
    return buildDirectory;
con's avatar
con committed
278
279
280
281
}

ProjectExplorer::BuildStepConfigWidget *CMakeProject::createConfigWidget()
{
282
    return new CMakeBuildSettingsWidget(this);
con's avatar
con committed
283
284
285
286
287
288
289
290
291
292
293
}

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)
 {
294
295
     // Default to all
     makeStep()->setBuildTarget(buildConfiguration, "all", true);
con's avatar
con committed
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
 }

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
dt's avatar
dt committed
314
    Project::saveSettingsImpl(writer);
con's avatar
con committed
315
316
}

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
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;
}

con's avatar
con committed
336
337
338
void CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader)
{
    // TODO
dt's avatar
dt committed
339
    Project::restoreSettingsImpl(reader);
dt's avatar
dt committed
340
341
342
343
344
345
346
347
348
349
350
351
352
353
    bool hasUserFile = !buildConfigurations().isEmpty();
    if (!hasUserFile) {
        // Ask the user for where he wants to build it
        // and the cmake command line

        // TODO check wheter there's already a CMakeCache.txt in the src directory,
        // then we don't need to ask, we simply need to build in the src directory

        CMakeConfigureDialog ccd(Core::ICore::instance()->mainWindow(), m_manager, QFileInfo(m_fileName).absolutePath());
        ccd.exec();

        qDebug()<<"ccd.buildDirectory()"<<ccd.buildDirectory();

        // Now create a standard build configuration
354
355
356
357
358
359
        CMakeStep *cmakeStep = new CMakeStep(this);
        MakeStep *makeStep = new MakeStep(this);

        insertBuildStep(0, cmakeStep);
        insertBuildStep(1, makeStep);

360
361
362
        addBuildConfiguration("all");
        setActiveBuildConfiguration("all");
        makeStep->setBuildTarget("all", "all", true);
dt's avatar
dt committed
363
364
365
366
367
368
        if (!ccd.buildDirectory().isEmpty())
        setValue("all", "buildDirectory", ccd.buildDirectory());
        cmakeStep->setUserArguments("all", ccd.arguments());
    }

    parseCMakeLists(); // Gets the directory from the active buildconfiguration
369

dt's avatar
dt committed
370
    if (!hasUserFile) {
371
372
        // Create run configurations for m_targets
        qDebug()<<"Create run configurations of m_targets";
373
        bool setActive = false;
dt's avatar
dt committed
374
        foreach(const CMakeTarget &ct, m_targets) {
375
376
            if (ct.executable.isEmpty())
                continue;
dt's avatar
dt committed
377
378
            QSharedPointer<ProjectExplorer::RunConfiguration> rc(new CMakeRunConfiguration(this, ct.executable, ct.workingDirectory));
            addRunConfiguration(rc);
379
380
381
382
383
            // The first one gets the honour of beeing the active one
            if (!setActive) {
                setActiveRunConfiguration(rc);
                setActive = true;
            }
dt's avatar
dt committed
384
385
        }

386
    }
con's avatar
con committed
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
}


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);
}

446
447
CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeProject *project)
    : m_project(project)
con's avatar
con committed
448
{
449
450
451
452
453
454
455
456
457
458
    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);
con's avatar
con committed
459
460
461
462
463
464
465
466
467
}

QString CMakeBuildSettingsWidget::displayName() const
{
    return "CMake";
}

void CMakeBuildSettingsWidget::init(const QString &buildConfiguration)
{
468
469
    m_buildConfiguration = buildConfiguration;
    m_pathChooser->setPath(m_project->buildDirectory(buildConfiguration));
con's avatar
con committed
470
}
471

472
473
474
475
476
477
478
479
480
void CMakeBuildSettingsWidget::buildDirectoryChanged()
{
    m_project->setValue(m_buildConfiguration, "buildDirectory", m_pathChooser->path());
}

/////
// CMakeCbpParser
////

481
482
483
484
485
486
bool CMakeCbpParser::parseCbpFile(const QString &fileName)
{
    QFile fi(fileName);
    if (fi.exists() && fi.open(QFile::ReadOnly)) {
        setDevice(&fi);

hjk's avatar
hjk committed
487
        while (!atEnd()) {
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
            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()
{
hjk's avatar
hjk committed
505
    while (!atEnd()) {
506
507
508
509
510
511
512
513
514
515
516
517
518
        readNext();
        if (isEndElement()) {
            return;
        } else if (name() == "Project") {
            parseProject();
        } else if (isStartElement()) {
            parseUnknownElement();
        }
    }
}

void CMakeCbpParser::parseProject()
{
hjk's avatar
hjk committed
519
    while (!atEnd()) {
520
521
522
        readNext();
        if (isEndElement()) {
            return;
523
524
        } else if (name() == "Option") {
            parseOption();
525
526
527
528
529
530
531
532
533
534
535
536
        } else if (name() == "Unit") {
            parseUnit();
        } else if (name() == "Build") {
            parseBuild();
        } else if (isStartElement()) {
            parseUnknownElement();
        }
    }
}

void CMakeCbpParser::parseBuild()
{
hjk's avatar
hjk committed
537
    while (!atEnd()) {
538
539
540
541
542
543
544
545
546
547
548
549
550
        readNext();
        if (isEndElement()) {
            return;
        } else if (name() == "Target") {
            parseTarget();
        } else if (isStartElement()) {
            parseUnknownElement();
        }
    }
}

void CMakeCbpParser::parseTarget()
{
dt's avatar
dt committed
551
    m_targetType = false;
dt's avatar
dt committed
552
553
554
555
    m_target.clear();

    if (attributes().hasAttribute("title"))
        m_target.title = attributes().value("title").toString();
dt's avatar
dt committed
556
    while (!atEnd()) {
557
558
        readNext();
        if (isEndElement()) {
559
            if (m_targetType || m_target.title == "all" || m_target.title == "install") {
dt's avatar
dt committed
560
                m_targets.append(m_target);
dt's avatar
dt committed
561
            }
562
563
564
            return;
        } else if (name() == "Compiler") {
            parseCompiler();
dt's avatar
dt committed
565
566
567
568
569
570
571
572
573
574
575
        } else if (name() == "Option") {
            parseTargetOption();
        } else if (isStartElement()) {
            parseUnknownElement();
        }
    }
}

void CMakeCbpParser::parseTargetOption()
{
    if (attributes().hasAttribute("output"))
dt's avatar
dt committed
576
        m_target.executable = attributes().value("output").toString();
577
    else if (attributes().hasAttribute("type") && (attributes().value("type") == "1" || attributes().value("type") == "0"))
dt's avatar
dt committed
578
        m_targetType = true;
dt's avatar
dt committed
579
580
    else if (attributes().hasAttribute("working_dir"))
        m_target.workingDirectory = attributes().value("working_dir").toString();
dt's avatar
dt committed
581
    while (!atEnd()) {
dt's avatar
dt committed
582
583
584
585
586
587
588
589
590
591
592
        readNext();
        if (isEndElement()) {
            return;
        } else if (name() == "MakeCommand") {
            parseMakeCommand();
        } else if (isStartElement()) {
            parseUnknownElement();
        }
    }
}

593
594
595
596
597
598
599
600
601
QString CMakeCbpParser::projectName() const
{
    return m_projectName;
}

void CMakeCbpParser::parseOption()
{
    if (attributes().hasAttribute("title"))
        m_projectName = attributes().value("title").toString();
602

603
604
605
    if (attributes().hasAttribute("compiler"))
        m_compiler = attributes().value("compiler").toString();

606
607
608
609
610
611
612
613
    while (!atEnd()) {
        readNext();
        if (isEndElement()) {
            return;
        } else if(isStartElement()) {
            parseUnknownElement();
        }
    }
614
615
}

dt's avatar
dt committed
616
617
void CMakeCbpParser::parseMakeCommand()
{
dt's avatar
dt committed
618
    while (!atEnd()) {
dt's avatar
dt committed
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
        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();
dt's avatar
dt committed
636
    while (!atEnd()) {
dt's avatar
dt committed
637
638
639
640
641
642
643
644
645
646
647
648
649
        readNext();
        if (isEndElement()) {
            return;
        } else if (isStartElement()) {
            parseUnknownElement();
        }
    }
}

void CMakeCbpParser::parseTargetClean()
{
    if (attributes().hasAttribute("command"))
        m_target.makeCleanCommand = attributes().value("command").toString();
dt's avatar
dt committed
650
    while (!atEnd()) {
dt's avatar
dt committed
651
652
653
        readNext();
        if (isEndElement()) {
            return;
654
655
656
657
658
659
660
661
        } else if (isStartElement()) {
            parseUnknownElement();
        }
    }
}

void CMakeCbpParser::parseCompiler()
{
hjk's avatar
hjk committed
662
    while (!atEnd()) {
663
664
665
666
667
668
669
670
671
672
673
674
675
676
        readNext();
        if (isEndElement()) {
            return;
        } else if (name() == "Add") {
            parseAdd();
        } else if (isStartElement()) {
            parseUnknownElement();
        }
    }
}

void CMakeCbpParser::parseAdd()
{
    m_includeFiles.append(attributes().value("directory").toString());
hjk's avatar
hjk committed
677
    while (!atEnd()) {
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
        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));
hjk's avatar
hjk committed
693
    while (!atEnd()) {
694
695
696
697
698
699
700
701
702
703
704
        readNext();
        if (isEndElement()) {
            return;
        } else if (isStartElement()) {
            parseUnknownElement();
        }
    }
}

void CMakeCbpParser::parseUnknownElement()
{
dt's avatar
dt committed
705
    Q_ASSERT(isStartElement());
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726

    while (!atEnd()) {
        readNext();

        if (isEndElement())
            break;

        if (isStartElement())
            parseUnknownElement();
    }
}

QList<ProjectExplorer::FileNode *> CMakeCbpParser::fileList()
{
    return m_fileList;
}

QStringList CMakeCbpParser::includeFiles()
{
    return m_includeFiles;
}
dt's avatar
dt committed
727
728
729
730
731
732

QList<CMakeTarget> CMakeCbpParser::targets()
{
    return m_targets;
}

733
734
735
736
737
QString CMakeCbpParser::compilerName() const
{
    return m_compiler;
}

dt's avatar
dt committed
738
739
740
741
742
743
744
745
746
void CMakeTarget::clear()
{
    executable = QString::null;
    makeCommand = QString::null;
    makeCleanCommand = QString::null;
    workingDirectory = QString::null;
    title = QString::null;
}