aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/backend/ninjabackend.py6
-rw-r--r--mesonbuild/compilers/c.py25
-rw-r--r--mesonbuild/compilers/fortran.py4
-rw-r--r--mesonbuild/dependencies/base.py4
-rw-r--r--mesonbuild/interpreter.py4
-rw-r--r--mesonbuild/mesonlib.py10
6 files changed, 31 insertions, 22 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 21c6c08..6446406 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -31,7 +31,7 @@ from .. import dependencies
from .. import compilers
from ..compilers import CompilerArgs, CCompiler, VisualStudioCCompiler, FortranCompiler
from ..linkers import ArLinker
-from ..mesonlib import File, MachineChoice, MesonException, OrderedSet
+from ..mesonlib import File, MachineChoice, MesonException, OrderedSet, LibType
from ..mesonlib import get_compiler_for_source, has_path_sep
from .backends import CleanTrees
from ..build import InvalidArguments
@@ -2401,8 +2401,8 @@ rule FORTRAN_DEP_HACK%s
# TODO The get_library_naming requirement currently excludes link targets that use d or fortran as their main linker
if hasattr(linker, 'get_library_naming'):
search_dirs = tuple(search_dirs) + linker.get_library_dirs(self.environment)
- static_patterns = linker.get_library_naming(self.environment, 'static', strict=True)
- shared_patterns = linker.get_library_naming(self.environment, 'shared', strict=True)
+ static_patterns = linker.get_library_naming(self.environment, LibType.STATIC, strict=True)
+ shared_patterns = linker.get_library_naming(self.environment, LibType.SHARED, strict=True)
for libname in libs:
# be conservative and record most likely shared and static resolution, because we don't know exactly
# which one the linker will prefer
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 6ab14d2..cac27ad 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -27,7 +27,7 @@ from . import compilers
from ..mesonlib import (
EnvironmentException, MachineChoice, MesonException, Popen_safe, listify,
version_compare, for_windows, for_darwin, for_cygwin, for_haiku,
- for_openbsd, darwin_get_object_archs
+ for_openbsd, darwin_get_object_archs, LibType
)
from .c_function_attributes import C_FUNC_ATTRIBUTES
@@ -905,7 +905,7 @@ class CCompiler(Compiler):
patterns.append(p + '{}.so.[0-9]*.[0-9]*')
return patterns
- def get_library_naming(self, env, libtype, strict=False):
+ def get_library_naming(self, env, libtype: LibType, strict=False):
'''
Get library prefixes and suffixes for the target platform ordered by
priority
@@ -938,18 +938,17 @@ class CCompiler(Compiler):
# Linux/BSDs
shlibext = ['so']
# Search priority
- if libtype == 'shared-static':
+ if libtype is LibType.PREFER_SHARED:
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':
+ elif libtype is LibType.PREFER_STATIC:
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':
+ elif libtype is LibType.SHARED:
patterns = self._get_patterns(env, prefixes, shlibext, True)
- elif libtype == 'static':
- patterns = self._get_patterns(env, prefixes, stlibext, False)
else:
- raise AssertionError('BUG: unknown libtype {!r}'.format(libtype))
+ assert libtype is LibType.STATIC
+ patterns = self._get_patterns(env, prefixes, stlibext, False)
return tuple(patterns)
@staticmethod
@@ -1011,13 +1010,13 @@ class CCompiler(Compiler):
'''
return self.sizeof('void *', '', env) == 8
- def find_library_real(self, libname, env, extra_dirs, code, libtype):
+ def find_library_real(self, libname, env, extra_dirs, code, libtype: LibType):
# 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.
# 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
+ # search for .a. This is only allowed if libtype is LibType.PREFER_SHARED
+ if ((not extra_dirs and libtype is LibType.PREFER_SHARED) or
libname in self.internal_libs):
args = ['-l' + libname]
largs = self.linker_to_compiler_args(self.get_allow_undefined_link_args())
@@ -1051,7 +1050,7 @@ class CCompiler(Compiler):
return [trial.as_posix()]
return None
- def find_library_impl(self, libname, env, extra_dirs, code, libtype):
+ def find_library_impl(self, libname, env, extra_dirs, code, libtype: LibType):
# These libraries are either built-in or invalid
if libname in self.ignore_libs:
return []
@@ -1067,7 +1066,7 @@ class CCompiler(Compiler):
return None
return value[:]
- def find_library(self, libname, env, extra_dirs, libtype='shared-static'):
+ def find_library(self, libname, env, extra_dirs, libtype: LibType = LibType.PREFER_SHARED):
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 738a5c6..15234ee 100644
--- a/mesonbuild/compilers/fortran.py
+++ b/mesonbuild/compilers/fortran.py
@@ -31,7 +31,7 @@ from .compilers import (
PGICompiler
)
-from mesonbuild.mesonlib import EnvironmentException, is_osx
+from mesonbuild.mesonlib import EnvironmentException, is_osx, LibType
class FortranCompiler(Compiler):
@@ -241,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='shared-static'):
+ def find_library(self, libname, env, extra_dirs, libtype: LibType = LibType.PREFER_SHARED):
code = '''program main
call exit(0)
end program main'''
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 2ba150b..995a980 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -36,7 +36,7 @@ from ..compilers import clib_langs
from ..environment import BinaryTable, Environment, MachineInfo
from ..mesonlib import MachineChoice, MesonException, OrderedSet, PerMachine
from ..mesonlib import Popen_safe, version_compare_many, version_compare, listify
-from ..mesonlib import Version
+from ..mesonlib import Version, LibType
# These must be defined in this file to avoid cyclical references.
packages = {}
@@ -703,7 +703,7 @@ class PkgConfigDependency(ExternalDependency):
libs_found = OrderedSet()
# Track not-found libraries to know whether to add library paths
libs_notfound = []
- libtype = 'static' if self.static else 'shared-static'
+ libtype = LibType.STATIC if self.static else LibType.PREFER_SHARED
# Generate link arguments for this library
link_args = []
for lib in full_args:
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 3c3cfae..5d8d071 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1493,11 +1493,11 @@ class CompilerHolder(InterpreterObject):
for i in search_dirs:
if not os.path.isabs(i):
raise InvalidCode('Search directory %s is not an absolute path.' % i)
- libtype = 'shared-static'
+ libtype = mesonlib.LibType.PREFER_SHARED
if 'static' in kwargs:
if not isinstance(kwargs['static'], bool):
raise InterpreterException('static must be a boolean')
- libtype = 'static' if kwargs['static'] else 'shared'
+ libtype = mesonlib.LibType.STATIC if kwargs['static'] else mesonlib.LibType.SHARED
linkargs = self.compiler.find_library(libname, self.environment, search_dirs, libtype)
if required and not linkargs:
raise InterpreterException(
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 0afc21b..25e15e4 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -1274,3 +1274,13 @@ def relpath(path, start):
return os.path.relpath(path, start)
except ValueError:
return path
+
+
+class LibType(Enum):
+
+ """Enumeration for library types."""
+
+ SHARED = 0
+ STATIC = 1
+ PREFER_SHARED = 2
+ PREFER_STATIC = 3