Improve generation of pkg-config files for static only libraries.

Previously pkg-config files generated by the pkgconfig modules for static libraries
with dependencies could only be used in a dependencies with `static: true`.

This was caused by the dependencies only appearing in Libs.private even
if they are needed in the default linking mode. But a user of a
dependency should not have to know if the default linking mode is static
or dynamic; A dependency('somelib') call should always pull in all
needed pieces into the build.

Now for meson build static libraries passed via `libraries` to the generate
method automatically promote dependencies to public.
pull/3411/head
Martin Hostettler 7 years ago committed by Jussi Pakkanen
parent 7c37ca15f3
commit 3f7c6cf3d6
  1. 12
      docs/markdown/snippets/pkg-config-fix-static-only.md
  2. 8
      mesonbuild/modules/pkgconfig.py
  3. 21
      run_unittests.py
  4. 2
      test cases/common/51 pkgconfig-gen/dependencies/meson.build
  5. 6
      test cases/unit/28 pkgconfig use libraries/app/app.c
  6. 5
      test cases/unit/28 pkgconfig use libraries/app/meson.build
  7. 2
      test cases/unit/28 pkgconfig use libraries/lib/liba.c
  8. 5
      test cases/unit/28 pkgconfig use libraries/lib/libb.c
  9. 16
      test cases/unit/28 pkgconfig use libraries/lib/meson.build

@ -0,0 +1,12 @@
## Improved generation of pkg-config files for static only libraries.
Previously pkg-config files generated by the pkgconfig modules for static libraries
with dependencies could only be used in a dependencies with `static: true`.
Now the generated file contains the needed dependencies libraries directly within
`Requires` and `Libs` for build static libraries passed via the `libraries` keyword
argument.
Projects that install both a static and a shared version of a library should use
the result of `both_libraries` to the pkg config file generator or use
configure_file for more complicated setups.

@ -119,11 +119,15 @@ class DependenciesHelper:
obj.generated_pc = self.name
elif isinstance(obj, (build.SharedLibrary, build.StaticLibrary)):
processed_libs.append(obj)
self.add_priv_libs(obj.get_dependencies())
self.add_priv_libs(obj.get_external_deps())
if public:
if not hasattr(obj, 'generated_pc'):
obj.generated_pc = self.name
if isinstance(obj, build.StaticLibrary) and public:
self.add_pub_libs(obj.get_dependencies())
self.add_pub_libs(obj.get_external_deps())
else:
self.add_priv_libs(obj.get_dependencies())
self.add_priv_libs(obj.get_external_deps())
elif isinstance(obj, str):
processed_libs.append(obj)
else:

@ -2841,6 +2841,27 @@ endian = 'little'
self.assertTrue(os.path.isfile(test_exe))
subprocess.check_call(test_exe, env=myenv)
@unittest.skipIf(shutil.which('pkg-config') is None, 'Pkg-config not found.')
def test_pkgconfig_internal_libraries(self):
'''
'''
with tempfile.TemporaryDirectory() as tempdirname:
# build library
testdirbase = os.path.join(self.unit_test_dir, '28 pkgconfig use libraries')
testdirlib = os.path.join(testdirbase, 'lib')
self.init(testdirlib, extra_args=['--prefix=' + tempdirname,
'--libdir=lib',
'--default-library=static'], default_args=False)
self.build()
self.install(use_destdir=False)
# build user of library
pkg_dir = os.path.join(tempdirname, 'lib/pkgconfig')
os.environ['PKG_CONFIG_PATH'] = pkg_dir
self.new_builddir()
self.init(os.path.join(testdirbase, 'app'))
self.build()
class LinuxArmCrossCompileTests(BasePlatformTests):
'''

@ -5,7 +5,7 @@ pkgg = import('pkgconfig')
# libmain internally use libinternal and expose libexpose in its API
exposed_lib = shared_library('libexposed', 'exposed.c')
internal_lib = shared_library('libinternal', 'internal.c')
main_lib = static_library('libmain', link_with : [exposed_lib, internal_lib])
main_lib = both_libraries('libmain', link_with : [exposed_lib, internal_lib])
pkgg.generate(exposed_lib)

@ -0,0 +1,6 @@
void libb_func();
int main() {
libb_func();
return 0;
}

@ -0,0 +1,5 @@
project('app', ['c'])
b = dependency('test-b')
executable('app', 'app.c', dependencies : [b])

@ -0,0 +1,5 @@
void liba_func();
void libb_func() {
liba_func();
}

@ -0,0 +1,16 @@
project('lib', ['c'])
a = library('test-a', 'liba.c', install: true)
b = library('test-b', 'libb.c', link_with: a, install: true)
import('pkgconfig').generate(
version: '0.0',
description: 'test library',
filebase: 'test-b',
name: 'test library',
libraries: [b],
subdirs: ['.']
)
Loading…
Cancel
Save