Add dependency type for Valgrind

Valgrind is a bit of a strange beast, in general use one isn't supposed
to link against valgrinds libs, they're non-PIC static libs, instead,
including the headers does magic to make valgrind work.

This patch implements a simple ValgrindDependency class subclassed from
PkgConfigDependency, that overwrites (effectively) only the
get_link_args method to always return an empty list. This solution may
seem strange, but I think that it follows the principle of least
surprise, and simplifies the most common use case for valgrind.

Essentially without this every valgrind consumer would be forced to
implement the following code to have a usable valgrind dependency
object:

_dep = dependency('valgrind', required : false)
if _dep.found()
  valgrind_dep = declare_dependency(
    compile_args : _dep.get_pkgconfig_variable('Cflags')
  )
else
  valgrind_dep = []
endif

While the above is workable, it's surprising behavior and the above code
snippet becomes boilerplate that everyone needs to copy into their meson
files.

Fixes #826
pull/1541/head
Dylan Baker 8 years ago
parent fa10703124
commit 7aa28456df
  1. 1
      authors.txt
  2. 9
      mesonbuild/dependencies.py

@ -72,3 +72,4 @@ Aaron Small
Joe Baldino
Peter Harris
Roger Boerdijk
Dylan Baker

@ -1483,6 +1483,14 @@ class Python3Dependency(Dependency):
def get_version(self):
return self.version
class ValgrindDependency(PkgConfigDependency):
def __init__(self, environment, kwargs):
PkgConfigDependency.__init__(self, 'valgrind', environment, kwargs)
def get_link_args(self):
return []
def get_dep_identifier(name, kwargs):
elements = [name]
modlist = kwargs.get('modules', [])
@ -1544,4 +1552,5 @@ packages = {'boost': BoostDependency,
'gl': GLDependency,
'threads': ThreadDependency,
'python3': Python3Dependency,
'valgrind': ValgrindDependency,
}

Loading…
Cancel
Save