pkgconfig: Add a simple version of the generator (#3284)

pull/3336/head
Xavier Claessens 7 years ago committed by Jussi Pakkanen
parent 9b2e533d87
commit b4aee4675a
  1. 7
      docs/markdown/Pkgconfig-module.md
  2. 14
      docs/markdown/snippets/pkgconfig-generator.md
  3. 28
      mesonbuild/modules/pkgconfig.py
  4. 8
      test cases/common/51 pkgconfig-gen/dependencies/meson.build

@ -51,3 +51,10 @@ keyword arguments.
- `version` a string describing the version of this library
- `d_module_versions` a list of module version flags used when compiling
D sources referred to by this pkg-config file
Since 0.46 a `StaticLibrary` or `SharedLibrary` object can optionally be passed
as first positional argument. If one is provided a default value will be
provided for all required fields of the pc file:
- `install_dir` is set to `pkgconfig` folder in the same location than the provided library.
- `description` is set to the project's name followed by the library's name.
- `name` is set to the library's name.

@ -0,0 +1,14 @@
## Improvements to pkgconfig module
A `StaticLibrary` or `SharedLibrary` object can optionally be passed
as first positional argument of the `generate()` method. If one is provided a
default value will be provided for all required fields of the pc file:
- `install_dir` is set to `pkgconfig` folder in the same location than the provided library.
- `description` is set to the project's name followed by the library's name.
- `name` is set to the library's name.
Generating a .pc file is now as simple as:
```
pkgconfig.generate(mylib)
```

@ -301,20 +301,34 @@ class PkgConfigModule(ExtensionModule):
'subdirs', 'requires', 'requires_private', 'libraries_private',
'install_dir', 'extra_cflags', 'variables', 'url', 'd_module_versions'})
def generate(self, state, args, kwargs):
if len(args) > 0:
raise mesonlib.MesonException('Pkgconfig_gen takes no positional arguments.')
default_version = state.project_version['version']
default_install_dir = None
default_description = None
default_name = None
mainlib = None
if len(args) == 1:
mainlib = getattr(args[0], 'held_object', args[0])
if not isinstance(mainlib, (build.StaticLibrary, build.SharedLibrary)):
raise mesonlib.MesonException('Pkgconfig_gen first positional argument must be a library object')
default_name = mainlib.name
default_description = state.project_name + ': ' + mainlib.name
install_dir = mainlib.get_custom_install_dir()[0]
if isinstance(install_dir, str):
default_install_dir = os.path.join(install_dir, 'pkgconfig')
elif len(args) > 1:
raise mesonlib.MesonException('Too many positional arguments passed to Pkgconfig_gen.')
subdirs = mesonlib.stringlistify(kwargs.get('subdirs', ['.']))
version = kwargs.get('version', None)
version = kwargs.get('version', default_version)
if not isinstance(version, str):
raise mesonlib.MesonException('Version must be specified.')
name = kwargs.get('name', None)
name = kwargs.get('name', default_name)
if not isinstance(name, str):
raise mesonlib.MesonException('Name not specified.')
filebase = kwargs.get('filebase', name)
if not isinstance(filebase, str):
raise mesonlib.MesonException('Filebase must be a string.')
description = kwargs.get('description', None)
description = kwargs.get('description', default_description)
if not isinstance(description, str):
raise mesonlib.MesonException('Description is not a string.')
url = kwargs.get('url', '')
@ -323,6 +337,8 @@ class PkgConfigModule(ExtensionModule):
conflicts = mesonlib.stringlistify(kwargs.get('conflicts', []))
deps = DependenciesHelper(filebase)
if mainlib:
deps.add_pub_libs(mainlib)
deps.add_pub_libs(kwargs.get('libraries', []))
deps.add_priv_libs(kwargs.get('libraries_private', []))
deps.add_pub_reqs(kwargs.get('requires', []))
@ -362,7 +378,7 @@ class PkgConfigModule(ExtensionModule):
variables = parse_variable_list(mesonlib.stringlistify(kwargs.get('variables', [])))
pcfile = filebase + '.pc'
pkgroot = kwargs.get('install_dir', None)
pkgroot = kwargs.get('install_dir', default_install_dir)
if pkgroot is None:
pkgroot = os.path.join(state.environment.coredata.get_builtin_option('libdir'), 'pkgconfig')
if not isinstance(pkgroot, str):

@ -1,4 +1,4 @@
project('pkgconfig-gen-dependencies', 'c')
project('pkgconfig-gen-dependencies', 'c', version: '1.0')
pkgg = import('pkgconfig')
@ -7,11 +7,7 @@ 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])
pkgg.generate(libraries : exposed_lib,
version : '1.0',
name : 'libexposed',
description : 'An exposed library in dependency test.'
)
pkgg.generate(exposed_lib)
# Declare a few different Dependency objects
pc_dep = dependency('libfoo', version : '>=1.0')

Loading…
Cancel
Save