diff options
author | Niklas Claesson <nicke.claesson@gmail.com> | 2019-03-11 19:56:52 +0100 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-03-11 20:56:52 +0200 |
commit | dd2c44cdf6f8ed8a969d0666cafb08aaf78a919d (patch) | |
tree | a6057cb899b43c55a820291c93dd62d61e2e0a69 /mesonbuild/compilers | |
parent | faf3581df6af59c04e66378da129bb2039beab8a (diff) | |
download | meson-dd2c44cdf6f8ed8a969d0666cafb08aaf78a919d.zip meson-dd2c44cdf6f8ed8a969d0666cafb08aaf78a919d.tar.gz meson-dd2c44cdf6f8ed8a969d0666cafb08aaf78a919d.tar.bz2 |
Add static as keyword to find_library
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r-- | mesonbuild/compilers/c.py | 35 | ||||
-rw-r--r-- | mesonbuild/compilers/fortran.py | 5 | ||||
-rw-r--r-- | mesonbuild/compilers/vala.py | 2 |
3 files changed, 23 insertions, 19 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 31d6464..d4626d6 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -936,18 +936,17 @@ class CCompiler(Compiler): else: # Linux/BSDs shlibext = ['so'] - patterns = [] # Search priority - if libtype in ('default', 'shared-static'): - patterns += self._get_patterns(env, prefixes, shlibext, True) - patterns += self._get_patterns(env, prefixes, stlibext, False) + if libtype == 'shared-static': + patterns = self._get_patterns(env, prefixes, shlibext, True) + patterns.extend([x for x in self._get_patterns(env, prefixes, stlibext, False) if x not in patterns]) elif libtype == 'static-shared': - patterns += self._get_patterns(env, prefixes, stlibext, False) - patterns += self._get_patterns(env, prefixes, shlibext, True) + patterns = self._get_patterns(env, prefixes, stlibext, False) + patterns.extend([x for x in self._get_patterns(env, prefixes, shlibext, True) if x not in patterns]) elif libtype == 'shared': - patterns += self._get_patterns(env, prefixes, shlibext, True) + patterns = self._get_patterns(env, prefixes, shlibext, True) elif libtype == 'static': - patterns += self._get_patterns(env, prefixes, stlibext, False) + patterns = self._get_patterns(env, prefixes, stlibext, False) else: raise AssertionError('BUG: unknown libtype {!r}'.format(libtype)) return tuple(patterns) @@ -975,11 +974,11 @@ class CCompiler(Compiler): if '*' in pattern: # NOTE: globbing matches directories and broken symlinks # so we have to do an isfile test on it later - return cls._sort_shlibs_openbsd(glob.glob(str(f))) - return [f.as_posix()] + return [Path(x) for x in cls._sort_shlibs_openbsd(glob.glob(str(f)))] + return [f] @staticmethod - def _get_file_from_list(env, files: List[str]) -> str: + def _get_file_from_list(env, files: List[str]) -> Path: ''' We just check whether the library exists. We can't do a link check because the library might have unresolved symbols that require other @@ -987,13 +986,14 @@ class CCompiler(Compiler): architecture. ''' # If not building on macOS for Darwin, do a simple file check + files = [Path(f) for f in files] if not env.machines.host.is_darwin() or not env.machines.build.is_darwin(): for f in files: - if os.path.isfile(f): + if f.is_file(): return f # Run `lipo` and check if the library supports the arch we want for f in files: - if not os.path.isfile(f): + if not f.is_file(): continue archs = darwin_get_object_archs(f) if archs and env.machines.host.cpu_family in archs: @@ -1014,7 +1014,10 @@ class CCompiler(Compiler): # First try if we can just add the library as -l. # Gcc + co seem to prefer builtin lib dirs to -L dirs. # Only try to find std libs if no extra dirs specified. - if not extra_dirs or libname in self.internal_libs: + # The built-in search procedure will always favour .so and then always + # search for .a. This is only allowed if libtype is 'shared-static' + if ((not extra_dirs and libtype == 'shared-static') or + libname in self.internal_libs): args = ['-l' + libname] largs = self.linker_to_compiler_args(self.get_allow_undefined_link_args()) if self.links(code, env, extra_args=(args + largs)): @@ -1044,7 +1047,7 @@ class CCompiler(Compiler): trial = self._get_file_from_list(env, trial) if not trial: continue - return [trial] + return [trial.as_posix()] return None def find_library_impl(self, libname, env, extra_dirs, code, libtype): @@ -1063,7 +1066,7 @@ class CCompiler(Compiler): return None return value[:] - def find_library(self, libname, env, extra_dirs, libtype='default'): + def find_library(self, libname, env, extra_dirs, libtype='shared-static'): code = 'int main(int argc, char **argv) { return 0; }' return self.find_library_impl(libname, env, extra_dirs, code, libtype) diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py index 6c260b6..738a5c6 100644 --- a/mesonbuild/compilers/fortran.py +++ b/mesonbuild/compilers/fortran.py @@ -13,6 +13,7 @@ # limitations under the License. from typing import List import subprocess, os +from pathlib import Path from .c import CCompiler from .compilers import ( @@ -240,7 +241,7 @@ class FortranCompiler(Compiler): def find_library_impl(self, *args): return CCompiler.find_library_impl(self, *args) - def find_library(self, libname, env, extra_dirs, libtype='default'): + def find_library(self, libname, env, extra_dirs, libtype='shared-static'): code = '''program main call exit(0) end program main''' @@ -272,7 +273,7 @@ class FortranCompiler(Compiler): return CCompiler._get_trials_from_pattern(pattern, directory, libname) @staticmethod - def _get_file_from_list(env, files: List[str]) -> str: + def _get_file_from_list(env, files: List[str]) -> Path: return CCompiler._get_file_from_list(env, files) class GnuFortranCompiler(GnuCompiler, FortranCompiler): diff --git a/mesonbuild/compilers/vala.py b/mesonbuild/compilers/vala.py index 1ee46fe..b463f0d 100644 --- a/mesonbuild/compilers/vala.py +++ b/mesonbuild/compilers/vala.py @@ -98,7 +98,7 @@ class ValaCompiler(Compiler): return ['--debug'] return [] - def find_library(self, libname, env, extra_dirs): + def find_library(self, libname, env, extra_dirs, *args): if extra_dirs and isinstance(extra_dirs, str): extra_dirs = [extra_dirs] # Valac always looks in the default vapi dir, so only search there if |