1project('proj', 'c') 2subproject('sub') 3libSub = dependency('sub', fallback: ['sub', 'libSub']) 4 5exe = executable('prog', 'prog.c', dependencies: libSub) 6test('subproject subdir', exe) 7 8# Verify the subproject has placed dependency override. 9dependency('sub-1.0') 10 11# Verify we can now take 'sub' dependency without fallback, but only version 1.0. 12dependency('sub') 13d = dependency('sub', version : '>=2.0', required : false) 14assert(not d.found(), 'version should not match') 15 16# Verify that not-found does not get cached, we can still fallback afterward. 17dependency('sub2', required : false) 18d = dependency('sub2', fallback: ['sub', 'libSub']) 19assert(d.found(), 'Should fallback even if a previous call returned not-found') 20 21# Verify we can get a fallback dependency without specifying the variable name, 22# because the subproject overridden 'sub-novar'. 23dependency('sub-novar', fallback : 'sub_novar') 24 25# Verify a subproject can force a dependency to be not-found 26d = dependency('sub-notfound', fallback : 'sub_novar', required : false) 27assert(not d.found(), 'Dependency should be not-found') 28 29# Verify that implicit fallback works because subprojects/sub_implicit directory exists 30d = dependency('sub_implicit', default_options: 'opt=overriden') 31assert(d.found(), 'Should implicitly fallback') 32 33# Verify that implicit fallback works because sub_implicit.wrap has 34# `dependency_names=sub_implicit_provide1` and the subproject overrides sub_implicit_provide1. 35d = dependency('sub_implicit_provide1') 36assert(d.found(), 'Should implicitly fallback') 37 38# Verify that implicit fallback works because sub_implicit.wrap has 39# `sub_implicit_provide2=sub_implicit_provide2_dep` and does not override 40# sub_implicit_provide2. 41d = dependency('sub_implicit_provide2') 42assert(d.found(), 'Should implicitly fallback') 43 44# sub_implicit.wrap provides glib-2.0 and we already configured that subproject, 45# so we must not return the system dependency here. Using glib-2.0 here because 46# some CI runners have it installed. 47d = dependency('glib-2.0', required : false) 48assert(d.found()) 49assert(d.type_name() == 'internal') 50 51# sub_implicit.wrap provides gobject-2.0 and we already configured that subproject, 52# so we must not return the system dependency here. But since the subproject did 53# not override that dependency and its not required, not-found should be returned. 54# Using gobject-2.0 here because some CI runners have it installed. 55d = dependency('gobject-2.0', required : false) 56assert(not d.found()) 57 58# Verify that implicit fallback works because subprojects/sub_implicit/subprojects/subsub 59# directory exists. 60d = dependency('subsub') 61assert(d.found(), 'Should be able to fallback to sub-subproject') 62 63# Verify that implicit fallback works because 64# subprojects/sub_implicit/subprojects/subsub/subprojects/subsubsub.wrap 65# file exists. 66d = dependency('subsubsub') 67assert(d.found(), 'Should be able to fallback to sub-sub-subproject') 68 69# Verify that `static: true` implies 'default_library=static'. 70d = dependency('sub_static', static: true) 71assert(d.found()) 72# Verify that when not specifying static kwarg we can still get fallback dep. 73d = dependency('sub_static') 74assert(d.found()) 75# But when asking for shared library explicitly, it is not found. 76d = dependency('sub_static', static: false, required: false) 77assert(not d.found()) 78# The subproject also overrides sub_static2 with `static: true` 79d = dependency('sub_static2') 80assert(d.found()) 81d = dependency('sub_static2', static: true) 82assert(d.found()) 83d = dependency('sub_static2', static: false, required: false) 84assert(not d.found()) 85# sub_static3 is overridden twice with `static: true` and `static: false` 86d = dependency('sub_static3') 87assert(d.found()) 88assert(d.get_variable('static') == 'true') 89d = dependency('sub_static3', static: true) 90assert(d.found()) 91assert(d.get_variable('static') == 'true') 92d = dependency('sub_static3', static: false) 93assert(d.found()) 94assert(d.get_variable('static') == 'false') 95