aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2016-04-03 17:57:00 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2016-04-04 22:18:14 +0300
commit737fde65fa0ab25bffa69f77261f467fa3167cdf (patch)
tree52acd4bd1c29f6601627dfac5a7be3d0a9cafc2c
parent6841672eb5e9bbf354e19fb83c695eb476130fb6 (diff)
downloadmeson-737fde65fa0ab25bffa69f77261f467fa3167cdf.zip
meson-737fde65fa0ab25bffa69f77261f467fa3167cdf.tar.gz
meson-737fde65fa0ab25bffa69f77261f467fa3167cdf.tar.bz2
Bring back the old manual search to cc.find_library.
-rw-r--r--mesonbuild/compilers.py37
-rw-r--r--mesonbuild/interpreter.py4
2 files changed, 33 insertions, 8 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index 7bc59d8..880113d 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -285,6 +285,9 @@ class Compiler():
def find_library(self, libname, extra_dirs):
raise EnvironmentException('Language {} does not support library finding.'.format(self.language))
+ def get_library_dirs(self):
+ return []
+
class CCompiler(Compiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
super().__init__(exelist, version)
@@ -372,6 +375,16 @@ class CCompiler(Compiler):
def get_std_shared_lib_link_args(self):
return ['-shared']
+ def get_library_dirs(self):
+ output = subprocess.Popen(self.exelist + ['--print-search-dirs'], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
+ (stdo, _) = output.communicate()
+ stdo = stdo.decode('utf-8')
+ for line in stdo.split('\n'):
+ if line.startswith('libraries:'):
+ libstr = line.split('=', 1)[1]
+ return libstr.split(':')
+ return []
+
def can_compile(self, filename):
suffix = filename.split('.')[-1]
if suffix == 'c' or suffix == 'h':
@@ -661,16 +674,28 @@ void bar() {
return self.compiles(templ % (prefix, typename), extra_args)
def find_library(self, libname, extra_dirs):
+ # First try if we can just add the library as -l.
code = '''int main(int argc, char **argv) {
return 0;
}
'''
- 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
+ # Gcc + co seem to prefer builtin lib dirs to -L dirs.
+ # Only try to find std libs if no extra dirs specified.
+ if len(extra_dirs) == 0:
+ args = ['-l' + libname]
+ if self.links(code, extra_args=args):
+ return args
+ # Not found? Try to find the library file itself.
+ extra_dirs += self.get_library_dirs()
+ suffixes = ['so', 'dylib', 'lib', 'dll', 'a']
+ for d in extra_dirs:
+ for suffix in suffixes:
+ trial = os.path.join(d, 'lib' + libname + '.' + suffix)
+ if os.path.isfile(trial):
+ return trial
+ trial2 = os.path.join(d, libname + '.' + suffix)
+ if os.path.isfile(trial2):
+ return trial2
return None
def thread_flags(self):
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index ef6f3c1..90a0a13 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -761,13 +761,13 @@ class CompilerHolder(InterpreterObject):
required = kwargs.get('required', True)
if not isinstance(required, bool):
raise InterpreterException('required must be boolean.')
- search_dirs = kwargs.get('dirs', [])
+ search_dirs = mesonlib.stringlistify(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))
+ raise InterpreterException('Library {} not found'.format(libname))
lib = dependencies.ExternalLibrary(libname, linkargs)
return ExternalLibraryHolder(lib)