diff options
| author | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-05-30 14:05:55 +0530 |
|---|---|---|
| committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-05-30 15:25:39 +0530 |
| commit | ff07314a865d960aac2c377a94de766b68888ee5 (patch) | |
| tree | 3ac92f0913cd680c0e565f88e5f518248bb3d77b /test cases/common | |
| parent | c87c42b736197b726f3cca47e92bc836c773085e (diff) | |
| download | meson-ff07314a865d960aac2c377a94de766b68888ee5.tar.gz | |
New compiler method: check_header
This checks not only for existence, but also for usability of the
header, which means it does a full compilation and not just
pre-processing or __has_include.
Fixes https://github.com/mesonbuild/meson/issues/2246
Diffstat (limited to 'test cases/common')
| -rw-r--r-- | test cases/common/200 check header/meson.build | 48 | ||||
| -rw-r--r-- | test cases/common/200 check header/ouagadougou.h | 1 |
2 files changed, 49 insertions, 0 deletions
diff --git a/test cases/common/200 check header/meson.build b/test cases/common/200 check header/meson.build new file mode 100644 index 000000000..7b343d7e3 --- /dev/null +++ b/test cases/common/200 check header/meson.build @@ -0,0 +1,48 @@ +project('check header', 'c', 'cpp') + +host_system = host_machine.system() + +non_existant_header = 'ouagadougou.h' + +# Copy it into the builddir to ensure that it isn't found even if it's there +configure_file(input : non_existant_header, + output : non_existant_header, + copy: true) + +fallback = '' + +foreach comp : [meson.get_compiler('c'), meson.get_compiler('cpp')] + assert(comp.check_header('stdio.h', prefix : fallback), 'Stdio missing.') + + # stdio.h doesn't actually need stdlib.h, but just test that setting the + # prefix does not result in an error. + assert(comp.check_header('stdio.h', prefix : '#include <stdlib.h>' + fallback), + 'Stdio missing.') + + # Test that check_header behaves differently than has_header. The second + # check without windows.h will fail with check_header. + # We only do this check on MSVC because MinGW often defines its own wrappers + # that pre-include windows.h + if comp.get_id() == 'msvc' + assert(comp.check_header('XInput.h', prefix : '#include <windows.h>' + fallback), + 'XInput.h should not be missing on Windows') + assert(not comp.check_header('XInput.h'), 'XInput.h needs windows.h') + endif + + # Test that the following GCC bug doesn't happen: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80005 + # https://github.com/mesonbuild/meson/issues/1458 + if host_system == 'linux' + assert(comp.check_header('linux/if.h', prefix : fallback), + 'Could not find <linux/if.h>') + if comp.has_header('intrin.h', prefix : fallback) + assert(not comp.check_header('intrin.h'), + 'intrin.h should not be usable on linux') + endif + endif + + # This header exists in the source and the builddir, but we still must not + # find it since we are looking in the system directories. + assert(not comp.check_header(non_existant_header, prefix : fallback), + 'Found non-existant header.') +endforeach diff --git a/test cases/common/200 check header/ouagadougou.h b/test cases/common/200 check header/ouagadougou.h new file mode 100644 index 000000000..2f76c49cc --- /dev/null +++ b/test cases/common/200 check header/ouagadougou.h @@ -0,0 +1 @@ +#define OMG_THIS_SHOULDNT_BE_FOUND |
