| 1 |
project('external dependency', 'c') |
| 2 |
|
| 3 |
# Zlib is probably on all dev machines. |
| 4 |
|
| 5 |
dep = dependency('zlib', version : '>=1.2', |
| 6 |
not_found_message: 'DANGER! DANGER! THIS MUST NEVER BE SEEN!') |
| 7 |
exe = executable('zlibprog', 'prog-checkver.c', |
| 8 |
dependencies : dep, |
| 9 |
c_args : '-DFOUND_ZLIB="' + dep.version() + '"') |
| 10 |
|
| 11 |
assert(dep.version().version_compare('>=1.2'), 'Pkg-config version numbers exposed incorrectly.') |
| 12 |
|
| 13 |
# Check that the version exposed by zlib internally is the same as the one we |
| 14 |
# retrieve from the pkg-config file. This assumes that the packager didn't mess |
| 15 |
# up, but we can be reasonably sure of that. |
| 16 |
test('zlibtest', exe) |
| 17 |
|
| 18 |
zprefix = dep.get_pkgconfig_variable('prefix') # Always set but we can't be sure what the value is. |
| 19 |
# pkg-config returns empty string for not defined variables |
| 20 |
assert(dep.get_pkgconfig_variable('nonexisting') == '', 'Value of unknown variable is not empty.') |
| 21 |
# ... unless default: is used |
| 22 |
assert(dep.get_pkgconfig_variable('nonexisting', default: 'foo') == 'foo', 'Value of unknown variable is not defaulted.') |
| 23 |
# pkg-config is able to replace variables |
| 24 |
assert(dep.get_pkgconfig_variable('prefix', define_variable: ['prefix', '/tmp']) == '/tmp', 'prefix variable has not been replaced.') |
| 25 |
assert(dep.get_variable('prefix', pkgconfig_define: ['prefix', '/tmp']) == '/tmp', 'prefix variable has not been replaced.') |
| 26 |
# pkg-config can replace multiple variables at once |
| 27 |
assert(dep.get_variable('prefix', pkgconfig_define: ['prefix', '/tmp', 'libdir', '/bad/libdir']) == '/tmp', 'first variable has not been replaced.') |
| 28 |
assert(dep.get_variable('prefix', pkgconfig_define: ['libdir', '/bad/libdir', 'prefix', '/tmp']) == '/tmp', 'second variable has not been replaced.') |
| 29 |
assert(dep.get_pkgconfig_variable('prefix', define_variable: ['prefix', '/tmp', 'libdir', '/bad/libdir']) == '/tmp', 'first variable has not been replaced.') |
| 30 |
assert(dep.get_pkgconfig_variable('prefix', define_variable: ['libdir', '/bad/libdir', 'prefix', '/tmp']) == '/tmp', 'second variable has not been replaced.') |
| 31 |
|
| 32 |
|
| 33 |
# Test that dependencies of dependencies work. |
| 34 |
dep2 = declare_dependency(dependencies : dep) |
| 35 |
exe2 = executable('zlibprog2', 'prog.c', dependencies : dep2) |
| 36 |
test('zlibtest2', exe2) |
| 37 |
|
| 38 |
# Try to find a nonexistent library to ensure requires:false works. |
| 39 |
|
| 40 |
dep = dependency('nvakuhrabnsdfasdf', required : false, |
| 41 |
not_found_message : 'This dependency was not found as was expected.') |
| 42 |
|
| 43 |
# Try to compile a test that takes a dep and an include_directories |
| 44 |
|
| 45 |
cc = meson.get_compiler('c') |
| 46 |
zlibdep = cc.find_library('z') |
| 47 |
code = '''#include<myinc.h> |
| 48 |
|
| 49 |
int main(void) { |
| 50 |
void * something = deflate; |
| 51 |
if(something != 0) |
| 52 |
return 0; |
| 53 |
return 1; |
| 54 |
} |
| 55 |
''' |
| 56 |
|
| 57 |
inc = include_directories('incdir') |
| 58 |
|
| 59 |
r = cc.run(code, include_directories : inc, dependencies : zlibdep) |
| 60 |
assert(r.returncode() == 0, 'Running manual zlib test failed.') |