Can query pkg-config variables from the system. Closes #726.

pull/920/head
Jussi Pakkanen 8 years ago
parent 44690763b0
commit e908910187
  1. 8
      mesonbuild/dependencies.py
  2. 28
      mesonbuild/interpreter.py
  3. 4
      mesonbuild/modules/gnome.py
  4. 4
      test cases/linuxlike/1 pkg-config/meson.build

@ -63,6 +63,9 @@ class Dependency():
def type_name(self):
return self.type_name
def get_pkgconfig_variable(self, variable_name):
raise MesonException('Tried to get a pkg-config variable from a non-pkgconfig dependency.')
class InternalDependency(Dependency):
def __init__(self, version, incdirs, compile_args, link_args, libraries, sources, ext_deps):
super().__init__('internal')
@ -190,7 +193,7 @@ class PkgConfigDependency(Dependency):
self.is_libtool = True
self.libs.append(lib)
def get_variable(self, variable_name):
def get_pkgconfig_variable(self, variable_name):
ret, out = self._call_pkgbin(['--variable=' + variable_name, self.name])
variable = ''
if ret != 0:
@ -199,8 +202,7 @@ class PkgConfigDependency(Dependency):
(self.type_string, self.name))
else:
variable = out.strip()
mlog.debug('return of subprocess : %s' % variable)
mlog.debug('Got pkgconfig variable %s : %s' % (variable_name, variable))
return variable
def get_modversion(self):

@ -284,7 +284,10 @@ class DependencyHolder(InterpreterObject):
self.held_object = dep
self.methods.update({'found' : self.found_method,
'type_name': self.type_name_method,
'version': self.version_method})
'version': self.version_method,
'version': self.version_method,
'get_pkgconfig_variable': self.pkgconfig_method,
})
def type_name_method(self, args, kwargs):
return self.held_object.type_name
@ -298,6 +301,29 @@ class DependencyHolder(InterpreterObject):
def version_method(self, args, kwargs):
return self.held_object.get_version()
def pkgconfig_method(self, args, kwargs):
if not isinstance(args, list):
args = [args]
if len(args) != 1:
raise InterpreterException('get_pkgconfig_variable takes exactly one argument.')
varname = args[0]
if not isinstance(varname, str):
raise InterpreterException('Variable name must be a string.')
return self.held_object.get_pkgconfig_variable(varname)
class InternalDependencyHolder(InterpreterObject):
def __init__(self, dep):
InterpreterObject.__init__(self)
self.held_object = dep
self.methods.update({'found' : self.found_method,
'version': self.version_method,
})
def found_method(self, args, kwargs):
return True
def version_method(self, args, kwargs):
return self.held_object.get_version()
class ExternalProgramHolder(InterpreterObject):
def __init__(self, ep):

@ -266,7 +266,7 @@ class GnomeModule:
ldflags.update([lib])
if isinstance(dep, dependencies.PkgConfigDependency):
girdir = dep.get_variable("girdir")
girdir = dep.get_pkgconfig_variable("girdir")
if girdir:
gi_includes.update([girdir])
elif isinstance(dep, (build.StaticLibrary, build.SharedLibrary)):
@ -421,7 +421,7 @@ class GnomeModule:
)
]
elif isinstance(dep, dependencies.PkgConfigDependency):
girdir = dep.get_variable("girdir")
girdir = dep.get_pkgconfig_variable("girdir")
if girdir:
typelib_cmd += ["--includedir=%s" % (girdir, )]

@ -9,6 +9,10 @@ assert(dep.version().version_compare('>=1.2.8'), 'Pkg-config version numbers exp
test('zlibtest', exe)
zprefix = dep.get_pkgconfig_variable('prefix') # Always set but we can't be sure what the value is.
# pkg-config returns empty string for not defined variables
assert(dep.get_pkgconfig_variable('nonexisting') == '', 'Value of unknown variable is not empty.')
# Test that dependencies of dependencies work.
dep2 = declare_dependency(dependencies : dep)
exe2 = executable('zlibprog2', 'prog.c', dependencies : dep2)

Loading…
Cancel
Save