Debian Codegraph @

test cases/common/28 try compile/meson.build

raw
1 project('try compile', 'c', 'cpp')
2
3 code = '''#include<stdio.h>
4 void func(void) { printf("Something.\n"); }
5 '''
6
7 breakcode = '''#include<nonexisting.h>
8 void func(void) { printf("This won't work.\n"); }
9 '''
10
11 warncode = '''#warning This is a warning
12 int main(void) { return 0; }
13 '''
14
15 configure_file(
16 input: 'foo.h.in',
17 output: 'foo.h',
18 configuration: {},
19 )
20
21 header_code = '#include "foo.h"'
22
23 foreach lang : ['c', 'cpp']
24 compiler = meson.get_compiler(lang)
25
26 assert(not compiler.compiles(header_code, name: 'Should not include . by default'))
27 assert(compiler.compiles(header_code, name: 'Should include builddir',
28 include_directories: include_directories('.'),
29 ))
30
31 if compiler.compiles(code, name : 'code should succeed') == false
32 error('Compiler ' + compiler.get_id() + ' is fail.')
33 endif
34
35 if compiler.compiles(files('valid.c'), name : 'file should succeed') == false
36 error('Compiler ' + compiler.get_id() + ' is fail.')
37 endif
38
39 copied = configure_file(input: 'valid.c', output: lang + '-valid-copy.c', copy: true)
40 if compiler.compiles(copied, name : 'built file should succeed') == false
41 error('Compiler ' + compiler.get_id() + ' is fail.')
42 endif
43
44 if compiler.compiles(breakcode, name : 'code should fail')
45 error('Compiler ' + compiler.get_id() + ' returned true on broken code.')
46 endif
47
48 if compiler.compiles(files('invalid.c'), name : 'file should fail')
49 error('Compiler ' + compiler.get_id() + ' returned true on broken code.')
50 endif
51
52 # MSVC does not support #warning instruction
53 if compiler.get_id() != 'msvc'
54 # First check that all tests pass without werror, then check they fail with it.
55 foreach with_werror : [false, true]
56 expect_success = not with_werror
57 assert(compiler.compiles(warncode,
58 name: f'code with warning compiles with werror=@with_werror@',
59 werror: with_werror) == expect_success)
60 assert(compiler.links(warncode,
61 name: f'code with warning links with werror=@with_werror@',
62 werror: with_werror) == expect_success)
63 if meson.can_run_host_binaries()
64 assert((compiler.run(warncode,
65 name: f'code with warning runs with werror=@with_werror@',
66 werror: with_werror).returncode() == 0) == expect_success)
67 endif
68 endforeach
69 endif
70 endforeach