Skip to content

Commit 610b9f7

Browse files
committed
µVision exporter: Separate out C and C++ options
To allow manual specification of the language standard, working around the limitations of the GUI's own option, modify the template so that we have C options in the target level, and C++ files get different C++ options. This means whatever language options are specified in the profile can now be passed directly as "misc control"s, and this overrides anything the GUI adds, as it comes later in the command line.
1 parent 5538e73 commit 610b9f7

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

tools/export/uvision/__init__.py

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -183,25 +183,29 @@ def format_flags(self):
183183
flags['c_flags'] + flags['cxx_flags'] + flags['common_flags']
184184
)
185185
in_template = set(
186-
["--no_vla", "--cpp", "--cpp11", "--c99", "-MMD"] + config_option
186+
["-MMD"] + config_option
187187
)
188188

189189
def valid_flag(x):
190190
return (
191191
x not in in_template and
192192
not x.startswith("-O") and
193-
not x.startswith("-std") and
194193
not x.startswith("-D")
195194
)
196195

197196
def is_define(s):
198197
return s.startswith("-D") and "(" not in s
199198

200199
flags['c_flags'] = " ".join(
201-
f.replace('"', '\\"') for f in c_flags if valid_flag(f)
200+
f.replace('"', '\\"') for f in flags['c_flags'] if valid_flag(f)
202201
)
203-
flags['c_flags'] += " "
204-
flags['c_flags'] += " ".join(config_option)
202+
flags['cxx_flags'] = " ".join(
203+
f.replace('"', '\\"') for f in flags['cxx_flags'] if valid_flag(f)
204+
)
205+
flags['common_flags'] = " ".join(
206+
f.replace('"', '\\"') for f in flags['common_flags'] if valid_flag(f)
207+
)
208+
flags['common_flags'] += " ".join(config_option)
205209
flags['c_defines'] = " ".join(f[2:].replace('"', '\\"')
206210
for f in c_flags if is_define(f))
207211
flags['ld_flags'] = " ".join(set(flags['ld_flags']))
@@ -289,33 +293,6 @@ def generate(self):
289293
ctx['armc6'] = int(self.TOOLCHAIN is 'ARMC6')
290294
ctx['toolchain_name'] = self.TOOLCHAIN_NAME
291295

292-
std = [flag for flag in self.flags['c_flags'] if flag.startswith("-std=")]
293-
if len(std) >= 1:
294-
std = std[-1][len('-std='):]
295-
else:
296-
std = None
297-
c_std = {
298-
'c89': 1, 'gnu89': 2,
299-
'c90': 1, 'gnu90': 2,
300-
'c99': 3, 'gnu99': 4,
301-
'c11': 5, 'gnu11': 6,
302-
}
303-
ctx['v6_lang'] = c_std.get(std, 0)
304-
305-
std = [flag for flag in self.flags['cxx_flags'] if flag.startswith("-std=")]
306-
if len(std) >= 1:
307-
std = std[-1][len('-std='):]
308-
else:
309-
std = None
310-
cpp_std = {
311-
'c++98': 1, 'gnu++98': 2,
312-
'c++03': 5, 'gnu++03': 2, # UVision 5.27.1.0 does not support gnu++03 - fall back to gnu++98
313-
'c++11': 3, 'gnu++11': 4,
314-
'c++14': 6, 'gnu++14': 4, # UVision 5.27.1.0 does not support gnu++14 - should be able to get it as compiler default, but that doesn't work as documented and requests gnu++98. So fall back to gnu++11
315-
'c++17': 6, 'gnu++17': 4, # UVision 5.27.1.0 does not support c++17/gnu++17 - fall back to c++14/gnu++11
316-
}
317-
ctx['v6_lang_p'] = cpp_std.get(std, 0)
318-
319296
ctx.update(self.format_flags())
320297
self.gen_file(
321298
'uvision/uvision.tmpl', ctx, self.project_name + ".uvprojx"

tools/export/uvision/uvision.tmpl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,17 +367,17 @@
367367
<wLevel>0</wLevel>
368368
<uThumb>0</uThumb>
369369
<uSurpInc>0</uSurpInc>
370-
<uC99>1</uC99>
370+
<uC99>0</uC99>
371371
<useXO>0</useXO>
372-
<v6Lang>{{v6_lang}}</v6Lang>
373-
<v6LangP>{{v6_lang_p}}</v6LangP>
372+
<v6Lang>0</v6Lang>
373+
<v6LangP>0</v6LangP>
374374
<vShortEn>1</vShortEn>
375375
<vShortWch>1</vShortWch>
376376
<v6Lto>0</v6Lto>
377377
<v6WtE>0</v6WtE>
378378
<v6Rtti>0</v6Rtti>
379379
<VariousControls>
380-
<MiscControls>{{c_flags}}</MiscControls>
380+
<MiscControls>{{c_flags}} {{common_flags}}</MiscControls>
381381
<Define>{{c_defines}}</Define>
382382
<Undefine></Undefine>
383383
<IncludePath>{{include_paths}}</IncludePath>
@@ -430,6 +430,17 @@
430430
<FileType>{{file.type}}</FileType>
431431
<FileName>{{file.name}}</FileName>
432432
<FilePath>{{file.loc}}</FilePath>
433+
{% if file.type == 8 %}
434+
<FileOption>
435+
<FileArmAds>
436+
<Cads>
437+
<VariousControls>
438+
<MiscControls>{{cxx_flags}} {{common_flags}}</MiscControls>
439+
</VariousControls>
440+
</Cads>
441+
</FileArmAds>
442+
</FileOption>
443+
{% endif %}
433444
</File>
434445
{% endfor %}
435446
</Files>

0 commit comments

Comments
 (0)