Added find_library method and deprecated the standalone version. Closes #396.

pull/428/head
Jussi Pakkanen 9 years ago
parent 0d5eaa2721
commit 6b548a1c75
  1. 13
      mesonbuild/compilers.py
  2. 11
      mesonbuild/dependencies.py
  3. 20
      mesonbuild/interpreter.py
  4. 9
      test cases/linuxlike/2 external library/meson.build

@ -190,6 +190,9 @@ class Compiler():
def unix_compile_flags_to_native(self, args):
return args
def find_library(self, libname):
raise EnvironmentException('Language {} does not support library finding.'.format(self.language))
class CCompiler(Compiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
super().__init__(exelist, version)
@ -563,6 +566,16 @@ void bar() {
'''
return self.compiles(templ % (prefix, typename), extra_args)
def find_library(self, libname):
code = '''int main(int argc, char **argv) {
return 0;
}
'''
linkarg = '-l' + libname
if self.links(code, extra_args=[linkarg]):
return linkarg
return None
def thread_flags(self):
return ['-pthread']

@ -388,7 +388,14 @@ class ExternalLibrary(Dependency):
def __init__(self, name, fullpath=None, silent=False):
super().__init__()
self.name = name
self.fullpath = fullpath
# Rename fullpath to link_args once standalone find_library() gets removed.
if fullpath is not None:
if isinstance(fullpath, list):
self.fullpath = fullpath
else:
self.fullpath = [fullpath]
else:
self.fullpath = fullpath
if not silent:
if self.found():
mlog.log('Library', mlog.bold(name), 'found:', mlog.green('YES'),
@ -401,7 +408,7 @@ class ExternalLibrary(Dependency):
def get_link_args(self):
if self.found():
return [self.fullpath]
return self.fullpath
return []
class BoostDependency(Dependency):

@ -27,6 +27,8 @@ from functools import wraps
import importlib
find_lib_deprecation_printed = False
class InterpreterException(coredata.MesonException):
pass
@ -581,6 +583,7 @@ class CompilerHolder(InterpreterObject):
'alignment' : self.alignment_method,
'version' : self.version_method,
'cmd_array' : self.cmd_array_method,
'find_library': self.find_library_method,
})
def version_method(self, args, kwargs):
@ -750,6 +753,19 @@ class CompilerHolder(InterpreterObject):
mlog.log('Has header "%s":' % string, h)
return haz
def find_library_method(self, args, kwargs):
if len(args) != 1:
raise InterpreterException('find_library method takes one argument.')
libname = args[0]
if not isinstance(libname, str):
raise InterpreterException('Library name not a string.')
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)
return ExternalLibraryHolder(lib)
class ModuleState:
pass
@ -1526,6 +1542,10 @@ 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):

@ -1,6 +1,8 @@
project('external library', 'c')
zlib = find_library('z')
cc = meson.get_compiler('c')
zlib = find_library('z') # DEPRECATED
zlib2 = cc.find_library('z') # The modern way.
# Verify that link testing works.
linkcode = '''#include<zlib.h>
@ -16,13 +18,16 @@ int main(int argc, char **argv) {
return ptr == 0;
}
'''
cc = meson.get_compiler('c')
assert(cc.links(linkcode, args : '-lz', name : 'Test link against zlib'), 'Linking test failed.')
assert(not cc.links(nolinkcode, name : 'Failing link'), 'Linking succeeded when it should have failed.')
e = executable('zprog', 'prog.c', dependencies : zlib)
test('libtest', e)
e2 = executable('zprog_alt', 'prog.c', dependencies : zlib2)
test('libtest_alt', e2)
# Test that ext deps work via an internal dep.
intdep = declare_dependency(dependencies : zlib)
exe2 = executable('zprog2', 'prog.c', dependencies : intdep)

Loading…
Cancel
Save