1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
4 ** Contact: http://www.qt.io/licensing
5 **
6 ** This file is part of Qbs.
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 and
13 ** conditions see http://www.qt.io/terms-conditions. For further information
14 ** use the contact form at http://www.qt.io/contact-us.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 or version 3 as published by the Free
19 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
20 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
21 ** following information to ensure the GNU Lesser General Public License
22 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
23 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, The Qt Company gives you certain additional
26 ** rights. These rights are described in The Qt Company LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ****************************************************************************/
30
31 #include "msp430assemblersettingsgroup_v7.h"
32
33 #include "../../iarewutils.h"
34
35 namespace qbs {
36 namespace iarew {
37 namespace msp430 {
38 namespace v7 {
39
40 constexpr int kAssemblerArchiveVersion = 5;
41 constexpr int kAssemblerDataVersion = 14;
42
43 namespace {
44
45 // Language page options.
46
47 struct LanguagePageOptions final
48 {
49 enum MacroQuoteCharacter {
50 AngleBracketsQuote,
51 RoundBracketsQuote,
52 SquareBracketsQuote,
53 FigureBracketsQuote
54 };
55
LanguagePageOptionsqbs::iarew::msp430::v7::__anon3dc777700111::LanguagePageOptions56 explicit LanguagePageOptions(const ProductData &qbsProduct)
57 {
58 const auto &qbsProps = qbsProduct.moduleProperties();
59 const QStringList flags = gen::utils::cppStringModuleProperties(
60 qbsProps, {QStringLiteral("assemblerFlags")});
61 enableSymbolsCaseSensitive = flags.contains(
62 QLatin1String("-s+"));
63 enableMultibyteSupport = flags.contains(
64 QLatin1String("-n"));
65
66 if (flags.contains(QLatin1String("-M<>")))
67 macroQuoteCharacter = LanguagePageOptions::AngleBracketsQuote;
68 else if (flags.contains(QLatin1String("-M()")))
69 macroQuoteCharacter = LanguagePageOptions::RoundBracketsQuote;
70 else if (flags.contains(QLatin1String("-M[]")))
71 macroQuoteCharacter = LanguagePageOptions::SquareBracketsQuote;
72 else if (flags.contains(QLatin1String("-M{}")))
73 macroQuoteCharacter = LanguagePageOptions::FigureBracketsQuote;
74 }
75
76 int enableSymbolsCaseSensitive = 1;
77 int enableMultibyteSupport = 0;
78
79 MacroQuoteCharacter macroQuoteCharacter = AngleBracketsQuote;
80 };
81
82 // Output page options.
83
84 struct OutputPageOptions final
85 {
OutputPageOptionsqbs::iarew::msp430::v7::__anon3dc777700111::OutputPageOptions86 explicit OutputPageOptions(const ProductData &qbsProduct)
87 {
88 debugInfo = gen::utils::debugInformation(qbsProduct);
89 }
90
91 int debugInfo = 0;
92 };
93
94 // Preprocessor page options.
95
96 struct PreprocessorPageOptions final
97 {
PreprocessorPageOptionsqbs::iarew::msp430::v7::__anon3dc777700111::PreprocessorPageOptions98 explicit PreprocessorPageOptions(const QString &baseDirectory,
99 const ProductData &qbsProduct)
100 {
101 const auto &qbsProps = qbsProduct.moduleProperties();
102 defineSymbols = gen::utils::cppVariantModuleProperties(
103 qbsProps, {QStringLiteral("defines")});
104
105 const QString toolkitPath = IarewUtils::toolkitRootPath(qbsProduct);
106 const QStringList fullIncludePaths = gen::utils::cppStringModuleProperties(
107 qbsProps, {QStringLiteral("includePaths"),
108 QStringLiteral("systemIncludePaths")});
109 for (const auto &fullIncludePath : fullIncludePaths) {
110 const QFileInfo includeFileInfo(fullIncludePath);
111 const QString includeFilePath = includeFileInfo.absoluteFilePath();
112 if (includeFilePath.startsWith(toolkitPath, Qt::CaseInsensitive)) {
113 const QString path = IarewUtils::toolkitRelativeFilePath(
114 toolkitPath, includeFilePath);
115 includePaths.push_back(path);
116 } else {
117 const QString path = IarewUtils::projectRelativeFilePath(
118 baseDirectory, includeFilePath);
119 includePaths.push_back(path);
120 }
121 }
122 }
123
124 QVariantList defineSymbols;
125 QVariantList includePaths;
126 };
127
128 // Diagnostics page options.
129
130 struct DiagnosticsPageOptions final
131 {
DiagnosticsPageOptionsqbs::iarew::msp430::v7::__anon3dc777700111::DiagnosticsPageOptions132 explicit DiagnosticsPageOptions(const ProductData &qbsProduct)
133 {
134 const auto &qbsProps = qbsProduct.moduleProperties();
135 const QString warningLevel = gen::utils::cppStringModuleProperty(
136 qbsProps, QStringLiteral("warningLevel"));
137 if (warningLevel == QLatin1String("all")) {
138 enableWarnings = 0;
139 enableAllWarnings = 0;
140 } else if (warningLevel == QLatin1String("none")) {
141 enableWarnings = 1;
142 enableAllWarnings = 0;
143 } else {
144 enableWarnings = 0;
145 enableAllWarnings = 1;
146 }
147 }
148
149 int enableWarnings = 0;
150 int enableAllWarnings = 0;
151 };
152
153 } // namespace
154
155 //Msp430AssemblerSettingsGroup
156
Msp430AssemblerSettingsGroup(const Project & qbsProject,const ProductData & qbsProduct,const std::vector<ProductData> & qbsProductDeps)157 Msp430AssemblerSettingsGroup::Msp430AssemblerSettingsGroup(
158 const Project &qbsProject,
159 const ProductData &qbsProduct,
160 const std::vector<ProductData> &qbsProductDeps)
161 {
162 Q_UNUSED(qbsProductDeps)
163
164 setName(QByteArrayLiteral("A430"));
165 setArchiveVersion(kAssemblerArchiveVersion);
166 setDataVersion(kAssemblerDataVersion);
167 setDataDebugInfo(gen::utils::debugInformation(qbsProduct));
168
169 const QString buildRootDirectory = gen::utils::buildRootPath(qbsProject);
170
171 buildLanguagePage(qbsProduct);
172 buildOutputPage(qbsProduct);
173 buildPreprocessorPage(buildRootDirectory, qbsProduct);
174 buildDiagnosticsPage(qbsProduct);
175 }
176
buildLanguagePage(const ProductData & qbsProduct)177 void Msp430AssemblerSettingsGroup::buildLanguagePage(
178 const ProductData &qbsProduct)
179 {
180 const LanguagePageOptions opts(qbsProduct);
181 // Add 'ACaseSensitivity' item (User symbols are case sensitive).
182 addOptionsGroup(QByteArrayLiteral("ACaseSensitivity"),
183 {opts.enableSymbolsCaseSensitive});
184 // Add 'AMultibyteSupport' item (Enable multibyte support).
185 addOptionsGroup(QByteArrayLiteral("AMultibyteSupport"),
186 {opts.enableMultibyteSupport});
187 // Add 'MacroChars' item (Macro quote characters: ()/[]/{}/<>).
188 addOptionsGroup(QByteArrayLiteral("MacroChars"),
189 {opts.macroQuoteCharacter});
190 }
191
buildOutputPage(const ProductData & qbsProduct)192 void Msp430AssemblerSettingsGroup::buildOutputPage(
193 const ProductData &qbsProduct)
194 {
195 const OutputPageOptions opts(qbsProduct);
196 // Add 'ADebug' item (Generate debug information).
197 addOptionsGroup(QByteArrayLiteral("ADebug"),
198 {opts.debugInfo});
199 }
200
buildPreprocessorPage(const QString & baseDirectory,const ProductData & qbsProduct)201 void Msp430AssemblerSettingsGroup::buildPreprocessorPage(
202 const QString &baseDirectory,
203 const ProductData &qbsProduct)
204 {
205 const PreprocessorPageOptions opts(baseDirectory, qbsProduct);
206 // Add 'ADefines' item (Defined symbols).
207 addOptionsGroup(QByteArrayLiteral("ADefines"),
208 opts.defineSymbols);
209 // Add 'AUserIncludes' item (Additional include directories).
210 addOptionsGroup(QByteArrayLiteral("AUserIncludes"),
211 opts.includePaths);
212 }
213
buildDiagnosticsPage(const ProductData & qbsProduct)214 void Msp430AssemblerSettingsGroup::buildDiagnosticsPage(
215 const ProductData &qbsProduct)
216 {
217 const DiagnosticsPageOptions opts(qbsProduct);
218 // Add 'AWarnEnable' item (Enable/disable warnings).
219 addOptionsGroup(QByteArrayLiteral("AWarnEnable"),
220 {opts.enableWarnings});
221 // Add 'AWarnWhat' item (Enable/disable all warnings).
222 addOptionsGroup(QByteArrayLiteral("AWarnWhat"),
223 {opts.enableAllWarnings});
224 }
225
226 } // namespace v7
227 } // namespace msp430
228 } // namespace iarew
229 } // namespace qbs
230