The Meson Build System
http://mesonbuild.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
4.0 KiB
92 lines
4.0 KiB
8 years ago
|
project('has function', 'c', 'cpp')
|
||
11 years ago
|
|
||
8 years ago
|
host_system = host_machine.system()
|
||
|
|
||
8 years ago
|
# This is used in the `test_compiler_check_flags_order` unit test
|
||
|
unit_test_args = '-I/tmp'
|
||
8 years ago
|
defines_has_builtin = '''#ifndef __has_builtin
|
||
|
#error "no __has_builtin"
|
||
|
#endif
|
||
|
'''
|
||
8 years ago
|
compilers = [meson.get_compiler('c'), meson.get_compiler('cpp')]
|
||
11 years ago
|
|
||
8 years ago
|
foreach cc : compilers
|
||
8 years ago
|
if not cc.has_function('printf', prefix : '#include<stdio.h>',
|
||
|
args : unit_test_args)
|
||
8 years ago
|
error('"printf" function not found (should always exist).')
|
||
|
endif
|
||
11 years ago
|
|
||
8 years ago
|
# Should also be able to detect it without specifying the header
|
||
|
# We check for a different function here to make sure the result is
|
||
|
# not taken from a cache (ie. the check above)
|
||
|
# On MSVC fprintf is defined as an inline function in the header, so it cannot
|
||
|
# be found without the include.
|
||
6 years ago
|
if not ['msvc', 'intel-cl'].contains(cc.get_id())
|
||
8 years ago
|
assert(cc.has_function('fprintf', args : unit_test_args),
|
||
|
'"fprintf" function not found without include (on !msvc).')
|
||
8 years ago
|
else
|
||
8 years ago
|
assert(cc.has_function('fprintf', prefix : '#include <stdio.h>',
|
||
|
args : unit_test_args),
|
||
|
'"fprintf" function not found with include (on msvc).')
|
||
8 years ago
|
# Compiler intrinsics
|
||
|
assert(cc.has_function('strcmp'),
|
||
|
'strcmp intrinsic should have been found on MSVC')
|
||
|
assert(cc.has_function('strcmp', prefix : '#include <string.h>'),
|
||
|
'strcmp intrinsic should have been found with #include on MSVC')
|
||
8 years ago
|
endif
|
||
9 years ago
|
|
||
8 years ago
|
if cc.has_function('hfkerhisadf', prefix : '#include<stdio.h>',
|
||
|
args : unit_test_args)
|
||
8 years ago
|
error('Found non-existent function "hfkerhisadf".')
|
||
|
endif
|
||
9 years ago
|
|
||
8 years ago
|
if cc.has_function('hfkerhisadf', args : unit_test_args)
|
||
|
error('Found non-existent function "hfkerhisadf".')
|
||
|
endif
|
||
|
|
||
8 years ago
|
# With glibc on Linux lchmod is a stub that will always return an error,
|
||
|
# we want to detect that and declare that the function is not available.
|
||
|
# We can't check for the C library used here of course, but if it's not
|
||
|
# implemented in glibc it's probably not implemented in any other 'slimmer'
|
||
|
# C library variants either, so the check should be safe either way hopefully.
|
||
8 years ago
|
if host_system == 'linux' or host_system == 'darwin'
|
||
8 years ago
|
assert (cc.has_function('poll', prefix : '#include <poll.h>',
|
||
|
args : unit_test_args),
|
||
|
'couldn\'t detect "poll" when defined by a header')
|
||
|
lchmod_prefix = '#include <sys/stat.h>\n#include <unistd.h>'
|
||
8 years ago
|
if host_system == 'linux'
|
||
|
assert (not cc.has_function('lchmod', prefix : lchmod_prefix,
|
||
|
args : unit_test_args),
|
||
|
'"lchmod" check should have failed')
|
||
|
else
|
||
|
# macOS and *BSD have lchmod
|
||
|
assert (cc.has_function('lchmod', prefix : lchmod_prefix,
|
||
|
args : unit_test_args),
|
||
|
'"lchmod" check should have succeeded')
|
||
|
endif
|
||
8 years ago
|
# Check that built-ins are found properly both with and without headers
|
||
|
assert(cc.has_function('alloca', args : unit_test_args),
|
||
8 years ago
|
'built-in alloca must be found on ' + host_system)
|
||
8 years ago
|
assert(cc.has_function('alloca', prefix : '#include <alloca.h>',
|
||
|
args : unit_test_args),
|
||
8 years ago
|
'built-in alloca must be found with #include')
|
||
|
if not cc.compiles(defines_has_builtin, args : unit_test_args)
|
||
|
assert(not cc.has_function('alloca',
|
||
|
prefix : '#include <alloca.h>\n#undef alloca',
|
||
|
args : unit_test_args),
|
||
|
'built-in alloca must not be found with #include and #undef')
|
||
|
endif
|
||
8 years ago
|
endif
|
||
9 years ago
|
|
||
8 years ago
|
# For some functions one needs to define _GNU_SOURCE before including the
|
||
|
# right headers to get them picked up. Make sure we can detect these functions
|
||
|
# as well without any prefix
|
||
8 years ago
|
if cc.has_header_symbol('sys/socket.h', 'recvmmsg',
|
||
|
prefix : '#define _GNU_SOURCE',
|
||
|
args : unit_test_args)
|
||
8 years ago
|
# We assume that if recvmmsg exists sendmmsg does too
|
||
8 years ago
|
assert (cc.has_function('sendmmsg', args : unit_test_args),
|
||
|
'Failed to detect function "sendmmsg" (should always exist).')
|
||
8 years ago
|
endif
|
||
|
endforeach
|