| 1 |
project('required keyword in has functions', 'c') |
| 2 |
|
| 3 |
cc = meson.get_compiler('c') |
| 4 |
opt = get_option('opt') |
| 5 |
|
| 6 |
cc.has_function('printf', prefix : '#include<stdio.h>', required : true) |
| 7 |
cc.has_type('time_t', prefix : '#include<time.h>', required : true) |
| 8 |
cc.has_member('struct tm', 'tm_sec', prefix : '#include<time.h>', required : true) |
| 9 |
cc.has_members('struct tm', ['tm_sec', 'tm_min'], prefix : '#include<time.h>', required : true) |
| 10 |
cc.has_header('time.h', required : true) |
| 11 |
cc.has_header_symbol('time.h', 'time', required : true) |
| 12 |
|
| 13 |
assert(not cc.has_function('printf', prefix : '#include<stdio.h>', required : opt)) |
| 14 |
assert(not cc.has_type('time_t', prefix : '#include<time.h>', required : opt)) |
| 15 |
assert(not cc.has_member('struct tm', 'tm_sec', prefix : '#include<time.h>', required : opt)) |
| 16 |
assert(not cc.has_members('struct tm', ['tm_sec', 'tm_min'], prefix : '#include<time.h>', required : opt)) |
| 17 |
assert(not cc.has_header('time.h', required : opt)) |
| 18 |
assert(not cc.has_header_symbol('time.h', 'time', required : opt)) |
| 19 |
|
| 20 |
# compiler.has_argument |
| 21 |
if cc.get_id() == 'msvc' |
| 22 |
is_arg = '/O2' |
| 23 |
else |
| 24 |
is_arg = '-O2' |
| 25 |
endif |
| 26 |
cc.has_argument(is_arg, required: true) |
| 27 |
assert(not cc.has_argument(is_arg, required: opt)) |
| 28 |
|
| 29 |
# compiler.has_multi_arguments |
| 30 |
if cc.get_id() == 'gcc' |
| 31 |
pre_arg = '-Wformat' |
| 32 |
arg = '-Werror=format-security' |
| 33 |
cc.has_multi_arguments([pre_arg, arg], required: true) |
| 34 |
assert(not cc.has_multi_arguments(pre_arg, arg, required: opt)) |
| 35 |
endif |
| 36 |
|
| 37 |
# compiler.has_link_argument |
| 38 |
if cc.get_argument_syntax() == 'msvc' |
| 39 |
is_arg = '/OPT:REF' |
| 40 |
else |
| 41 |
is_arg = '-Wl,-L/tmp' |
| 42 |
endif |
| 43 |
cc.has_link_argument(is_arg, required: true) |
| 44 |
assert(not cc.has_link_argument(is_arg, required: opt)) |
| 45 |
|
| 46 |
# compiler.has_function_attribute |
| 47 |
if not ['pgi', 'msvc', 'clang-cl', 'intel-cl'].contains(cc.get_id()) |
| 48 |
a = 'aligned' |
| 49 |
cc.has_function_attribute(a, required: true) |
| 50 |
assert(not cc.has_function_attribute(a, required: opt)) |
| 51 |
endif |
| 52 |
|
| 53 |
testcase expect_error('''compiler.has_function keyword argument 'required' was of type str but should have been one of: bool, UserFeatureOption''') |
| 54 |
cc.has_function('printf', required : 'not a bool') |
| 55 |
endtestcase |
| 56 |
|
| 57 |
testcase expect_error('''C function 'asdfkawlegsdiovapfjhkr' not usable''') |
| 58 |
cc.has_function('asdfkawlegsdiovapfjhkr', required : true) |
| 59 |
endtestcase |
| 60 |
|
| 61 |
testcase expect_error('''C header 'asdfkawlegsdiovapfjhkr.h' not found''') |
| 62 |
cc.has_header('asdfkawlegsdiovapfjhkr.h', required : true) |
| 63 |
endtestcase |
| 64 |
|
| 65 |
testcase expect_error('''C symbol time_not_found not found in header time.h''') |
| 66 |
cc.has_header_symbol('time.h', 'time_not_found', required : true) |
| 67 |
endtestcase |