Set PKG_CONFIG_PATH inside meson.build
Asked Answered
E

2

6

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?

Ealing answered 9/8, 2017 at 18:28 Comment(0)
E
2

After asking on the IRC, I was informed that PKG_CONFIG_PATH should be set by the user (not by me) so meson does not provide a way to change it.

The best approach in this case would be to use subprojects or wraps so meson handles everything at once.

Ealing answered 9/8, 2017 at 20:8 Comment(0)
Q
1

set PKG_CONFIG_PATH to wherever projectA's .pc file is when you build projectB.

Yes, PKG_CONFIG_PATH is for users for sure. However, in this context, whoever compiles your projectA and projectB is a user, even you are.

ie) When you want to compile projectB because you want to test projectB against new version of projectA which is installed to a different directory, then you must adjust the PKG_CONFIG_PATH.

And Yes, it's much easier for your user if you setup projectB having projectA as a subproject.

Quinidine answered 10/8, 2017 at 2:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.