Skip to content

Commit c06e932

Browse files
committed
modules/pkgconfig: Resolve dependencies in case of an internal dependency
When giving a dependency object as requires, allow to use the dependency from a subproject (that is an InternalDepdency).
1 parent 68d29ef commit c06e932

File tree

6 files changed

+58
-0
lines changed

6 files changed

+58
-0
lines changed

mesonbuild/modules/pkgconfig.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ def _process_reqs(self, reqs: T.Sequence[T.Union[str, build.StaticLibrary, build
156156
pass
157157
elif isinstance(obj, dependencies.ExternalDependency) and obj.name == 'threads':
158158
pass
159+
elif isinstance(obj, dependencies.InternalDependency) and all(lib.get_id() in self.metadata for lib in obj.libraries):
160+
# Ensure BothLibraries are resolved:
161+
if self.pub_libs and isinstance(self.pub_libs[0], build.StaticLibrary):
162+
obj = obj.get_as_static(recursive=True)
163+
else:
164+
obj = obj.get_as_shared(recursive=True)
165+
for lib in obj.libraries:
166+
processed_reqs.append(self.metadata[lib.get_id()].filebase)
159167
else:
160168
raise mesonlib.MesonException('requires argument not a string, '
161169
'library with pkgconfig-generated file '
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
project('test1', 'c', meson_version: '>=1.9.0')
2+
pkg = import('pkgconfig')
3+
4+
test2_dep = dependency('test2')
5+
6+
test1_lib = library('test1',
7+
'test1.c',
8+
dependencies: [test2_dep]
9+
)
10+
11+
pkg.generate(test1_lib,
12+
requires: test2_dep,
13+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
project('test2', 'c', meson_version: '>=1.9.0')
2+
pkg = import('pkgconfig')
3+
4+
test2_lib = library(
5+
'test2',
6+
'test2.c',
7+
)
8+
9+
test2_dep = declare_dependency(
10+
link_with: test2_lib,
11+
include_directories: include_directories('.')
12+
)
13+
14+
pkg.generate(test2_lib)
15+
16+
meson.override_dependency('test2', test2_dep)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int exposed_function2(void) {
2+
return 42;
3+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"installed": [
3+
{ "type": "file", "file": "usr/lib/pkgconfig/test1.pc"},
4+
{ "type": "file", "file": "usr/lib/pkgconfig/test2.pc"}
5+
],
6+
"matrix": {
7+
"options": {
8+
"default_library": [
9+
{ "val": "shared" },
10+
{ "val": "static" },
11+
{ "val": "both" }
12+
]
13+
}
14+
}
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int exposed_function(void) {
2+
return 42;
3+
}

0 commit comments

Comments
 (0)