summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/projectpartbuilder.cpp
blob: a2efe98b1339821d08b1aa4f5bc440bbe560139d (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/

#include "projectpartbuilder.h"

#include "projectinfo.h"

#include <projectexplorer/abi.h>
#include <projectexplorer/headerpath.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>

namespace CppTools {

class ToolChainImpl : public ToolChainInterface
{
public:
    ToolChainImpl(ProjectExplorer::ToolChain &toolChain,
                  const ProjectExplorer::Kit *kit,
                  const QStringList &commandLineFlags)
        : m_toolChain(toolChain)
        , m_kit(kit)
        , m_commandLineFlags(commandLineFlags)
    {
    }

    Core::Id type() const override
    {
        return m_toolChain.typeId();
    }

    bool isMsvc2015Toolchain() const override
    {
        return m_toolChain.targetAbi().osFlavor() == ProjectExplorer::Abi::WindowsMsvc2015Flavor;
    }

    unsigned wordWidth() const override
    {
        return m_toolChain.targetAbi().wordWidth();
    }

    QString targetTriple() const override
    {
        if (type() == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
            return QLatin1String("i686-pc-windows-msvc");

        return m_toolChain.originalTargetTriple();
    }

    QByteArray predefinedMacros() const override
    {
        return m_toolChain.predefinedMacros(m_commandLineFlags);
    }

    QList<ProjectExplorer::HeaderPath> systemHeaderPaths() const override
    {
        return m_toolChain.systemHeaderPaths(
                    m_commandLineFlags,
                    ProjectExplorer::SysRootKitInformation::sysRoot(m_kit));
    }

    ProjectExplorer::WarningFlags warningFlags() const override
    {
        return m_toolChain.warningFlags(m_commandLineFlags);
    }

    ProjectExplorer::ToolChain::CompilerFlags compilerFlags() const override
    {
        return m_toolChain.compilerFlags(m_commandLineFlags);
    }

private:
    ProjectExplorer::ToolChain &m_toolChain;
    const ProjectExplorer::Kit *m_kit = nullptr;
    const QStringList m_commandLineFlags;
};

class ProjectImpl : public ProjectInterface
{
public:
    ProjectImpl(ProjectExplorer::Project &project)
        : m_project(project)
    {
        if (ProjectExplorer::Target *activeTarget = m_project.activeTarget())
            m_kit = activeTarget->kit();
    }

    QString displayName() const override
    {
        return m_project.displayName();
    }

    QString projectFilePath() const override
    {
        return m_project.projectFilePath().toString();
    }

    ToolChainInterfacePtr toolChain(Core::Id language,
                                    const QStringList &commandLineFlags) const override
    {
        using namespace ProjectExplorer;

        if (ProjectExplorer::ToolChain *t = ToolChainKitInformation::toolChain(m_kit, language))
            return ToolChainInterfacePtr(new ToolChainImpl(*t, m_kit, commandLineFlags));

        return ToolChainInterfacePtr();
    }

private:
    ProjectExplorer::Project &m_project;
    ProjectExplorer::Kit *m_kit = nullptr;
};

ProjectPartBuilder::ProjectPartBuilder(ProjectInfo &projectInfo)
    : BaseProjectPartBuilder(new ProjectImpl(*projectInfo.project().data()), projectInfo)
{
}

} // namespace CppTools