qbsproject.cpp 21 KB
Newer Older
Tobias Hunger's avatar
Tobias Hunger committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#include "qbsproject.h"

#include "qbsbuildconfiguration.h"
33
#include "qbslogsink.h"
Tobias Hunger's avatar
Tobias Hunger committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "qbsprojectfile.h"
#include "qbsprojectmanagerconstants.h"
#include "qbsnodes.h"

#include <coreplugin/documentmanager.h>
#include <utils/qtcassert.h>

#include <language/language.h>

#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/id.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/mimedatabase.h>
#include <cpptools/cppmodelmanager.h>
#include <projectexplorer/buildenvironmentwidget.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h>
56
#include <projectexplorer/toolchain.h>
57
#include <projectexplorer/headerpath.h>
Tobias Hunger's avatar
Tobias Hunger committed
58
#include <qtsupport/qtkitinformation.h>
59
#include <qmljstools/qmljsmodelmanager.h>
Tobias Hunger's avatar
Tobias Hunger committed
60
61
62
63
64
65
66
67
68
69
70
71

#include <qmljs/qmljsmodelmanagerinterface.h>

#include <qbs.h>
#include <tools/scripttools.h> // qbs, remove once there is a expand method in Qbs itself!

#include <QFileInfo>

// --------------------------------------------------------------------
// Constants:
// --------------------------------------------------------------------

72
73
static const char CONFIG_CPP_MODULE[] = "cpp";
static const char CONFIG_CXXFLAGS[] = "cxxflags";
74
static const char CONFIG_CFLAGS[] = "cflags";
75
76
77
78
static const char CONFIG_DEFINES[] = "defines";
static const char CONFIG_INCLUDEPATHS[] = "includePaths";
static const char CONFIG_FRAMEWORKPATHS[] = "frameworkPaths";
static const char CONFIG_PRECOMPILEDHEADER[] = "precompiledHeader";
Tobias Hunger's avatar
Tobias Hunger committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

static const char CONFIGURATION_PATH[] = "<configuration>";

// --------------------------------------------------------------------
// HELPERS:
// --------------------------------------------------------------------

ProjectExplorer::TaskHub *taskHub()
{
    return ProjectExplorer::ProjectExplorerPlugin::instance()->taskHub();
}


namespace QbsProjectManager {
namespace Internal {

// --------------------------------------------------------------------
// QbsProject:
// --------------------------------------------------------------------

QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
100
101
102
    m_manager(manager),
    m_projectName(QFileInfo(fileName).completeBaseName()),
    m_fileName(fileName),
103
    m_rootProjectNode(0),
Tobias Hunger's avatar
Tobias Hunger committed
104
105
    m_qbsSetupProjectJob(0),
    m_qbsUpdateFutureInterface(0),
106
107
    m_currentProgressBase(0),
    m_forceParsing(false),
Tobias Hunger's avatar
Tobias Hunger committed
108
109
    m_currentBc(0)
{
110
    m_parsingDelay.setInterval(1000); // delay parsing by 1s.
111

Tobias Hunger's avatar
Tobias Hunger committed
112
    setProjectContext(Core::Context(Constants::PROJECT_ID));
113
    setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
Tobias Hunger's avatar
Tobias Hunger committed
114
115
116
117
118

    connect(this, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
            this, SLOT(changeActiveTarget(ProjectExplorer::Target*)));
    connect(this, SIGNAL(addedTarget(ProjectExplorer::Target*)),
            this, SLOT(targetWasAdded(ProjectExplorer::Target*)));
119
120
121
    connect(this, SIGNAL(environmentChanged()), this, SLOT(delayParsing()));

    connect(&m_parsingDelay, SIGNAL(timeout()), this, SLOT(parseCurrentBuildConfiguration()));
Tobias Hunger's avatar
Tobias Hunger committed
122

123
    updateDocuments(QSet<QString>() << fileName);
124
    m_rootProjectNode = new QbsProjectNode(this); // needs documents to be initialized!
Tobias Hunger's avatar
Tobias Hunger committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
}

QbsProject::~QbsProject()
{
    m_codeModelFuture.cancel();
}

QString QbsProject::displayName() const
{
    return m_projectName;
}

Core::Id QbsProject::id() const
{
    return Core::Id(Constants::PROJECT_ID);
}

Core::IDocument *QbsProject::document() const
{
    foreach (Core::IDocument *doc, m_qbsDocuments) {
        if (doc->fileName() == m_fileName)
            return doc;
    }
    QTC_ASSERT(false, return 0);
}

QbsManager *QbsProject::projectManager() const
{
    return m_manager;
}

ProjectExplorer::ProjectNode *QbsProject::rootProjectNode() const
{
    return m_rootProjectNode;
}

QStringList QbsProject::files(ProjectExplorer::Project::FilesMode fileMode) const
{
    Q_UNUSED(fileMode);
164
    QSet<QString> result;
165
166
    if (m_rootProjectNode && m_rootProjectNode->qbsProjectData().isValid()) {
        foreach (const qbs::ProductData &prd, m_rootProjectNode->qbsProjectData().allProducts()) {
167
168
169
            foreach (const qbs::GroupData &grp, prd.groups()) {
                foreach (const QString &file, grp.allFilePaths())
                    result.insert(file);
170
                result.insert(grp.location().fileName());
171
            }
172
            result.insert(prd.location().fileName());
173
        }
174
        result.insert(m_rootProjectNode->qbsProjectData().location().fileName());
Tobias Hunger's avatar
Tobias Hunger committed
175
    }
176
    return result.toList();
Tobias Hunger's avatar
Tobias Hunger committed
177
178
179
180
181
182
183
}

void QbsProject::invalidate()
{
    prepareForParsing();
}

184
qbs::BuildJob *QbsProject::build(const qbs::BuildOptions &opts, QStringList productNames)
Tobias Hunger's avatar
Tobias Hunger committed
185
{
Tobias Hunger's avatar
Tobias Hunger committed
186
    if (!qbsProject() || isParsing())
Tobias Hunger's avatar
Tobias Hunger committed
187
        return 0;
188
189
190
191
192
193
    if (productNames.isEmpty()) {
        return qbsProject()->buildAllProducts(opts);
    } else {
        QList<qbs::ProductData> products;
        foreach (const QString &productName, productNames) {
            bool found = false;
194
            foreach (const qbs::ProductData &data, qbsProjectData().allProducts()) {
195
196
197
198
199
200
201
202
203
204
205
206
                if (data.name() == productName) {
                    found = true;
                    products.append(data);
                    break;
                }
            }
            if (!found)
                return 0;
        }

        return qbsProject()->buildSomeProducts(products, opts);
    }
Tobias Hunger's avatar
Tobias Hunger committed
207
208
}

209
qbs::CleanJob *QbsProject::clean(const qbs::CleanOptions &opts)
Tobias Hunger's avatar
Tobias Hunger committed
210
{
211
    if (!qbsProject())
Tobias Hunger's avatar
Tobias Hunger committed
212
        return 0;
213
    return qbsProject()->cleanAllProducts(opts);
Tobias Hunger's avatar
Tobias Hunger committed
214
215
}

Tobias Hunger's avatar
Tobias Hunger committed
216
217
218
219
220
221
222
qbs::InstallJob *QbsProject::install(const qbs::InstallOptions &opts)
{
    if (!qbsProject())
        return 0;
    return qbsProject()->installAllProducts(opts);
}

Tobias Hunger's avatar
Tobias Hunger committed
223
224
225
226
227
228
229
230
231
232
233
234
QString QbsProject::profileForTarget(const ProjectExplorer::Target *t) const
{
    return m_manager->profileForKit(t->kit());
}

bool QbsProject::isParsing() const
{
    return m_qbsUpdateFutureInterface;
}

bool QbsProject::hasParseResult() const
{
235
    return qbsProject();
Tobias Hunger's avatar
Tobias Hunger committed
236
237
238
239
240
241
242
243
244
}

Utils::FileName QbsProject::defaultBuildDirectory() const
{
    QFileInfo fi(m_fileName);
    const QString buildDir = QDir(fi.canonicalPath()).absoluteFilePath(QString::fromLatin1("../%1-build").arg(fi.baseName()));
    return Utils::FileName::fromString(buildDir);
}

245
246
247
248
const qbs::Project *QbsProject::qbsProject() const
{
    if (!m_rootProjectNode)
        return 0;
249
    return m_rootProjectNode->qbsProject();
250
251
}

252
const qbs::ProjectData QbsProject::qbsProjectData() const
253
254
{
    if (!m_rootProjectNode)
255
        return qbs::ProjectData();
256
    return m_rootProjectNode->qbsProjectData();
257
258
}

259
260
261
262
263
bool QbsProject::needsSpecialDeployment() const
{
    return true;
}

Tobias Hunger's avatar
Tobias Hunger committed
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
void QbsProject::handleQbsParsingDone(bool success)
{
    QTC_ASSERT(m_qbsSetupProjectJob, return);
    QTC_ASSERT(m_qbsUpdateFutureInterface, return);

    qbs::Project *project = 0;
    if (success) {
        project = new qbs::Project(m_qbsSetupProjectJob->project());
    } else {
        generateErrors(m_qbsSetupProjectJob->error());
        m_qbsUpdateFutureInterface->reportCanceled();
    }
    m_qbsSetupProjectJob->deleteLater();
    m_qbsSetupProjectJob = 0;

    m_qbsUpdateFutureInterface->reportFinished();
    delete m_qbsUpdateFutureInterface;
    m_qbsUpdateFutureInterface = 0;

    m_rootProjectNode->update(project);

285
    updateDocuments(project ? project->buildSystemFiles() : QSet<QString>() << m_fileName);
Tobias Hunger's avatar
Tobias Hunger committed
286

287
288
    updateCppCodeModel(m_rootProjectNode->qbsProjectData());
    updateQmlJsCodeModel(m_rootProjectNode->qbsProjectData());
Tobias Hunger's avatar
Tobias Hunger committed
289

Tobias Hunger's avatar
Tobias Hunger committed
290
291
292
    foreach (ProjectExplorer::Target *t, targets())
        t->updateDefaultRunConfigurations();

293
    emit fileListChanged();
Tobias Hunger's avatar
Tobias Hunger committed
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
    emit projectParsingDone(success);
}

void QbsProject::handleQbsParsingProgress(int progress)
{
    if (m_qbsUpdateFutureInterface)
        m_qbsUpdateFutureInterface->setProgressValue(m_currentProgressBase + progress);
}

void QbsProject::handleQbsParsingTaskSetup(const QString &description, int maximumProgressValue)
{
    Q_UNUSED(description);
    if (m_qbsUpdateFutureInterface) {
        m_currentProgressBase = m_qbsUpdateFutureInterface->progressValue();
        m_qbsUpdateFutureInterface->setProgressRange(0, m_currentProgressBase + maximumProgressValue);
    }
}

void QbsProject::targetWasAdded(ProjectExplorer::Target *t)
{
    connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
315
316
            this, SLOT(delayForcedParsing()));
    connect(t, SIGNAL(buildDirectoryChanged()), this, SLOT(delayForcedParsing()));
Tobias Hunger's avatar
Tobias Hunger committed
317
318
319
320
321
322
323
324
325
326
327
328
329
}

void QbsProject::changeActiveTarget(ProjectExplorer::Target *t)
{
    ProjectExplorer::BuildConfiguration *bc = 0;
    if (t && t->kit())
        bc = t->activeBuildConfiguration();
    buildConfigurationChanged(bc);
}

void QbsProject::buildConfigurationChanged(ProjectExplorer::BuildConfiguration *bc)
{
    if (m_currentBc)
330
        disconnect(m_currentBc, SIGNAL(qbsConfigurationChanged()), this, SLOT(delayParsing()));
Tobias Hunger's avatar
Tobias Hunger committed
331
332
333

    m_currentBc = qobject_cast<QbsBuildConfiguration *>(bc);
    if (m_currentBc) {
334
335
        connect(m_currentBc, SIGNAL(qbsConfigurationChanged()), this, SLOT(delayParsing()));
        delayParsing();
Tobias Hunger's avatar
Tobias Hunger committed
336
337
338
339
340
    } else {
        invalidate();
    }
}

341
342
343
344
345
void QbsProject::delayParsing()
{
    m_parsingDelay.start();
}

346
347
348
349
350
351
void QbsProject::delayForcedParsing()
{
    m_forceParsing = true;
    delayParsing();
}

Tobias Hunger's avatar
Tobias Hunger committed
352
353
void QbsProject::parseCurrentBuildConfiguration()
{
354
355
    m_parsingDelay.stop();

Tobias Hunger's avatar
Tobias Hunger committed
356
357
358
359
360
    if (!activeTarget())
        return;
    QbsBuildConfiguration *bc = qobject_cast<QbsBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
    if (!bc)
        return;
Tobias Hunger's avatar
Tobias Hunger committed
361
    parse(bc->qbsConfiguration(), bc->environment(), bc->buildDirectory());
Tobias Hunger's avatar
Tobias Hunger committed
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
}

bool QbsProject::fromMap(const QVariantMap &map)
{
    if (!Project::fromMap(map))
        return false;

    ProjectExplorer::KitManager *km = ProjectExplorer::KitManager::instance();
    if (!activeTarget() && km->defaultKit()) {
        ProjectExplorer::Target *t = new ProjectExplorer::Target(this, km->defaultKit());
        t->updateDefaultBuildConfigurations();
        t->updateDefaultDeployConfigurations();
        t->updateDefaultRunConfigurations();
        addTarget(t);
    }

    return true;
}

381
void QbsProject::generateErrors(const qbs::ErrorInfo &e)
Tobias Hunger's avatar
Tobias Hunger committed
382
{
383
    foreach (const qbs::ErrorItem &item, e.items())
Tobias Hunger's avatar
Tobias Hunger committed
384
        taskHub()->addTask(ProjectExplorer::Task(ProjectExplorer::Task::Error,
385
386
387
                                                 item.description(),
                                                 Utils::FileName::fromString(item.codeLocation().fileName()),
                                                 item.codeLocation().line(),
Tobias Hunger's avatar
Tobias Hunger committed
388
389
390
                                                 ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
}

Tobias Hunger's avatar
Tobias Hunger committed
391
void QbsProject::parse(const QVariantMap &config, const Utils::Environment &env, const QString &dir)
Tobias Hunger's avatar
Tobias Hunger committed
392
393
{
    QTC_ASSERT(!dir.isNull(), return);
394

Tobias Hunger's avatar
Tobias Hunger committed
395
    qbs::SetupProjectParameters params;
396
    params.setBuildConfiguration(config);
397
    qbs::ErrorInfo err = params.expandBuildConfiguration(m_manager->settings());
Tobias Hunger's avatar
Tobias Hunger committed
398
    if (err.hasError()) {
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
        generateErrors(err);
        return;
    }

    // Avoid useless reparsing:
    const qbs::Project *currentProject = qbsProject();
    if (!m_forceParsing
            && currentProject
            && currentProject->projectConfiguration() == params.buildConfiguration()) {
        QHash<QString, QString> usedEnv = currentProject->usedEnvironment();
        bool canSkip = true;
        for (QHash<QString, QString>::const_iterator i = usedEnv.constBegin();
             i != usedEnv.constEnd(); ++i) {
            if (env.value(i.key()) != i.value()) {
                canSkip = false;
                break;
            }
        }
        if (canSkip)
            return;
    }

421
    params.setBuildRoot(dir);
Christian Kandeler's avatar
Christian Kandeler committed
422
423
    params.setProjectFilePath(m_fileName);
    params.setIgnoreDifferentProjectFilePath(false);
Tobias Hunger's avatar
Tobias Hunger committed
424
    params.setEnvironment(env.toProcessEnvironment());
425
    qbs::Preferences *prefs = QbsManager::preferences();
426
    const QString buildDir = qbsBuildDir();
Christian Kandeler's avatar
Christian Kandeler committed
427
428
    params.setSearchPaths(prefs->searchPaths(buildDir));
    params.setPluginPaths(prefs->pluginPaths(buildDir));
Tobias Hunger's avatar
Tobias Hunger committed
429

430
431
432
433
    // Do the parsing:
    prepareForParsing();
    QTC_ASSERT(!m_qbsSetupProjectJob, return);

Tobias Hunger's avatar
Tobias Hunger committed
434
    m_qbsSetupProjectJob
435
            = qbs::Project::setupProject(params, m_manager->logSink(), 0);
Tobias Hunger's avatar
Tobias Hunger committed
436
437
438
439
440
441
442

    connect(m_qbsSetupProjectJob, SIGNAL(finished(bool,qbs::AbstractJob*)),
            this, SLOT(handleQbsParsingDone(bool)));
    connect(m_qbsSetupProjectJob, SIGNAL(taskStarted(QString,int,qbs::AbstractJob*)),
            this, SLOT(handleQbsParsingTaskSetup(QString,int)));
    connect(m_qbsSetupProjectJob, SIGNAL(taskProgress(int,qbs::AbstractJob*)),
            this, SLOT(handleQbsParsingProgress(int)));
443
444

    emit projectParsingStarted();
Tobias Hunger's avatar
Tobias Hunger committed
445
446
447
448
}

void QbsProject::prepareForParsing()
{
449
450
    m_forceParsing = false;

451
    taskHub()->clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_COMPILE);
Tobias Hunger's avatar
Tobias Hunger committed
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
    if (m_qbsUpdateFutureInterface)
        m_qbsUpdateFutureInterface->reportCanceled();
    delete m_qbsUpdateFutureInterface;
    m_qbsUpdateFutureInterface = 0;

    delete m_qbsSetupProjectJob;
    m_qbsSetupProjectJob = 0;

    m_currentProgressBase = 0;
    m_qbsUpdateFutureInterface = new QFutureInterface<void>();
    m_qbsUpdateFutureInterface->setProgressRange(0, 0);
    Core::ICore::progressManager()->addTask(m_qbsUpdateFutureInterface->future(), tr("Evaluating"),
                                            QLatin1String(Constants::QBS_EVALUATE));
    m_qbsUpdateFutureInterface->reportStarted();
}

468
void QbsProject::updateDocuments(const QSet<QString> &files)
Tobias Hunger's avatar
Tobias Hunger committed
469
470
{
    // Update documents:
471
472
    QSet<QString> newFiles = files;
    QTC_ASSERT(!newFiles.isEmpty(), newFiles << m_fileName);
Tobias Hunger's avatar
Tobias Hunger committed
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
    QSet<QString> oldFiles;
    foreach (Core::IDocument *doc, m_qbsDocuments)
        oldFiles.insert(doc->fileName());

    QSet<QString> filesToAdd = newFiles;
    filesToAdd.subtract(oldFiles);
    QSet<QString> filesToRemove = oldFiles;
    filesToRemove.subtract(newFiles);

    QSet<Core::IDocument *> currentDocuments = m_qbsDocuments;
    foreach (Core::IDocument *doc, currentDocuments) {
        if (filesToRemove.contains(doc->fileName())) {
            m_qbsDocuments.remove(doc);
            delete doc;
        }
    }
    QSet<Core::IDocument *> toAdd;
    foreach (const QString &f, filesToAdd)
        toAdd.insert(new QbsProjectFile(this, f));

    Core::DocumentManager::instance()->addDocuments(toAdd.toList());
    m_qbsDocuments.unite(toAdd);
}

497
void QbsProject::updateCppCodeModel(const qbs::ProjectData &prj)
Tobias Hunger's avatar
Tobias Hunger committed
498
{
499
    if (!prj.isValid())
Tobias Hunger's avatar
Tobias Hunger committed
500
501
502
503
504
505
506
507
508
509
        return;

    ProjectExplorer::Kit *k = 0;
    QtSupport::BaseQtVersion *qtVersion = 0;
    if (ProjectExplorer::Target *target = activeTarget())
        k = target->kit();
    else
        k = ProjectExplorer::KitManager::instance()->defaultKit();
    qtVersion = QtSupport::QtKitInformation::qtVersion(k);

510
511
    CppTools::CppModelManagerInterface *modelmanager =
        CppTools::CppModelManagerInterface::instance();
Tobias Hunger's avatar
Tobias Hunger committed
512
513
514
515

    if (!modelmanager)
        return;

516
    CppTools::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this);
Tobias Hunger's avatar
Tobias Hunger committed
517
    pinfo.clearProjectParts();
518
519
    CppTools::ProjectPart::QtVersion qtVersionForPart
            = CppTools::ProjectPart::NoQt;
Tobias Hunger's avatar
Tobias Hunger committed
520
521
    if (qtVersion) {
        if (qtVersion->qtVersion() < QtSupport::QtVersionNumber(5,0,0))
522
            qtVersionForPart = CppTools::ProjectPart::Qt4;
Tobias Hunger's avatar
Tobias Hunger committed
523
        else
524
            qtVersionForPart = CppTools::ProjectPart::Qt5;
Tobias Hunger's avatar
Tobias Hunger committed
525
526
527
    }

    QStringList allFiles;
528
    foreach (const qbs::ProductData &prd, prj.allProducts()) {
Tobias Hunger's avatar
Tobias Hunger committed
529
        foreach (const qbs::GroupData &grp, prd.groups()) {
530
            const qbs::PropertyMap &props = grp.properties();
Tobias Hunger's avatar
Tobias Hunger committed
531

532
533
534
            const QStringList cxxFlags = props.getModulePropertiesAsStringList(
                        QLatin1String(CONFIG_CPP_MODULE),
                        QLatin1String(CONFIG_CXXFLAGS));
Tobias Hunger's avatar
Tobias Hunger committed
535

536
537
538
539
            const QStringList cFlags = props.getModulePropertiesAsStringList(
                        QLatin1String(CONFIG_CPP_MODULE),
                        QLatin1String(CONFIG_CFLAGS));

540
541
542
            QStringList list = props.getModulePropertiesAsStringList(
                        QLatin1String(CONFIG_CPP_MODULE),
                        QLatin1String(CONFIG_DEFINES));
543
            QByteArray grpDefines;
544
545
546
547
548
549
550
            foreach (const QString &def, list) {
                QByteArray data = def.toUtf8();
                int pos = data.indexOf('=');
                if (pos >= 0)
                    data[pos] = ' ';
                grpDefines += (QByteArray("#define ") + data + '\n');
            }
Tobias Hunger's avatar
Tobias Hunger committed
551

552
553
            list = props.getModulePropertiesAsStringList(QLatin1String(CONFIG_CPP_MODULE),
                                                         QLatin1String(CONFIG_INCLUDEPATHS));
554
            QStringList grpIncludePaths;
Tobias Hunger's avatar
Tobias Hunger committed
555
556
557
558
559
            foreach (const QString &p, list) {
                const QString cp = Utils::FileName::fromUserInput(p).toString();
                grpIncludePaths.append(cp);
            }

560
561
            list = props.getModulePropertiesAsStringList(QLatin1String(CONFIG_CPP_MODULE),
                                                         QLatin1String(CONFIG_FRAMEWORKPATHS));
562
            QStringList grpFrameworkPaths;
Tobias Hunger's avatar
Tobias Hunger committed
563
564
565
566
567
            foreach (const QString &p, list) {
                const QString cp = Utils::FileName::fromUserInput(p).toString();
                grpFrameworkPaths.append(cp);
            }

568
569
            const QString pch = props.getModuleProperty(QLatin1String(CONFIG_CPP_MODULE),
                    QLatin1String(CONFIG_PRECOMPILEDHEADER)).toString();
Tobias Hunger's avatar
Tobias Hunger committed
570

571
            CppTools::ProjectPart::Ptr part(new CppTools::ProjectPart);
572
573
            part->evaluateToolchain(ProjectExplorer::ToolChainKitInformation::toolChain(k),
                                    cxxFlags,
574
                                    cFlags,
575
576
                                    ProjectExplorer::SysRootKitInformation::sysRoot(k));

577
            CppTools::ProjectFileAdder adder(part->files);
578
579
580
            foreach (const QString &file, grp.allFilePaths())
                if (adder.maybeAdd(file))
                    allFiles.append(file);
581
582
            part->files << CppTools::ProjectFile(QLatin1String(CONFIGURATION_PATH),
                                                  CppTools::ProjectFile::CXXHeader);
583
584

            part->qtVersion = qtVersionForPart;
585
586
            part->includePaths += grpIncludePaths;
            part->frameworkPaths += grpFrameworkPaths;
587
            part->precompiledHeaders = QStringList(pch);
588
            part->defines += grpDefines;
589
            pinfo.appendProjectPart(part);
Tobias Hunger's avatar
Tobias Hunger committed
590
591
592
        }
    }

593
594
    setProjectLanguage(ProjectExplorer::Constants::LANG_CXX, !allFiles.isEmpty());

Tobias Hunger's avatar
Tobias Hunger committed
595
596
597
598
599
    if (pinfo.projectParts().isEmpty())
        return;

    // Register update the code model:
    modelmanager->updateProjectInfo(pinfo);
600
601
    m_codeModelFuture = modelmanager->updateSourceFiles(allFiles,
        CppTools::CppModelManagerInterface::ForcedProgressNotification);
Tobias Hunger's avatar
Tobias Hunger committed
602
603
}

604
void QbsProject::updateQmlJsCodeModel(const qbs::ProjectData &prj)
Tobias Hunger's avatar
Tobias Hunger committed
605
606
{
    Q_UNUSED(prj);
607
608
609
610
    QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
    if (!modelManager)
        return;

611
612
    QmlJS::ModelManagerInterface::ProjectInfo projectInfo =
            QmlJSTools::defaultProjectInfoForProject(this);
613
614

    setProjectLanguage(ProjectExplorer::Constants::LANG_QMLJS, !projectInfo.sourceFiles.isEmpty());
Tobias Hunger's avatar
Tobias Hunger committed
615
616
617
    modelManager->updateProjectInfo(projectInfo);
}

618
619
620
621
622
QString QbsProject::qbsBuildDir() const
{
    QString buildDir = Utils::Environment::systemEnvironment()
            .value(QLatin1String("QBS_BUILD_DIR"));
    if (buildDir.isEmpty())
623
        buildDir = Core::ICore::resourcePath() + QLatin1String("/qbs");
624
625
626
    return buildDir;
}

Tobias Hunger's avatar
Tobias Hunger committed
627
628
} // namespace Internal
} // namespace QbsProjectManager