dependencies: Pass language to PkgConfigDependency

Also try harder to find a compiler that dependencies can use.

This means that in C++-only projects we will use the C++ compiler for
compiler checks, which can be important.
pull/2703/head
Nirbheek Chauhan 7 years ago
parent b2feae9833
commit 133df3b045
  1. 24
      mesonbuild/dependencies/base.py
  2. 2
      mesonbuild/dependencies/misc.py
  3. 6
      mesonbuild/dependencies/ui.py

@ -157,9 +157,6 @@ class ExternalDependency(Dependency):
self.name = type_name # default
self.is_found = False
self.language = language
if language and language not in self.env.coredata.compilers:
m = self.name.capitalize() + ' requires a {} compiler'
raise DependencyException(m.format(language.capitalize()))
self.version_reqs = kwargs.get('version', None)
self.required = kwargs.get('required', True)
self.silent = kwargs.get('silent', False)
@ -177,7 +174,20 @@ class ExternalDependency(Dependency):
compilers = self.env.coredata.cross_compilers
else:
compilers = self.env.coredata.compilers
self.compiler = compilers.get(self.language or 'c', None)
# Set the compiler for this dependency if a language is specified,
# else try to pick something that looks usable.
if self.language:
if self.language not in compilers:
m = self.name.capitalize() + ' requires a {} compiler'
raise DependencyException(m.format(self.language.capitalize()))
self.compiler = compilers[self.language]
else:
# Try to find a compiler that this dependency can use for compiler
# checks. It's ok if we don't find one.
for lang in ('c', 'cpp', 'objc', 'objcpp', 'fortran', 'd'):
self.compiler = compilers.get(lang, None)
if self.compiler:
break
def get_compiler(self):
return self.compiler
@ -309,8 +319,8 @@ class PkgConfigDependency(ExternalDependency):
# multiple times in the same Meson invocation.
class_pkgbin = None
def __init__(self, name, environment, kwargs):
super().__init__('pkgconfig', environment, None, kwargs)
def __init__(self, name, environment, kwargs, language=None):
super().__init__('pkgconfig', environment, language, kwargs)
self.name = name
self.is_libtool = False
# Store a copy of the pkg-config path on the object itself so it is
@ -428,7 +438,7 @@ class PkgConfigDependency(ExternalDependency):
# MSVC cannot handle MinGW-esque /c/foo paths, convert them to C:/foo.
# We cannot resolve other paths starting with / like /home/foo so leave
# them as-is so the user gets an error/warning from the compiler/linker.
if self.compiler.id == 'msvc':
if self.compiler and self.compiler.id == 'msvc':
# Library search path
if lib.startswith('-L/'):
pargs = PurePath(lib[2:]).parts

@ -408,7 +408,7 @@ class MPIDependency(ExternalDependency):
for pkg in pkgconfig_files:
try:
pkgdep = PkgConfigDependency(pkg, environment, kwargs)
pkgdep = PkgConfigDependency(pkg, environment, kwargs, language=self.language)
if pkgdep.found():
self.compile_args = pkgdep.get_compile_args()
self.link_args = pkgdep.get_link_args()

@ -218,7 +218,8 @@ class QtBaseDependency(ExternalDependency):
kwargs['required'] = False
modules = OrderedDict()
for module in mods:
modules[module] = PkgConfigDependency(self.qtpkgname + module, self.env, kwargs)
modules[module] = PkgConfigDependency(self.qtpkgname + module, self.env,
kwargs, language=self.language)
for m in modules.values():
if not m.found():
self.is_found = False
@ -232,7 +233,8 @@ class QtBaseDependency(ExternalDependency):
core = modules['Core']
else:
corekwargs = {'required': 'false', 'silent': 'true'}
core = PkgConfigDependency(self.qtpkgname + 'Core', self.env, corekwargs)
core = PkgConfigDependency(self.qtpkgname + 'Core', self.env, corekwargs,
language=self.language)
# Used by self.compilers_detect()
self.bindir = self.get_pkgconfig_host_bins(core)
if not self.bindir:

Loading…
Cancel
Save