Some compilers try very had to pretend they're another compiler (ICC pretends to be GCC and Linux and MacOS, and MSVC on windows), Clang behaves much like GCC, but now also has clang-cl, which behaves like MSVC. This method provides an easy way to determine whether testing for MSVC like arguments `/w1234` or gcc like arguments `-Wfoo` are likely to succeed, without having to check for dozens of compilers and the host operating system, (as you would otherwise have to do with ICC).pull/4449/head
parent
8cd7f7871b
commit
63f4f9481e
8 changed files with 112 additions and 25 deletions
@ -0,0 +1,22 @@ |
||||
## new compiler method `get_argument_syntax` |
||||
|
||||
The compiler object now has `get_argument_syntax` method, which returns a |
||||
string value of `gcc`, `msvc`, or an undefined value string value. This can be |
||||
used to determine if a compiler uses gcc syntax (`-Wfoo`), msvc syntax |
||||
(`/w1234`), or some other kind of arguments. |
||||
|
||||
```meson |
||||
cc = meson.get_compiler('c') |
||||
|
||||
if cc.get_argument_syntax() == 'msvc' |
||||
if cc.has_argument('/w1235') |
||||
add_project_arguments('/w1235', language : ['c']) |
||||
endif |
||||
elif cc.get_argument_syntax() == 'gcc' |
||||
if cc.has_argument('-Wfoo') |
||||
add_project_arguments('-Wfoo', language : ['c']) |
||||
endif |
||||
elif cc.get_id() == 'some other compiler' |
||||
add_project_arguments('--error-on-foo', language : ['c']) |
||||
endif |
||||
``` |
@ -0,0 +1,25 @@ |
||||
project( |
||||
'argument syntax', |
||||
['c'], |
||||
) |
||||
|
||||
cc = meson.get_compiler('c') |
||||
|
||||
if ['gcc', 'lcc', 'clang'].contains(cc.get_id()) |
||||
expected = 'gcc' |
||||
elif cc.get_id() == 'msvc' |
||||
expected = 'msvc' |
||||
elif cc.get_id() == 'intel' |
||||
if host_machine.system() == 'windows' |
||||
expected = 'msvc' |
||||
else |
||||
expected = 'gcc' |
||||
endif |
||||
else |
||||
# It's possible that other compilers end up here that shouldn't |
||||
expected = 'other' |
||||
endif |
||||
|
||||
assert(cc.get_argument_syntax() == expected, |
||||
'Wrong output for compiler @0@. expected @1@ but got @2@'.format( |
||||
cc.get_id(), expected, cc.get_argument_syntax())) |
Loading…
Reference in new issue