1project(
2  'dependency include_type',
3  ['c', 'cpp'],
4)
5
6dep = dependency('zlib', method: 'pkg-config', required : false)
7boost_dep = dependency('boost', modules: ['graph'], include_type : 'system', required: false)
8
9if not dep.found()
10  error('MESON_SKIP_TEST zlib was not found')
11endif
12
13if not boost_dep.found()
14  error('MESON_SKIP_TEST boost was not found')
15endif
16
17assert(dep.include_type() == 'preserve', 'include_type must default to "preserve"')
18
19dep_sys = dep.as_system()
20assert(dep_sys.include_type() == 'system', 'as_system must return a system dep')
21
22dep2 = dependency('zlib', method: 'pkg-config', include_type : 'system')
23assert(dep2.include_type() == 'system', 'include_type must be true when set')
24
25dep2_sys = dep2.as_system('non-system')
26assert(dep2_sys.include_type() == 'non-system', 'as_system must set include_type correctly')
27
28sp = subproject('subDep')
29sp_dep = sp.get_variable('subDep_dep')
30assert(sp_dep.include_type() == 'preserve', 'default is preserve')
31
32sp_dep_sys = sp_dep.as_system('system')
33assert(sp_dep_sys.include_type() == 'system', 'changing include_type works')
34assert(sp_dep.include_type() == 'preserve', 'as_system must not mutate the original object')
35
36fallback = dependency('sdffgagf_does_not_exist', include_type: 'system', fallback: ['subDep', 'subDep_dep'])
37assert(fallback.include_type() == 'system', 'include_type works with dependency fallback')
38
39fallback_empty = dependency('', include_type: 'system', fallback: ['subDep', 'subDep_dep'])
40assert(fallback_empty.include_type() == 'system', 'include_type works with empty name dependency fallback')
41
42# Check that PCH works with `include_type : 'system'` See https://github.com/mesonbuild/meson/issues/7167
43main_exe = executable('main_exe', 'main.cpp', cpp_pch: 'pch/test.hpp', dependencies: boost_dep)
44test('main_test', main_exe)
45