| 1 |
project('has arg', 'c', 'cpp') |
| 2 |
|
| 3 |
cc = meson.get_compiler('c') |
| 4 |
cpp = meson.get_compiler('cpp') |
| 5 |
|
| 6 |
if cc.get_id() == 'msvc' |
| 7 |
is_arg = '/O2' |
| 8 |
useless = '/DFOO' |
| 9 |
else |
| 10 |
is_arg = '-O2' |
| 11 |
useless = '-DFOO' |
| 12 |
endif |
| 13 |
|
| 14 |
isnt_arg = '-fiambroken' |
| 15 |
|
| 16 |
assert(cc.has_argument(is_arg), 'Arg that should have worked does not work.') |
| 17 |
assert(not cc.has_argument(isnt_arg), 'Arg that should be broken is not.') |
| 18 |
|
| 19 |
assert(cpp.has_argument(is_arg), 'Arg that should have worked does not work.') |
| 20 |
assert(not cpp.has_argument(isnt_arg), 'Arg that should be broken is not.') |
| 21 |
|
| 22 |
assert(cc.get_supported_arguments([is_arg, isnt_arg, useless]) == [is_arg, useless], 'Arg filtering returned different result.') |
| 23 |
assert(cpp.get_supported_arguments([is_arg, isnt_arg, useless]) == [is_arg, useless], 'Arg filtering returned different result.') |
| 24 |
|
| 25 |
# Have useless at the end to ensure that the search goes from front to back. |
| 26 |
l1 = cc.first_supported_argument([isnt_arg, is_arg, isnt_arg, useless]) |
| 27 |
l2 = cc.first_supported_argument(isnt_arg, isnt_arg, isnt_arg) |
| 28 |
|
| 29 |
assert(l1.length() == 1, 'First supported returned wrong result.') |
| 30 |
assert(l1.get(0) == is_arg, 'First supported returned wrong argument.') |
| 31 |
assert(l2.length() == 0, 'First supported did not return empty array.') |
| 32 |
|
| 33 |
l1 = cpp.first_supported_argument([isnt_arg, is_arg, isnt_arg, useless]) |
| 34 |
l2 = cpp.first_supported_argument(isnt_arg, isnt_arg, isnt_arg) |
| 35 |
|
| 36 |
assert(l1.length() == 1, 'First supported returned wrong result.') |
| 37 |
assert(l1.get(0) == is_arg, 'First supported returned wrong argument.') |
| 38 |
assert(l2.length() == 0, 'First supported did not return empty array.') |
| 39 |
|
| 40 |
if cc.get_id() == 'gcc' |
| 41 |
pre_arg = '-Wformat' |
| 42 |
# NOTE: We have special handling for -Wno-foo args because gcc silently |
| 43 |
# ignores unknown -Wno-foo args unless you pass -Werror, so for this test, we |
| 44 |
# pass it as two separate arguments. |
| 45 |
anti_pre_arg = ['-W', 'no-format'] |
| 46 |
arg = '-Werror=format-security' |
| 47 |
assert(not cc.has_multi_arguments([anti_pre_arg, arg]), 'Arg that should be broken is not.') |
| 48 |
assert(cc.has_multi_arguments(pre_arg), 'Arg that should have worked does not work.') |
| 49 |
assert(cc.has_multi_arguments([pre_arg, arg]), 'Arg that should have worked does not work.') |
| 50 |
# Test that gcc correctly errors out on unknown -Wno flags |
| 51 |
assert(not cc.has_argument('-Wno-lol-meson-test-flags'), 'should error out on unknown -Wno args') |
| 52 |
assert(not cc.has_multi_arguments(['-Wno-pragmas', '-Wno-lol-meson-test-flags']), 'should error out even if some -Wno args are valid') |
| 53 |
endif |
| 54 |
|
| 55 |
if cpp.get_id() == 'gcc' and cpp.version().version_compare('>=12.1.0') |
| 56 |
# Handle special -Wno-attributes=foo where -Wattributes=foo is invalid |
| 57 |
# i.e. our usual -Wno-foo -Wfoo hack doesn't work for -Wattributes=foo. |
| 58 |
assert(cpp.has_argument('-Wno-attributes=meson::i_do_not_exist')) |
| 59 |
endif |
| 60 |
|
| 61 |
if cpp.get_id() == 'gcc' |
| 62 |
# Handle negative flags whose positive counterparts require a value to be |
| 63 |
# specified. |
| 64 |
if cpp.version().version_compare('>=4.4.0') |
| 65 |
assert(cpp.has_argument('-Wno-frame-larger-than')) |
| 66 |
endif |
| 67 |
if cpp.version().version_compare('>=4.7.0') |
| 68 |
assert(cpp.has_argument('-Wno-stack-usage')) |
| 69 |
endif |
| 70 |
if cpp.version().version_compare('>=7.1.0') |
| 71 |
assert(cpp.has_argument('-Wno-alloc-size-larger-than')) |
| 72 |
assert(cpp.has_argument('-Wno-alloca-larger-than')) |
| 73 |
assert(cpp.has_argument('-Wno-vla-larger-than')) |
| 74 |
endif |
| 75 |
endif |
| 76 |
|
| 77 |
if cc.get_id() == 'clang' and cc.version().version_compare('<=4.0.0') |
| 78 |
# 4.0.0 does not support -fpeel-loops. Newer versions may. |
| 79 |
# Please adjust above version number as new versions of clang are released. |
| 80 |
notyet_arg = '-fpeel-loops' |
| 81 |
assert(not cc.has_argument(notyet_arg), 'Arg that should be broken (unless clang added support recently) is not.') |
| 82 |
endif |