I am using meson in a couple of C projects (projectA and projectB), where projectB links to a library from projectA. In projectA/meson.build, I have written a pkg-config projectA.pc file using meson, that is installed to join_paths(get_option('prefix'), get_option('libdir'), 'pkgconfig') as expected.
In projectB/meson.build I use dependency('projectA') to look for the projectA.pc file.
When I use a custom installation prefix to build projectA and projectB, meson is unable to find projectA.pc when building projectB. Is there a way to specify a PKG_CONFIG_PATH from projectB/meson.build?
This issue is reproduce with this minimal example:
projectA/meson.build:
project('projectA', 'c', version: '1')
pkg = import('pkgconfig')
pkg.generate(name : 'projectA',
description: 'ProjectA',
version: meson.project_version())
projectB/meson.build:
project('projectB', 'c', version: '1')
dep = dependency('projectA')
Commands:
meson buildA projectA --prefix=$PWD/install
(cd buildA && ninja install)
#[0/1] Installing files.
#Installing /tmp/test/buildA/meson-private/projectA.pc to /tmp/test/install/lib/x86_64-linux-gnu/pkgconfig
# [ The error: ]
meson buildB projectB --prefix=$PWD/install
#Native dependency 'projectA' not found
# [ My workaround: ]
PKG_CONFIG_PATH="$PWD/install/lib/x86_64-linux-gnu/pkgconfig" meson buildB projectB --prefix=$PWD/install
# Native dependency projectA found: YES 1
Is there a way to tell projectB/meson.build that dependency() should look into join_paths(get_option('prefix'), get_option('libdir'), 'pkgconfig')?
I was trying to have an environment variable set inside the meson dependency() call, but the env argument does not exist for dependency():
pkgconfigpath = join_paths(get_option('prefix'), get_option('libdir'), 'pkgconfig')
message('pkgconfig: @0@'.format(pkgconfigpath))
env_pkgconfig = environment()
env_pkgconfig.set('PKG_CONFIG_PATH', pkgconfigpath)
projectA_dep = dependency('projectA', env: env_pkgconfig)
Unfortunately the env: argument in dependency is ignored (it does not exist in the docs).
Appending ${prefix}/${libdir}/pkgconfig directory to PKG_CONFIG_PATH from meson makes sense to me. Is there a way to do it?