Merge pull request #1006 from centricular/cpp-has-header-symbol
A bunch of fixes for compiler checks with C++pull/1017/head
commit
cf7b50364f
12 changed files with 256 additions and 167 deletions
@ -1,18 +1,32 @@ |
|||||||
project('has header symbol', 'c') |
project('has header symbol', 'c', 'cpp') |
||||||
|
|
||||||
cc = meson.get_compiler('c') |
cc = meson.get_compiler('c') |
||||||
|
cpp = meson.get_compiler('cpp') |
||||||
|
|
||||||
assert (cc.has_header_symbol('stdio.h', 'int'), 'base types should always be available') |
foreach comp : [cc, cpp] |
||||||
assert (cc.has_header_symbol('stdio.h', 'printf'), 'printf function not found') |
assert (comp.has_header_symbol('stdio.h', 'int'), 'base types should always be available') |
||||||
assert (cc.has_header_symbol('stdio.h', 'FILE'), 'FILE structure not found') |
assert (comp.has_header_symbol('stdio.h', 'printf'), 'printf function not found') |
||||||
assert (cc.has_header_symbol('limits.h', 'INT_MAX'), 'INT_MAX define not found') |
assert (comp.has_header_symbol('stdio.h', 'FILE'), 'FILE structure not found') |
||||||
assert (not cc.has_header_symbol('limits.h', 'guint64'), 'guint64 is not defined in limits.h') |
assert (comp.has_header_symbol('limits.h', 'INT_MAX'), 'INT_MAX define not found') |
||||||
assert (not cc.has_header_symbol('stdlib.h', 'FILE'), 'FILE structure is defined in stdio.h, not stdlib.h') |
assert (not comp.has_header_symbol('limits.h', 'guint64'), 'guint64 is not defined in limits.h') |
||||||
assert (not cc.has_header_symbol('stdlol.h', 'printf'), 'stdlol.h shouldn\'t exist') |
assert (not comp.has_header_symbol('stdlib.h', 'FILE'), 'FILE structure is defined in stdio.h, not stdlib.h') |
||||||
assert (not cc.has_header_symbol('stdlol.h', 'int'), 'shouldn\'t be able to find "int" with invalid header') |
assert (not comp.has_header_symbol('stdlol.h', 'printf'), 'stdlol.h shouldn\'t exist') |
||||||
|
assert (not comp.has_header_symbol('stdlol.h', 'int'), 'shouldn\'t be able to find "int" with invalid header') |
||||||
|
endforeach |
||||||
|
|
||||||
# This is likely only available on Glibc, so just test for it |
# This is likely only available on Glibc, so just test for it |
||||||
if cc.has_function('ppoll') |
if cc.has_function('ppoll') |
||||||
assert (not cc.has_header_symbol('poll.h', 'ppoll'), 'ppoll should not be accessible without _GNU_SOURCE') |
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') |
assert (cc.has_header_symbol('poll.h', 'ppoll', prefix : '#define _GNU_SOURCE'), 'ppoll should be accessible with _GNU_SOURCE') |
||||||
endif |
endif |
||||||
|
|
||||||
|
assert (cpp.has_header_symbol('iostream', 'std::iostream'), 'iostream not found in iostream.h') |
||||||
|
assert (cpp.has_header_symbol('vector', 'std::vector'), 'vector not found in vector.h') |
||||||
|
assert (not cpp.has_header_symbol('limits.h', 'std::iostream'), 'iostream should not be defined in limits.h') |
||||||
|
|
||||||
|
boost = dependency('boost', required : false) |
||||||
|
if boost.found() |
||||||
|
assert (cpp.has_header_symbol('boost/math/quaternion.hpp', 'boost::math::quaternion', dependencies : boost), 'quaternion not found') |
||||||
|
else |
||||||
|
assert (not cpp.has_header_symbol('boost/math/quaternion.hpp', 'boost::math::quaternion', dependencies : boost), 'quaternion found?!') |
||||||
|
endif |
||||||
|
@ -1,13 +1,33 @@ |
|||||||
project('sizeof', 'c') |
project('sizeof', 'c', 'cpp') |
||||||
|
|
||||||
|
# Test with C |
||||||
cc = meson.get_compiler('c') |
cc = meson.get_compiler('c') |
||||||
|
|
||||||
intsize = cc.sizeof('int') |
intsize = cc.sizeof('int') |
||||||
wcharsize = cc.sizeof('wchar_t', prefix : '#include<wchar.h>') |
wcharsize = cc.sizeof('wchar_t', prefix : '#include<wchar.h>') |
||||||
|
|
||||||
cd = configuration_data() |
cd = configuration_data() |
||||||
cd.set('INTSIZE', intsize) |
cd.set('INTSIZE', intsize) |
||||||
cd.set('WCHARSIZE', wcharsize) |
cd.set('WCHARSIZE', wcharsize) |
||||||
|
cd.set('CONFIG', 'config.h') |
||||||
configure_file(input : 'config.h.in', output : 'config.h', configuration : cd) |
configure_file(input : 'config.h.in', output : 'config.h', configuration : cd) |
||||||
|
s = configure_file(input : 'prog.c.in', output : 'prog.c', configuration : cd) |
||||||
|
|
||||||
e = executable('prog', 'prog.c') |
e = executable('prog', s) |
||||||
test('sizeof test', e) |
test('sizeof test', e) |
||||||
|
|
||||||
|
# Test with C++ |
||||||
|
cpp = meson.get_compiler('cpp') |
||||||
|
|
||||||
|
intsize = cpp.sizeof('int') |
||||||
|
wcharsize = cpp.sizeof('wchar_t', prefix : '#include<wchar.h>') |
||||||
|
|
||||||
|
cdpp = configuration_data() |
||||||
|
cdpp.set('INTSIZE', intsize) |
||||||
|
cdpp.set('WCHARSIZE', wcharsize) |
||||||
|
cdpp.set('CONFIG', 'config.hpp') |
||||||
|
configure_file(input : 'config.h.in', output : 'config.hpp', configuration : cdpp) |
||||||
|
spp = configure_file(input : 'prog.c.in', output : 'prog.cc', configuration : cdpp) |
||||||
|
|
||||||
|
epp = executable('progpp', spp) |
||||||
|
test('sizeof test c++', epp) |
||||||
|
@ -1,6 +1,6 @@ |
|||||||
#include"config.h" |
#include "@CONFIG@" |
||||||
#include<stdio.h> |
#include <stdio.h> |
||||||
#include<wchar.h> |
#include <wchar.h> |
||||||
|
|
||||||
int main(int argc, char **argv) { |
int main(int argc, char **argv) { |
||||||
if(INTSIZE != sizeof(int)) { |
if(INTSIZE != sizeof(int)) { |
@ -1,11 +1,11 @@ |
|||||||
project('has header', 'c') |
project('has header', 'c', 'cpp') |
||||||
|
|
||||||
cc = meson.get_compiler('c') |
foreach comp : [meson.get_compiler('c'), meson.get_compiler('cpp')] |
||||||
|
if comp.has_header('stdio.h') == false |
||||||
|
error('Stdio missing.') |
||||||
|
endif |
||||||
|
|
||||||
if cc.has_header('stdio.h') == false |
if comp.has_header('ouagadougou.h') |
||||||
error('Stdio missing.') |
error('Found non-existant header.') |
||||||
endif |
endif |
||||||
|
endforeach |
||||||
if cc.has_header('ouagadougou.h') |
|
||||||
error('Found non-existant header.') |
|
||||||
endif |
|
||||||
|
@ -1,41 +1,43 @@ |
|||||||
project('has function', 'c') |
project('has function', 'c', 'cpp') |
||||||
|
|
||||||
cc = meson.get_compiler('c') |
compilers = [meson.get_compiler('c'), meson.get_compiler('cpp')] |
||||||
|
|
||||||
if not cc.has_function('printf', prefix : '#include<stdio.h>') |
foreach cc : compilers |
||||||
error('"printf" function not found (should always exist).') |
if not cc.has_function('printf', prefix : '#include<stdio.h>') |
||||||
endif |
error('"printf" function not found (should always exist).') |
||||||
|
endif |
||||||
|
|
||||||
# Should also be able to detect it without specifying the header |
# Should also be able to detect it without specifying the header |
||||||
# We check for a different function here to make sure the result is |
# We check for a different function here to make sure the result is |
||||||
# not taken from a cache (ie. the check above) |
# not taken from a cache (ie. the check above) |
||||||
# On MSVC fprintf is defined as an inline function in the header, so it cannot |
# On MSVC fprintf is defined as an inline function in the header, so it cannot |
||||||
# be found without the include. |
# be found without the include. |
||||||
if cc.get_id() != 'msvc' |
if cc.get_id() != 'msvc' |
||||||
assert(cc.has_function('fprintf'), '"fprintf" function not found without include (on !msvc).') |
assert(cc.has_function('fprintf'), '"fprintf" function not found without include (on !msvc).') |
||||||
else |
else |
||||||
assert(cc.has_function('fprintf', prefix : '#include <stdio.h>'), '"fprintf" function not found with include (on msvc).') |
assert(cc.has_function('fprintf', prefix : '#include <stdio.h>'), '"fprintf" function not found with include (on msvc).') |
||||||
endif |
endif |
||||||
|
|
||||||
if cc.has_function('hfkerhisadf', prefix : '#include<stdio.h>') |
if cc.has_function('hfkerhisadf', prefix : '#include<stdio.h>') |
||||||
error('Found non-existent function "hfkerhisadf".') |
error('Found non-existent function "hfkerhisadf".') |
||||||
endif |
endif |
||||||
|
|
||||||
# With glibc on Linux lchmod is a stub that will always return an error, |
# 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 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 |
# 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' |
# 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. |
# C library variants either, so the check should be safe either way hopefully. |
||||||
if host_machine.system() == 'linux' and cc.get_id() == 'gcc' |
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 (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> |
assert (not cc.has_function('lchmod', prefix : '''#include <sys/stat.h> |
||||||
#include <unistd.h>'''), '"lchmod" check should have failed') |
#include <unistd.h>'''), '"lchmod" check should have failed') |
||||||
endif |
endif |
||||||
|
|
||||||
# For some functions one needs to define _GNU_SOURCE before including the |
# 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 |
# right headers to get them picked up. Make sure we can detect these functions |
||||||
# as well without any prefix |
# as well without any prefix |
||||||
if cc.has_header_symbol('sys/socket.h', 'recvmmsg', prefix : '#define _GNU_SOURCE') |
if cc.has_header_symbol('sys/socket.h', 'recvmmsg', prefix : '#define _GNU_SOURCE') |
||||||
# We assume that if recvmmsg exists sendmmsg does too |
# We assume that if recvmmsg exists sendmmsg does too |
||||||
assert (cc.has_function('sendmmsg'), 'Failed to detect function "sendmmsg" (should always exist).') |
assert (cc.has_function('sendmmsg'), 'Failed to detect function "sendmmsg" (should always exist).') |
||||||
endif |
endif |
||||||
|
endforeach |
||||||
|
@ -1,19 +1,21 @@ |
|||||||
project('has member', 'c') |
project('has member', 'c', 'cpp') |
||||||
|
|
||||||
cc = meson.get_compiler('c') |
compilers = [meson.get_compiler('c'), meson.get_compiler('cpp')] |
||||||
|
|
||||||
if not cc.has_member('struct tm', 'tm_sec', prefix : '#include<time.h>') |
foreach cc : compilers |
||||||
error('Did not detect member of "struct tm" that exists: "tm_sec"') |
if not cc.has_member('struct tm', 'tm_sec', prefix : '#include<time.h>') |
||||||
endif |
error('Did not detect member of "struct tm" that exists: "tm_sec"') |
||||||
|
endif |
||||||
|
|
||||||
if cc.has_member('struct tm', 'tm_nonexistent', prefix : '#include<time.h>') |
if cc.has_member('struct tm', 'tm_nonexistent', prefix : '#include<time.h>') |
||||||
error('Not existing member "tm_nonexistent" found.') |
error('Not existing member "tm_nonexistent" found.') |
||||||
endif |
endif |
||||||
|
|
||||||
if not cc.has_members('struct tm', 'tm_sec', 'tm_min', prefix : '#include<time.h>') |
if not cc.has_members('struct tm', 'tm_sec', 'tm_min', prefix : '#include<time.h>') |
||||||
error('Did not detect members of "struct tm" that exist: "tm_sec" "tm_min"') |
error('Did not detect members of "struct tm" that exist: "tm_sec" "tm_min"') |
||||||
endif |
endif |
||||||
|
|
||||||
if cc.has_members('struct tm', 'tm_sec', 'tm_nonexistent2', prefix : '#include<time.h>') |
if cc.has_members('struct tm', 'tm_sec', 'tm_nonexistent2', prefix : '#include<time.h>') |
||||||
error('Not existing member "tm_nonexistent2" found.') |
error('Not existing member "tm_nonexistent2" found.') |
||||||
endif |
endif |
||||||
|
endforeach |
||||||
|
@ -1,29 +1,31 @@ |
|||||||
project('alignment', 'c') |
project('alignment', 'c', 'cpp') |
||||||
|
|
||||||
cc = meson.get_compiler('c') |
compilers = [meson.get_compiler('c'), meson.get_compiler('cpp')] |
||||||
|
|
||||||
# These tests should return the same value on all |
foreach cc : compilers |
||||||
# platforms. If (and when) they don't, fix 'em up. |
# These tests should return the same value on all |
||||||
if cc.alignment('char') != 1 |
# platforms. If (and when) they don't, fix 'em up. |
||||||
error('Alignment of char misdetected.') |
if cc.alignment('char') != 1 |
||||||
endif |
error('Alignment of char misdetected.') |
||||||
|
endif |
||||||
|
|
||||||
ptr_size = cc.sizeof('void*') |
ptr_size = cc.sizeof('void*') |
||||||
dbl_alignment = cc.alignment('double') |
dbl_alignment = cc.alignment('double') |
||||||
|
|
||||||
# These tests are not thorough. Doing this properly |
# These tests are not thorough. Doing this properly |
||||||
# would take a lot of work because it is strongly |
# would take a lot of work because it is strongly |
||||||
# platform and compiler dependent. So just check |
# platform and compiler dependent. So just check |
||||||
# that they produce something fairly sane. |
# that they produce something fairly sane. |
||||||
|
|
||||||
if ptr_size == 8 or ptr_size == 4 |
if ptr_size == 8 or ptr_size == 4 |
||||||
message('Size of ptr ok.') |
message('Size of ptr ok.') |
||||||
else |
else |
||||||
error('Size of ptr misdetected.') |
error('Size of ptr misdetected.') |
||||||
endif |
endif |
||||||
|
|
||||||
if dbl_alignment == 8 or dbl_alignment == 4 |
if dbl_alignment == 8 or dbl_alignment == 4 |
||||||
message('Alignment of double ok.') |
message('Alignment of double ok.') |
||||||
else |
else |
||||||
error('Alignment of double misdetected.') |
error('Alignment of double misdetected.') |
||||||
endif |
endif |
||||||
|
endforeach |
||||||
|
@ -1,11 +1,13 @@ |
|||||||
project('has type', 'c') |
project('has type', 'c', 'cpp') |
||||||
|
|
||||||
cc = meson.get_compiler('c') |
compilers = [meson.get_compiler('c'), meson.get_compiler('cpp')] |
||||||
|
|
||||||
if not cc.has_type('time_t', prefix : '#include<time.h>') |
foreach cc : compilers |
||||||
error('Did not detect type that exists.') |
if not cc.has_type('time_t', prefix : '#include<time.h>') |
||||||
endif |
error('Did not detect type that exists.') |
||||||
|
endif |
||||||
|
|
||||||
if cc.has_type('no_time_t', prefix : '#include<time.h>') |
if cc.has_type('no_time_t', prefix : '#include<time.h>') |
||||||
error('Not existing type found.') |
error('Not existing type found.') |
||||||
endif |
endif |
||||||
|
endforeach |
||||||
|
Loading…
Reference in new issue