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