Debian Codegraph @

vendored-meson/meson/test cases/common/32 has header/meson.build

raw
1 project('has header', 'c', 'cpp')
2
3 host_system = host_machine.system()
4 cpp = meson.get_compiler('cpp')
5
6 non_existent_header = 'ouagadougou.h'
7
8 # Copy it into the builddir to ensure that it isn't found even if it's there
9 configure_file(input : non_existent_header,
10 output : non_existent_header,
11 configuration : configuration_data())
12
13 is_libcxx = cpp.has_header_symbol('ciso646', '_LIBCPP_VERSION')
14
15 # Test that the fallback to __has_include also works on all compilers
16 #
17 # darwin: can't redefine builtin macros so the above doesn't work
18 # libcxx: Undefining __has_include() breaks LLVM libcxx platform.h
19 if host_system != 'darwin' and not is_libcxx
20 fallbacks = ['', '\n#undef __has_include']
21 else
22 fallbacks = ['']
23 endif
24
25 foreach fallback : fallbacks
26 foreach comp : [meson.get_compiler('c'), cpp]
27 assert(comp.has_header('stdio.h', prefix : fallback), 'Stdio missing.')
28
29 # stdio.h doesn't actually need stdlib.h, but just test that setting the
30 # prefix does not result in an error.
31 assert(comp.has_header('stdio.h', prefix : '#include <stdlib.h>' + fallback),
32 'Stdio missing.')
33
34 # XInput.h should not require type definitions from windows.h, but it does
35 # require macro definitions. Specifically, it requires an arch setting for
36 # VS2015 at least.
37 # We only do this check on MSVC because MinGW often defines its own wrappers
38 # that pre-include windows.h
39 if comp.get_id() == 'msvc'
40 assert(comp.has_header('XInput.h', prefix : '#include <windows.h>' + fallback),
41 'XInput.h should not be missing on Windows')
42 assert(comp.has_header('XInput.h', prefix : '#define _X86_' + fallback),
43 'XInput.h should not need windows.h')
44 endif
45
46 # Test that the following GCC bug doesn't happen:
47 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80005
48 # https://github.com/mesonbuild/meson/issues/1458
49 if host_system == 'linux'
50 assert(comp.has_header('linux/if.h', prefix : fallback),
51 'Could not find <linux/if.h>')
52 endif
53
54 # This header exists in the source and the builddir, but we still must not
55 # find it since we are looking in the system directories.
56 assert(not comp.has_header(non_existent_header, prefix : fallback),
57 'Found nonexistent header.')
58 endforeach
59 endforeach