Debian Codegraph @

test cases/linuxlike/5 dependency versions/meson.build

raw
1 project('dep versions', 'c', 'cpp')
2
3 # Find external dependency without version
4 zlib = dependency('zlib')
5 # Find external dependency with version
6 zlibver = dependency('zlib', version : '>1.0')
7 assert(zlib.version() == zlibver.version(), 'zlib versions did not match!')
8 # Find external dependency with conflicting version
9 assert(zlib.type_name() == 'pkgconfig', 'zlib should be of type "pkgconfig" not ' + zlib.type_name())
10 zlibver = dependency('zlib', version : '<1.0', required : false)
11 assert(zlibver.found() == false, 'zlib <1.0 should not be found!')
12
13 # Find external dependencies with various version restrictions
14 dependency('zlib', version : '>=1.0')
15 dependency('zlib', version : '<=9999')
16 dependency('zlib', version : '=' + zlib.version())
17
18 # Find external dependencies with multiple version restrictions
19 dependency('zlib', version : ['>=1.0', '<=9999'])
20 if dependency('zlib', version : ['<=1.0', '>=9999', '=' + zlib.version()], required : false).found()
21 error('zlib <=1.0 >=9999 should not have been found')
22 endif
23
24 # Test that a versionless zlib is found after not finding an optional zlib dep with version reqs
25 zlibopt = dependency('zlib', required : false)
26 assert(zlibopt.found() == true, 'zlib not found')
27
28 # Test https://github.com/mesonbuild/meson/pull/610
29 dependency('somebrokenlib', version : '>=2.0', required : false)
30 dependency('somebrokenlib', version : '>=1.0', required : false)
31
32 # Search for an external dependency that won't be found, but must later be
33 # found via fallbacks
34 somelibnotfound = dependency('somelib1', required : false)
35 assert(somelibnotfound.found() == false, 'somelibnotfound was found?')
36 # Find internal dependency without version
37 somelibver = dependency('somelib1',
38 fallback : ['somelibnover', 'some_dep'])
39 assert(somelibver.type_name() == 'internal', 'somelibver should be of type "internal", not ' + somelibver.type_name())
40 # Find an internal dependency again with the same name and a specific version
41 somelib = dependency('somelib2',
42 version : '== 0.1',
43 fallback : ['somelib', 'some_dep'])
44 # Find an internal dependency again even if required = false
45 somelib_reqfalse = dependency('somelib3',
46 required: false,
47 fallback : ['somelib', 'some_dep'])
48 assert(somelib_reqfalse.found(), 'somelib should have been found')
49 # Find an internal dependency again with the same name and incompatible version
50 somelibver = dependency('somelib4',
51 version : '>= 0.3',
52 fallback : ['somelibver', 'some_dep'])
53 # Find an internal dependency again with impossible multi-version
54 somelibver = dependency('somelib5',
55 version : ['>= 0.3', '<0.3'],
56 required : false,
57 fallback : ['somelibver', 'some_dep'])
58 assert(not somelibver.found(), 'Dependency should not be found')
59 # Find somelib again, but with a fallback that will fail because subproject does not exist
60 somelibfail = dependency('somelib6',
61 version : '>= 0.2',
62 required : false,
63 fallback : ['somelibfail', 'some_dep'])
64 assert(somelibfail.found() == false, 'somelibfail found via wrong fallback')
65 # Find somelib again, but with a fallback that will fail because dependency does not exist
66 somefail_dep = dependency('somelib7',
67 version : '>= 0.2',
68 required : false,
69 fallback : ['somelib', 'somefail_dep'])
70 assert(somefail_dep.found() == false, 'somefail_dep found via wrong fallback')
71
72 # Fallback should only be used if the primary was not found
73 fallbackzlib_dep = dependency('zlib',
74 fallback : ['fakezlib', 'fakezlib_dep'])
75 assert(fallbackzlib_dep.type_name() == 'pkgconfig', 'fallbackzlib_dep should be of type "pkgconfig", not ' + fallbackzlib_dep.type_name())
76 # Check that the above dependency was pkgconfig because the fallback wasn't
77 # checked, not because the fallback didn't work
78 fakezlib_dep = dependency('fakezlib',
79 fallback : ['fakezlib', 'fakezlib_dep'])
80 assert(fakezlib_dep.type_name() == 'internal', 'fakezlib_dep should be of type "internal", not ' + fakezlib_dep.type_name())
81
82 # Verify that once we got a system dependency, we won't fallback if a newer
83 # version is requested.
84 d = dependency('zlib', version: '>= 999',
85 fallback : ['nonexistent', 'fakezlib_dep'],
86 required: false)
87 assert(not d.found(), 'version should not match and it should not fallback')
88
89 # Check that you can find a dependency by not specifying a version after not
90 # finding it by specifying a version. We add `static: true` here so that the
91 # previously cached zlib dependencies don't get checked.
92 dependency('zlib', static : true, version : '>=8000', required : false)
93 dependency('zlib', static : true)
94
95 # Check that you can find a dependency by specifying a correct version after
96 # not finding it by specifying a wrong one. We add `method: pkg-config` here so that
97 # the previously cached zlib dependencies don't get checked.
98 bzip2 = dependency('zlib', method : 'pkg-config', version : '>=9000', required : false)
99 bzip2 = dependency('zlib', method : 'pkg-config', version : '>=1.0')
100
101 if meson.is_cross_build()
102 # Test caching of native and cross dependencies
103 # https://github.com/mesonbuild/meson/issues/1736
104 cross_prefix = dependency('zlib').get_pkgconfig_variable('prefix')
105 native_prefix = dependency('zlib', native : true).get_pkgconfig_variable('prefix')
106 assert(cross_prefix != '', 'cross zlib prefix is not defined')
107 assert(native_prefix != '', 'native zlib prefix is not defined')
108 assert(native_prefix != cross_prefix, 'native prefix == cross_prefix == ' + native_prefix)
109 endif
110
111 objc_found = add_languages('objc', required : false)
112
113 foreach d : ['sdl2', 'gnustep', 'wxwidgets', 'gl', 'python3', 'boost', 'gtest', 'gmock', 'valgrind']
114 if d == 'gnustep' and not objc_found
115 message('Skipping gnustep because no ObjC compiler found')
116 else
117 dep = dependency(d, required : false)
118 if dep.found()
119 dep.version()
120 endif
121 endif
122 endforeach