aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/compilers.py16
-rw-r--r--mesonbuild/dependencies.py19
-rw-r--r--mesonbuild/interpreter.py47
3 files changed, 29 insertions, 53 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index f3ddf8d..22978f5 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -190,7 +190,7 @@ class Compiler():
def unix_compile_flags_to_native(self, args):
return args
- def find_library(self, libname):
+ def find_library(self, libname, extra_dirs):
raise EnvironmentException('Language {} does not support library finding.'.format(self.language))
class CCompiler(Compiler):
@@ -298,6 +298,9 @@ class CCompiler(Compiler):
def get_pch_name(self, header_name):
return os.path.split(header_name)[-1] + '.' + self.get_pch_suffix()
+ def get_linker_search_args(self, dirname):
+ return ['-L'+dirname]
+
def sanity_check(self, work_dir):
mlog.debug('Sanity testing C compiler:', ' '.join(self.exelist))
mlog.debug('Is cross compiler: %s.' % str(self.is_cross))
@@ -566,14 +569,17 @@ void bar() {
'''
return self.compiles(templ % (prefix, typename), extra_args)
- def find_library(self, libname):
+ def find_library(self, libname, extra_dirs):
code = '''int main(int argc, char **argv) {
return 0;
}
'''
- linkarg = '-l' + libname
- if self.links(code, extra_args=[linkarg]):
- return linkarg
+ args = []
+ for i in extra_dirs:
+ args += self.get_linker_search_args(i)
+ args.append('-l' + libname)
+ if self.links(code, extra_args=args):
+ return args
return None
def thread_flags(self):
diff --git a/mesonbuild/dependencies.py b/mesonbuild/dependencies.py
index ee2dd62..b9f5c89 100644
--- a/mesonbuild/dependencies.py
+++ b/mesonbuild/dependencies.py
@@ -385,30 +385,29 @@ class ExternalProgram():
return self.name
class ExternalLibrary(Dependency):
- def __init__(self, name, fullpath=None, silent=False):
+ def __init__(self, name, link_args=None, silent=False):
super().__init__()
self.name = name
# Rename fullpath to link_args once standalone find_library() gets removed.
- if fullpath is not None:
- if isinstance(fullpath, list):
- self.fullpath = fullpath
+ if link_args is not None:
+ if isinstance(link_args, list):
+ self.link_args = link_args
else:
- self.fullpath = [fullpath]
+ self.link_args = [link_args]
else:
- self.fullpath = fullpath
+ self.link_args = link_args
if not silent:
if self.found():
- mlog.log('Library', mlog.bold(name), 'found:', mlog.green('YES'),
- '(%s)' % self.fullpath)
+ mlog.log('Library', mlog.bold(name), 'found:', mlog.green('YES'))
else:
mlog.log('Library', mlog.bold(name), 'found:', mlog.red('NO'))
def found(self):
- return self.fullpath is not None
+ return self.link_args is not None
def get_link_args(self):
if self.found():
- return self.fullpath
+ return self.link_args
return []
class BoostDependency(Dependency):
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 2ade18a..35cbc3e 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -27,8 +27,6 @@ from functools import wraps
import importlib
-find_lib_deprecation_printed = False
-
class InterpreterException(coredata.MesonException):
pass
@@ -762,8 +760,14 @@ class CompilerHolder(InterpreterObject):
required = kwargs.get('required', True)
if not isinstance(required, bool):
raise InterpreterException('required must be boolean.')
- linkarg = self.compiler.find_library(libname)
- lib = dependencies.ExternalLibrary(libname, linkarg)
+ search_dirs = kwargs.get('dirs', [])
+ for i in search_dirs:
+ if not os.path.isabs(i):
+ raise InvalidCode('Search directory %s is not an absolute path.' % i)
+ linkargs = self.compiler.find_library(libname, search_dirs)
+ if required and linkargs is None:
+ raise InterpreterException('Library %s not found'.format(libname))
+ lib = dependencies.ExternalLibrary(libname, linkargs)
return ExternalLibraryHolder(lib)
class ModuleState:
@@ -1542,40 +1546,7 @@ class Interpreter():
return progobj
def func_find_library(self, node, args, kwargs):
- global find_lib_deprecation_printed
- if not find_lib_deprecation_printed:
- find_lib_deprecation_printed = True
- mlog.log(mlog.red('DEPRECATION:'), 'find_library() is deprecated, use the corresponding method in compiler object instead.')
- self.validate_arguments(args, 1, [str])
- required = kwargs.get('required', True)
- if not isinstance(required, bool):
- raise InvalidArguments('"required" argument must be a boolean.')
- libname = args[0]
- # We do not cache found libraries because they can come
- # and go between invocations wildly. As an example we
- # may find the 64 bit version but need instead the 32 bit
- # one that is not installed. If we cache the found path
- # then we will never found the new one if it get installed.
- # This causes a bit of a slowdown as libraries are rechecked
- # on every regen, but since it is a fast operation it should be
- # ok.
- if 'dirs' in kwargs:
- search_dirs = kwargs['dirs']
- if not isinstance(search_dirs, list):
- search_dirs = [search_dirs]
- for i in search_dirs:
- if not isinstance(i, str):
- raise InvalidCode('Directory entry is not a string.')
- if not os.path.isabs(i):
- raise InvalidCode('Search directory %s is not an absolute path.' % i)
- else:
- search_dirs = None
- result = self.environment.find_library(libname, search_dirs)
- extlib = dependencies.ExternalLibrary(libname, result)
- libobj = ExternalLibraryHolder(extlib)
- if required and not libobj.found():
- raise InvalidArguments('External library "%s" not found.' % libname)
- return libobj
+ mlog.log(mlog.red('DEPRECATION:'), 'find_library() is removed, use the corresponding method in compiler object instead.')
def func_dependency(self, node, args, kwargs):
self.validate_arguments(args, 1, [str])