aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-11-15 22:51:34 +0200
committerGitHub <noreply@github.com>2017-11-15 22:51:34 +0200
commite51da1a34d3ac2ed23451e05c971720c20aaa064 (patch)
tree4f929542408830518055b5258c3059931ade4d22 /mesonbuild/compilers
parentb9ef15a7193e55bb72216135066666b7bacbfaf0 (diff)
parentda654dd2b9ebb91a2202e7a841c4ae1c71ebf8ea (diff)
downloadmeson-e51da1a34d3ac2ed23451e05c971720c20aaa064.zip
meson-e51da1a34d3ac2ed23451e05c971720c20aaa064.tar.gz
meson-e51da1a34d3ac2ed23451e05c971720c20aaa064.tar.bz2
Merge pull request #2611 from mesonbuild/nirbheek/pkgconfig-msvc-static
Several fixes to pkg-config dependencies and the pkg-config module (try 3)
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/c.py59
1 files changed, 49 insertions, 10 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 3f9ba5c..9e85712 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -17,6 +17,7 @@ import subprocess, os.path, tempfile
from .. import mlog
from .. import coredata
from ..mesonlib import EnvironmentException, version_compare, Popen_safe, listify
+from ..mesonlib import for_windows, for_darwin, for_cygwin
from .compilers import (
GCC_MINGW,
@@ -710,7 +711,45 @@ class CCompiler(Compiler):
return False
raise RuntimeError('BUG: {!r} check failed unexpectedly'.format(n))
- def find_library(self, libname, env, extra_dirs):
+ def get_library_naming(self, env, libtype):
+ '''
+ Get library prefixes and suffixes for the target platform ordered by
+ priority
+ '''
+ stlibext = ['a']
+ # We've always allowed libname to be both `foo` and `libfoo`,
+ # and now people depend on it
+ prefixes = ['lib', '']
+ # Library suffixes and prefixes
+ if for_darwin(env.is_cross_build(), env):
+ shlibext = ['dylib']
+ elif for_windows(env.is_cross_build(), env):
+ if self.id == 'msvc':
+ shlibext = ['lib']
+ else:
+ shlibext = ['dll', 'dll.a', 'lib']
+ # Yep, static libraries can also be foo.lib
+ stlibext += ['lib']
+ elif for_cygwin(env.is_cross_build(), env):
+ shlibext = ['dll', 'dll.a']
+ prefixes = ['cyg'] + prefixes
+ else:
+ # Linux/BSDs
+ shlibext = ['so']
+ # Search priority
+ if libtype in ('default', 'shared-static'):
+ suffixes = shlibext + stlibext
+ elif libtype == 'static-shared':
+ suffixes = stlibext + shlibext
+ elif libtype == 'shared':
+ suffixes = shlibext
+ elif libtype == 'static':
+ suffixes = stlibext
+ else:
+ raise AssertionError('BUG: unknown libtype {!r}'.format(libtype))
+ return prefixes, suffixes
+
+ def find_library(self, libname, env, extra_dirs, libtype='default'):
# These libraries are either built-in or invalid
if libname in self.ignore_libs:
return []
@@ -720,21 +759,21 @@ class CCompiler(Compiler):
extra_dirs = [extra_dirs]
# 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:
+ if not extra_dirs and libtype == 'default':
args = ['-l' + libname]
if self.links(code, env, extra_args=args):
return args
- # Not found? Try to find the library file itself.
+ # Not found or we want to use a specific libtype? Try to find the
+ # library file itself.
extra_dirs += self.get_library_dirs()
- suffixes = ['so', 'dylib', 'lib', 'dll', 'a']
+ prefixes, suffixes = self.get_library_naming(env, libtype)
+ # Triply-nested loop!
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]
+ for prefix in prefixes:
+ trial = os.path.join(d, prefix + libname + '.' + suffix)
+ if os.path.isfile(trial):
+ return [trial]
return None
def thread_flags(self):