qmakekitinformation.cpp 5.65 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Tobias Hunger's avatar
Tobias Hunger committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
Tobias Hunger's avatar
Tobias Hunger committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Tobias Hunger's avatar
Tobias Hunger committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** 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.
Tobias Hunger's avatar
Tobias Hunger committed
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** 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
Tobias Hunger's avatar
Tobias Hunger committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
Tobias Hunger's avatar
Tobias Hunger committed
29

Tobias Hunger's avatar
Tobias Hunger committed
30
#include "qmakekitinformation.h"
Tobias Hunger's avatar
Tobias Hunger committed
31

Tobias Hunger's avatar
Tobias Hunger committed
32
#include "qmakekitconfigwidget.h"
Tobias Hunger's avatar
Tobias Hunger committed
33
34

#include <projectexplorer/projectexplorerconstants.h>
35
#include <projectexplorer/toolchain.h>
36
#include <projectexplorer/toolchainmanager.h>
Tobias Hunger's avatar
Tobias Hunger committed
37

Tobias Hunger's avatar
Tobias Hunger committed
38
#include <qtsupport/qtkitinformation.h>
Tobias Hunger's avatar
Tobias Hunger committed
39
40
41
42
43
44

namespace Qt4ProjectManager {
namespace Internal {
const char MKSPEC_INFORMATION[] = "QtPM4.mkSpecInformation";
} // namespace Internal

Tobias Hunger's avatar
Tobias Hunger committed
45
QmakeKitInformation::QmakeKitInformation()
Tobias Hunger's avatar
Tobias Hunger committed
46
{
Tobias Hunger's avatar
Tobias Hunger committed
47
    setObjectName(QLatin1String("QmakeKitInformation"));
Tobias Hunger's avatar
Tobias Hunger committed
48
49
}

Tobias Hunger's avatar
Tobias Hunger committed
50
Core::Id QmakeKitInformation::dataId() const
Tobias Hunger's avatar
Tobias Hunger committed
51
52
53
54
55
{
    static Core::Id id = Core::Id(Internal::MKSPEC_INFORMATION);
    return id;
}

Tobias Hunger's avatar
Tobias Hunger committed
56
unsigned int QmakeKitInformation::priority() const
Tobias Hunger's avatar
Tobias Hunger committed
57
58
59
60
{
    return 24000;
}

Tobias Hunger's avatar
Tobias Hunger committed
61
QVariant QmakeKitInformation::defaultValue(ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
62
{
Tobias Hunger's avatar
Tobias Hunger committed
63
    Q_UNUSED(k);
64
    return QString();
Tobias Hunger's avatar
Tobias Hunger committed
65
66
}

67
QList<ProjectExplorer::Task> QmakeKitInformation::validate(const ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
68
69
{
    QList<ProjectExplorer::Task> result;
Tobias Hunger's avatar
Tobias Hunger committed
70
    QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(k);
Tobias Hunger's avatar
Tobias Hunger committed
71

Tobias Hunger's avatar
Tobias Hunger committed
72
    Utils::FileName mkspec = QmakeKitInformation::mkspec(k);
Tobias Hunger's avatar
Tobias Hunger committed
73
74
75
76
77
78
79
80
81
82
83
84
85
    if (!version && !mkspec.isEmpty())
        result << ProjectExplorer::Task(ProjectExplorer::Task::Warning,
                                        tr("No Qt version set, so mkspec is ignored."),
                                        Utils::FileName(), -1,
                                        Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
    if (version && !version->hasMkspec(mkspec))
        result << ProjectExplorer::Task(ProjectExplorer::Task::Error,
                                        tr("Mkspec not found for Qt version."),
                                        Utils::FileName(), -1,
                                        Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
    return result;
}

86
void QmakeKitInformation::setup(ProjectExplorer::Kit *k)
87
88
89
90
91
92
93
94
95
96
97
98
99
{
    QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(k);
    if (!version)
        return;

    Utils::FileName spec = QmakeKitInformation::mkspec(k);
    if (spec.isEmpty())
        spec = version->mkspec();

    ProjectExplorer::ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k);

    if (!tc || !tc->suggestedMkspecList().contains(spec)) {
        QList<ProjectExplorer::ToolChain *> tcList = ProjectExplorer::ToolChainManager::instance()->toolChains();
100
        ProjectExplorer::ToolChain *possibleTc = 0;
101
        foreach (ProjectExplorer::ToolChain *current, tcList) {
102
103
104
105
            if (version->qtAbis().contains(current->targetAbi())) {
                possibleTc = current;
                if (current->suggestedMkspecList().contains(spec))
                    break;
106
107
            }
        }
108
        ProjectExplorer::ToolChainKitInformation::setToolChain(k, possibleTc);
109
110
111
    }
}

Tobias Hunger's avatar
Tobias Hunger committed
112
113
ProjectExplorer::KitConfigWidget *
QmakeKitInformation::createConfigWidget(ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
114
{
Tobias Hunger's avatar
Tobias Hunger committed
115
    return new Internal::QmakeKitConfigWidget(k);
Tobias Hunger's avatar
Tobias Hunger committed
116
117
}

118
ProjectExplorer::KitInformation::ItemList QmakeKitInformation::toUserOutput(const ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
119
{
Tobias Hunger's avatar
Tobias Hunger committed
120
    return ItemList() << qMakePair(tr("mkspec"), mkspec(k).toUserOutput());
Tobias Hunger's avatar
Tobias Hunger committed
121
122
}

Tobias Hunger's avatar
Tobias Hunger committed
123
Utils::FileName QmakeKitInformation::mkspec(const ProjectExplorer::Kit *k)
Tobias Hunger's avatar
Tobias Hunger committed
124
{
Tobias Hunger's avatar
Tobias Hunger committed
125
    if (!k)
Tobias Hunger's avatar
Tobias Hunger committed
126
        return Utils::FileName();
Tobias Hunger's avatar
Tobias Hunger committed
127
    return Utils::FileName::fromString(k->value(Core::Id(Internal::MKSPEC_INFORMATION)).toString());
Tobias Hunger's avatar
Tobias Hunger committed
128
129
}

Tobias Hunger's avatar
Tobias Hunger committed
130
Utils::FileName QmakeKitInformation::effectiveMkspec(const ProjectExplorer::Kit *k)
131
{
Tobias Hunger's avatar
Tobias Hunger committed
132
    if (!k)
133
        return Utils::FileName();
Tobias Hunger's avatar
Tobias Hunger committed
134
    Utils::FileName spec = mkspec(k);
135
    if (spec.isEmpty())
Tobias Hunger's avatar
Tobias Hunger committed
136
        return defaultMkspec(k);
137
138
139
    return spec;
}

Tobias Hunger's avatar
Tobias Hunger committed
140
void QmakeKitInformation::setMkspec(ProjectExplorer::Kit *k, const Utils::FileName &fn)
Tobias Hunger's avatar
Tobias Hunger committed
141
{
Tobias Hunger's avatar
Tobias Hunger committed
142
143
    if (fn == defaultMkspec(k))
        k->setValue(Core::Id(Internal::MKSPEC_INFORMATION), QString());
144
    else
Tobias Hunger's avatar
Tobias Hunger committed
145
        k->setValue(Core::Id(Internal::MKSPEC_INFORMATION), fn.toString());
146
147
}

Tobias Hunger's avatar
Tobias Hunger committed
148
Utils::FileName QmakeKitInformation::defaultMkspec(const ProjectExplorer::Kit *k)
149
{
Tobias Hunger's avatar
Tobias Hunger committed
150
    QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(k);
151
152
153
    if (!version) // No version, so no qmake
        return Utils::FileName();

Tobias Hunger's avatar
Tobias Hunger committed
154
    return version->mkspecFor(ProjectExplorer::ToolChainKitInformation::toolChain(k));
Tobias Hunger's avatar
Tobias Hunger committed
155
156
157
}

} // namespace Qt4ProjectManager