Skip to content

Commit

Permalink
envconfig: add pkg_config_libdir property
Browse files Browse the repository at this point in the history
In order to unify the use of sysroot in the cross-file,
the pkg_config_libdir can now be passed directly in the file.
  • Loading branch information
Stéphane Cerveau committed Jan 15, 2020
1 parent 71bbcc7 commit e9636cf
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/markdown/Cross-compilation.md
Expand Up @@ -138,6 +138,7 @@ has_function_printf = true
c_args = ['-DCROSS=1', '-DSOMETHING=3']
c_link_args = ['-some_link_arg']
sys_root = '/some/path'
pkg_config_libdir = '/some/path/lib/pkgconfig'
```

In most cases you don't need the size and alignment settings, Meson
Expand All @@ -155,6 +156,10 @@ internally by Meson to set the PKG_CONFIG_SYSROOT_DIR environment variable
for pkg-config. If this is unset the host system is assumed to share a root
with the build system.

*Since 0.54.0* The pkg_config_libdir property may point to a list of path used
internally by Meson to set the PKG_CONFIG_LIBDIR environment variable for pkg-config.
This prevents pkg-config from searching cross dependencies in system directories.

One important thing to note, if you did not define an `exe_wrapper` in
the previous section, is that Meson will make a best-effort guess at
whether it can run the generated binaries on the build machine. It
Expand Down
7 changes: 6 additions & 1 deletion mesonbuild/dependencies/base.py
Expand Up @@ -693,10 +693,15 @@ def _call_pkgbin(self, args, env=None):
sysroot = self.env.properties[self.for_machine].get_sys_root()
if sysroot:
env['PKG_CONFIG_SYSROOT_DIR'] = sysroot
new_pkg_config_path = ':'.join([p for p in extra_paths])
new_pkg_config_path = os.pathsep.join(extra_paths)
mlog.debug('PKG_CONFIG_PATH: ' + new_pkg_config_path)
env['PKG_CONFIG_PATH'] = new_pkg_config_path

pkg_config_libdir_prop = self.env.properties[self.for_machine].get_pkg_config_libdir()
if pkg_config_libdir_prop:
new_pkg_config_libdir = os.pathsep.join(pkg_config_libdir_prop)
env['PKG_CONFIG_LIBDIR'] = new_pkg_config_libdir

fenv = frozenset(env.items())
targs = tuple(args)
cache = PkgConfigDependency.pkgbin_cache
Expand Down
6 changes: 6 additions & 0 deletions mesonbuild/envconfig.py
Expand Up @@ -140,6 +140,12 @@ def get_root(self) -> T.Optional[T.Union[str, T.List[str]]]:
def get_sys_root(self) -> T.Optional[T.Union[str, T.List[str]]]:
return self.properties.get('sys_root', None)

def get_pkg_config_libdir(self) -> T.Optional[T.Union[str, T.List[str]]]:
p = self.properties.get('pkg_config_libdir', None)
if p is None:
return p
return mesonlib.listify(p)

def __eq__(self, other: T.Any) -> 'T.Union[bool, NotImplemented]':
if isinstance(other, type(self)):
return self.properties == other.properties
Expand Down
16 changes: 15 additions & 1 deletion run_unittests.py
Expand Up @@ -5665,6 +5665,20 @@ def test_pkgconfig_link_order(self):
deps = stdo.split()
self.assertTrue(deps.index(b'-lsomething') < deps.index(b'-ldependency'))

@skipIfNoPkgconfig
def test_pkgconfig_cross_linkdir(self):
'''
Test that libraries are listed before their dependencies.
'''
testdir = os.path.join(self.unit_test_dir, '73 cross pkgconfig libdir')
self.init(testdir, extra_args=['-Dgenerate=true'])
self.meson_cross_file = os.path.join(self.builddir, "crossfile")
self.assertTrue(os.path.exists(self.meson_cross_file))
self.new_builddir()
self.init(testdir, default_args=False, extra_args=['--cross-file', self.meson_cross_file])



def test_deterministic_dep_order(self):
'''
Test that the dependencies are always listed in a deterministic order.
Expand Down Expand Up @@ -6768,7 +6782,7 @@ def test_compile_sys_path(self):

class CrossFileTests(BasePlatformTests):

"""Tests for cross file functioality not directly related to
"""Tests for cross file functionality not directly related to
cross compiling.
This is mainly aimed to testing overrides from cross files.
Expand Down
6 changes: 6 additions & 0 deletions test cases/unit/73 cross pkgconfig libdir/crossfile.in
@@ -0,0 +1,6 @@

[properties]
pkg_config_libdir = ['@pkg_config_libdir@']

[binaries]
pkgconfig = 'pkg-config'
17 changes: 17 additions & 0 deletions test cases/unit/73 cross pkgconfig libdir/meson.build
@@ -0,0 +1,17 @@
project('crosspkgconfiglibdir')

if get_option('generate')
conf_data = configuration_data()
conf_data.set('pkg_config_libdir', meson.current_source_dir())

configure_file(input: 'crossfile.in',
output: 'crossfile',
configuration: conf_data)
message('Written cross file')
else
assert(meson.is_cross_build(), 'not setup as cross build')
build = dependency('zlib', method : 'pkg-config', native : true)
host = dependency('zlib', method : 'pkg-config', native : false)
assert(build.version() != '9.9.99', 'wrong version for build machine dependency')
assert(host.version() == '9.9.99', 'wrong version for host machine dependency')
endif
@@ -0,0 +1 @@
option('generate', type : 'boolean', value : false)
13 changes: 13 additions & 0 deletions test cases/unit/73 cross pkgconfig libdir/zlib.pc
@@ -0,0 +1,13 @@
prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/lib/x86_64-linux-gnu
sharedlibdir=${libdir}
includedir=${prefix}/include

Name: zlib
Description: zlib compression library
Version: 9.9.99

Requires:
Libs: -L${libdir} -L${sharedlibdir} -lz
Cflags: -I${includedir}

0 comments on commit e9636cf

Please sign in to comment.