1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25
26 #pragma once
27
28 #include "projectexplorer_export.h"
29
30 #include <utils/osspecificaspects.h>
31
32 #include <QList>
33 #include <QHash>
34
35 #include <vector>
36
37 namespace Utils { class FilePath; }
38
39 namespace ProjectExplorer {
40
41 // --------------------------------------------------------------------------
42 // ABI (documentation inside)
43 // --------------------------------------------------------------------------
44
45 class Abi;
46 using Abis = QVector<Abi>;
47
48 class PROJECTEXPLORER_EXPORT Abi
49 {
50 public:
51 enum Architecture {
52 ArmArchitecture,
53 X86Architecture,
54 ItaniumArchitecture,
55 MipsArchitecture,
56 PowerPCArchitecture,
57 ShArchitecture,
58 AvrArchitecture,
59 Avr32Architecture,
60 XtensaArchitecture,
61 Mcs51Architecture,
62 Mcs251Architecture,
63 AsmJsArchitecture,
64 Stm8Architecture,
65 Msp430Architecture,
66 Rl78Architecture,
67 C166Architecture,
68 V850Architecture,
69 Rh850Architecture,
70 RxArchitecture,
71 K78Architecture,
72 M68KArchitecture,
73 M32CArchitecture,
74 M16CArchitecture,
75 M32RArchitecture,
76 R32CArchitecture,
77 CR16Architecture,
78 RiscVArchitecture,
79 UnknownArchitecture
80 };
81
82 enum OS {
83 BsdOS,
84 LinuxOS,
85 DarwinOS,
86 UnixOS,
87 WindowsOS,
88 VxWorks,
89 QnxOS,
90 BareMetalOS,
91 UnknownOS
92 };
93
94 enum OSFlavor {
95 // BSDs
96 FreeBsdFlavor,
97 NetBsdFlavor,
98 OpenBsdFlavor,
99
100 // Linux
101 AndroidLinuxFlavor,
102
103 // Unix
104 SolarisUnixFlavor,
105
106 // Windows
107 WindowsMsvc2005Flavor,
108 WindowsMsvc2008Flavor,
109 WindowsMsvc2010Flavor,
110 WindowsMsvc2012Flavor,
111 WindowsMsvc2013Flavor,
112 WindowsMsvc2015Flavor,
113 WindowsMsvc2017Flavor,
114 WindowsMsvc2019Flavor,
115 WindowsLastMsvcFlavor = WindowsMsvc2019Flavor,
116 WindowsMSysFlavor,
117 WindowsCEFlavor,
118
119 // Embedded
120 VxWorksFlavor,
121
122 // Generic:
123 RtosFlavor,
124 GenericFlavor,
125
126 UnknownFlavor // keep last in this enum!
127 };
128
129 enum BinaryFormat {
130 ElfFormat,
131 MachOFormat,
132 PEFormat,
133 RuntimeQmlFormat,
134 UbrofFormat,
135 OmfFormat,
136 EmscriptenFormat,
137 UnknownFormat
138 };
139
140 Abi(const Architecture &a = UnknownArchitecture, const OS &o = UnknownOS,
141 const OSFlavor &so = UnknownFlavor, const BinaryFormat &f = UnknownFormat,
142 unsigned char w = 0, const QString &p = {});
143
144 static Abi abiFromTargetTriplet(const QString &machineTriple);
145
146 static Utils::OsType abiOsToOsType(const OS os);
147
148 bool operator != (const Abi &other) const;
149 bool operator == (const Abi &other) const;
150 bool isCompatibleWith(const Abi &other) const;
151
152 bool isValid() const;
153 bool isNull() const;
154
architecture()155 Architecture architecture() const { return m_architecture; }
os()156 OS os() const { return m_os; }
osFlavor()157 OSFlavor osFlavor() const { return m_osFlavor; }
binaryFormat()158 BinaryFormat binaryFormat() const { return m_binaryFormat; }
wordWidth()159 unsigned char wordWidth() const { return m_wordWidth; }
160
161 QString toString() const;
162 QString param() const;
163
164 static QString toString(const Architecture &a);
165 static QString toString(const OS &o);
166 static QString toString(const OSFlavor &of);
167 static QString toString(const BinaryFormat &bf);
168 static QString toString(int w);
169
170 static Architecture architectureFromString(const QString &a);
171 static OS osFromString(const QString &o);
172 static OSFlavor osFlavorFromString(const QString &of, const OS os);
173 static BinaryFormat binaryFormatFromString(const QString &bf);
174 static unsigned char wordWidthFromString(const QString &w);
175
176 static OSFlavor registerOsFlavor(const std::vector<OS> &oses, const QString &flavorName);
177 static QList<OSFlavor> flavorsForOs(const OS &o);
178 static QList<OSFlavor> allOsFlavors();
179 static bool osSupportsFlavor(const OS &os, const OSFlavor &flavor);
180 static OSFlavor flavorForMsvcVersion(int version);
181
182 static Abi fromString(const QString &abiString);
183 static Abi hostAbi();
184 static Abis abisOfBinary(const Utils::FilePath &path);
185
186
187 private:
188 Architecture m_architecture;
189 OS m_os;
190 OSFlavor m_osFlavor;
191 BinaryFormat m_binaryFormat;
192 unsigned char m_wordWidth;
193 QString m_param;
194 };
195
qHash(const ProjectExplorer::Abi & abi)196 inline auto qHash(const ProjectExplorer::Abi &abi)
197 {
198 int h = abi.architecture()
199 + (abi.os() << 3)
200 + (abi.osFlavor() << 6)
201 + (abi.binaryFormat() << 10)
202 + (abi.wordWidth() << 13);
203 return QT_PREPEND_NAMESPACE(qHash)(h);
204 }
205
206 } // namespace ProjectExplorer
207