From 133df3b045c8b70b2750fac5961dc85cea2e19b2 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 30 Nov 2017 12:40:20 +0530 Subject: [PATCH] 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. --- mesonbuild/dependencies/base.py | 24 +++++++++++++++++------- mesonbuild/dependencies/misc.py | 2 +- mesonbuild/dependencies/ui.py | 6 ++++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 81b93c46c..7249b0165 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.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 diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index 41666a357..5bd9d9305 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -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() diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index dd045800f..bf74029c5 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -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: