diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 3df3a451a..fd0385d74 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2816,6 +2816,12 @@ external dependencies (including libraries) must go to "dependencies".''') if not dep: return False found = dep.version_method([], {}) + # Don't do a version check if the dependency is not found and not required + if found == 'none' and not required: + subproj_path = os.path.join(self.subproject_dir, dirname) + mlog.log('Dependency', mlog.bold(name), 'from subproject', + mlog.bold(subproj_path), 'found:', mlog.red('NO'), '(cached)') + return dep if self.check_subproject_version(wanted, found): subproj_path = os.path.join(self.subproject_dir, dirname) mlog.log('Dependency', mlog.bold(name), 'from subproject', diff --git a/test cases/common/176 subproject nested subproject dirs/contrib/subprojects/beta/meson.build b/test cases/common/176 subproject nested subproject dirs/contrib/subprojects/beta/meson.build index ea4cc9bdf..1720d3e7c 100644 --- a/test cases/common/176 subproject nested subproject dirs/contrib/subprojects/beta/meson.build +++ b/test cases/common/176 subproject nested subproject dirs/contrib/subprojects/beta/meson.build @@ -1,3 +1,4 @@ project('beta project', 'c') lb = shared_library('b', 'b.c') +notfound = dependency('', required : false) diff --git a/test cases/common/176 subproject nested subproject dirs/meson.build b/test cases/common/176 subproject nested subproject dirs/meson.build index a4d0a9716..875eed350 100644 --- a/test cases/common/176 subproject nested subproject dirs/meson.build +++ b/test cases/common/176 subproject nested subproject dirs/meson.build @@ -3,5 +3,9 @@ project('gamma project', 'c', subproject_dir: 'contrib/subprojects') a = subproject('alpha') lib = a.get_variable('l') +# Ensure that the dependency version is not checked for a not-found dependency +notfound = dependency('', version : '>=1.0', required : false, + fallback : ['beta', 'notfound']) + exe = executable('prog', 'prog.c', link_with : lib) test('basic', exe)