diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-04-13 19:09:22 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-04-13 19:09:22 +0300 |
commit | 5d65c4b6789f159a6d83aa93696dac5030cae81e (patch) | |
tree | c842c5c70d9b5737553c56d62d8e97e1670b7ca3 /test cases | |
parent | 48e678db76948cc4b02369b64bc072810535f12f (diff) | |
parent | e72523ae410d780c3a703f0e3296105408fcc122 (diff) | |
download | meson-5d65c4b6789f159a6d83aa93696dac5030cae81e.zip meson-5d65c4b6789f159a6d83aa93696dac5030cae81e.tar.gz meson-5d65c4b6789f159a6d83aa93696dac5030cae81e.tar.bz2 |
Merge pull request #490 from centricular/has_function_link
Use the linker to check if a specific function is provided by the toolchain or runtime
Diffstat (limited to 'test cases')
-rw-r--r-- | test cases/common/111 has header symbol/meson.build | 18 | ||||
-rw-r--r-- | test cases/common/43 has function/meson.build | 24 |
2 files changed, 42 insertions, 0 deletions
diff --git a/test cases/common/111 has header symbol/meson.build b/test cases/common/111 has header symbol/meson.build new file mode 100644 index 0000000..e0afb42 --- /dev/null +++ b/test cases/common/111 has header symbol/meson.build @@ -0,0 +1,18 @@ +project('has header symbol', 'c') + +cc = meson.get_compiler('c') + +assert (cc.has_header_symbol('stdio.h', 'int'), 'base types should always be available') +assert (cc.has_header_symbol('stdio.h', 'printf'), 'printf function not found') +assert (cc.has_header_symbol('stdio.h', 'FILE'), 'FILE structure not found') +assert (cc.has_header_symbol('limits.h', 'INT_MAX'), 'INT_MAX define not found') +assert (not cc.has_header_symbol('limits.h', 'guint64'), 'guint64 is not defined in limits.h') +assert (not cc.has_header_symbol('stdlib.h', 'FILE'), 'FILE structure is defined in stdio.h, not stdlib.h') +assert (not cc.has_header_symbol('stdlol.h', 'printf'), 'stdlol.h shouldn\'t exist') +assert (not cc.has_header_symbol('stdlol.h', 'int'), 'shouldn\'t be able to find "int" with invalid header') + +# This is likely only available on Glibc, so just test for it +if cc.has_function('ppoll') + assert (not cc.has_header_symbol('poll.h', 'ppoll'), 'ppoll should not be accessible without _GNU_SOURCE') + assert (cc.has_header_symbol('poll.h', 'ppoll', prefix : '#define _GNU_SOURCE'), 'ppoll should be accessible with _GNU_SOURCE') +endif diff --git a/test cases/common/43 has function/meson.build b/test cases/common/43 has function/meson.build index 8fccaef..3736a3d 100644 --- a/test cases/common/43 has function/meson.build +++ b/test cases/common/43 has function/meson.build @@ -6,6 +6,30 @@ if not cc.has_function('printf', prefix : '#include<stdio.h>') error('Existing function not found.') endif +# 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) +assert(cc.has_function('fprintf'), 'Existing function not found without include') + if cc.has_function('hfkerhisadf', prefix : '#include<stdio.h>') error('Found non-existant function.') endif + +# 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. +if host_machine.system() == 'linux' and cc.get_id() == 'gcc' + assert (cc.has_function('poll', prefix : '#include <poll.h>'), 'couldn\'t detect poll when defined by a header') + assert (not cc.has_function('lchmod', prefix : '''#include <sys/stat.h> + #include <unistd.h>'''), 'lchmod check should have failed') +endif + +# 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 +if cc.has_header_symbol('sys/socket.h', 'recvmmsg', prefix : '#define _GNU_SOURCE') + # We assume that if recvmmsg exists sendmmsg does too + assert (cc.has_function('sendmmsg'), 'Failed to detect existing function') +endif |