diff options
author | Dudemanguy <random342@airmail.cc> | 2022-01-10 19:02:12 -0600 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2022-05-03 23:03:56 -0400 |
commit | 557680f7d6b2a2e7c3d0f04fb0d6529ac7a6d475 (patch) | |
tree | dedf300cdb4b39a83e7bfa9eb7720f7fb43f0352 /mesonbuild/dependencies | |
parent | 8b3a54e5085933b78a8509103a76bed7ca8cdde4 (diff) | |
download | meson-557680f7d6b2a2e7c3d0f04fb0d6529ac7a6d475.zip meson-557680f7d6b2a2e7c3d0f04fb0d6529ac7a6d475.tar.gz meson-557680f7d6b2a2e7c3d0f04fb0d6529ac7a6d475.tar.bz2 |
add prefer_static built-in option
By default, meson will try to look for shared libraries first before
static ones. In the meson.build itself, one can use the static keyword
to control if a static library will be tried first but there's no simple
way for an end user performing a build to switch back and forth at will.
Let's cover this usecase by adding an option that allows a user to
specify if they want dependency lookups to try static or shared
libraries first. The writer of the meson.build can manually specify the
static keyword where appropriate which will override the value of this
option.
Diffstat (limited to 'mesonbuild/dependencies')
-rw-r--r-- | mesonbuild/dependencies/__init__.py | 8 | ||||
-rw-r--r-- | mesonbuild/dependencies/base.py | 4 | ||||
-rw-r--r-- | mesonbuild/dependencies/misc.py | 2 | ||||
-rw-r--r-- | mesonbuild/dependencies/scalapack.py | 4 |
4 files changed, 11 insertions, 7 deletions
diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py index cdadd56..bbf31ad 100644 --- a/mesonbuild/dependencies/__init__.py +++ b/mesonbuild/dependencies/__init__.py @@ -142,8 +142,8 @@ There are a couple of things about this that still aren't ideal. For one, we don't want to be reading random environment variables at this point. Those should actually be added to `envconfig.Properties` and read in `environment.Environment._set_default_properties_from_env` (see how -`BOOST_ROOT` is handled). We can also handle the `static` keyword. So -now that becomes: +`BOOST_ROOT` is handled). We can also handle the `static` keyword and the +`prefer_static` built-in option. So now that becomes: ```python class FooSystemDependency(ExternalDependency): @@ -156,7 +156,9 @@ class FooSystemDependency(ExternalDependency): self.is_found = False return - static = Mesonlib.LibType.STATIC if kwargs.get('static', False) else Mesonlib.LibType.SHARED + get_option = environment.coredata.get_option + static_opt = kwargs.get('static', get_option(Mesonlib.OptionKey('prefer_static')) + static = Mesonlib.LibType.STATIC if static_opt else Mesonlib.LibType.SHARED lib = self.clib_compiler.find_library( 'foo', environment, [os.path.join(root, 'lib')], libtype=static) if lib is None: diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 97a19be..8e4d556 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -25,7 +25,7 @@ from enum import Enum from .. import mlog, mesonlib from ..compilers import clib_langs -from ..mesonlib import LibType, MachineChoice, MesonException, HoldableObject +from ..mesonlib import LibType, MachineChoice, MesonException, HoldableObject, OptionKey from ..mesonlib import version_compare_many #from ..interpreterbase import FeatureDeprecated, FeatureNew @@ -338,7 +338,7 @@ class ExternalDependency(Dependency, HasNativeKwarg): self.version_reqs = [self.version_reqs] self.required = kwargs.get('required', True) self.silent = kwargs.get('silent', False) - self.static = kwargs.get('static', False) + self.static = kwargs.get('static', self.env.coredata.get_option(OptionKey('prefer_static'))) self.libtype = LibType.STATIC if self.static else LibType.PREFER_SHARED if not isinstance(self.static, bool): raise DependencyException('Static keyword must be boolean') diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index 5292d02..2edb0c7 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -612,7 +612,7 @@ def shaderc_factory(env: 'Environment', shared_libs = ['shaderc'] static_libs = ['shaderc_combined', 'shaderc_static'] - if kwargs.get('static', False): + if kwargs.get('static', env.coredata.get_option(mesonlib.OptionKey('prefer_static'))): c = [functools.partial(PkgConfigDependency, name, env, kwargs) for name in static_libs + shared_libs] else: diff --git a/mesonbuild/dependencies/scalapack.py b/mesonbuild/dependencies/scalapack.py index 707e698..656978d 100644 --- a/mesonbuild/dependencies/scalapack.py +++ b/mesonbuild/dependencies/scalapack.py @@ -17,6 +17,7 @@ import functools import os import typing as T +from ..mesonlib import OptionKey from .base import DependencyMethods from .base import DependencyException from .cmake import CMakeDependency @@ -35,7 +36,8 @@ def scalapack_factory(env: 'Environment', for_machine: 'MachineChoice', candidates: T.List['DependencyGenerator'] = [] if DependencyMethods.PKGCONFIG in methods: - mkl = 'mkl-static-lp64-iomp' if kwargs.get('static', False) else 'mkl-dynamic-lp64-iomp' + static_opt = kwargs.get('static', env.coredata.get_option(OptionKey('prefer_static'))) + mkl = 'mkl-static-lp64-iomp' if static_opt else 'mkl-dynamic-lp64-iomp' candidates.append(functools.partial( MKLPkgConfigDependency, mkl, env, kwargs)) |