add default_both_libraries core option

pull/13609/head
Charles Brunet 12 months ago committed by Dylan Baker
parent 7b3169f464
commit 2d6915a598
  1. 11
      docs/markdown/Builtin-options.md
  2. 4
      docs/markdown/snippets/default_both_libraries.md
  3. 4
      mesonbuild/build.py
  4. 7
      mesonbuild/interpreter/interpreter.py
  5. 2
      mesonbuild/options.py
  6. 44
      test cases/common/273 both libraries/meson.build
  7. 15
      test cases/common/273 both libraries/src/api.h
  8. 10
      test cases/common/273 both libraries/src/library.c
  9. 5
      test cases/common/273 both libraries/src/library.h
  10. 8
      test cases/common/273 both libraries/src/main.c
  11. 16
      test cases/common/273 both libraries/test.json

@ -79,6 +79,7 @@ machine](#specifying-options-per-machine) section for details.
| genvslite {vs2022} | vs2022 | Setup multi-builtype ninja build directories and Visual Studio solution | no | no |
| buildtype {plain, debug,<br>debugoptimized, release, minsize, custom} | debug | Build type to use | no | no |
| debug | true | Enable debug symbols and other information | no | no |
| default_both_libraries {shared, static, auto} | shared | Default library type for both_libraries | no | no |
| default_library {shared, static, both} | shared | Default library type | no | yes |
| errorlogs | true | Whether to print the logs from failing tests. | no | no |
| install_umask {preserve, 0000-0777} | 022 | Default umask to apply on permissions of installed files | no | no |
@ -177,6 +178,16 @@ fails.
`vsenv` is `true` by default when using the `vs` backend.
#### Details for `default_both_libraries`
Since `1.6.0`, you can select the default type of library selected when using
a `both_libraries` object. This can be either 'shared' (default value, compatible
with previous meson versions), 'static', or 'auto'. With auto, the value from
`default_library` option is used, unless it is 'both', in which case 'shared'
is used instead.
## Base options
These are set in the same way as universal options, either by

@ -0,0 +1,4 @@
## New built-in option for default both_libraries
`both_libraries` targets used to be considered as a shared library by default.
There is now the `default_both_libraries` option to change this default.

@ -2486,8 +2486,8 @@ class SharedModule(SharedLibrary):
return self.environment.get_shared_module_dir(), '{moduledir_shared}'
class BothLibraries(SecondLevelHolder):
def __init__(self, shared: SharedLibrary, static: StaticLibrary) -> None:
self._preferred_library = 'shared'
def __init__(self, shared: SharedLibrary, static: StaticLibrary, preferred_library: Literal['shared', 'static', 'auto']) -> None:
self._preferred_library = preferred_library
self.shared = shared
self.static = static
self.subproject = self.shared.subproject

@ -3230,6 +3230,11 @@ class Interpreter(InterpreterBase, HoldableObject):
def build_both_libraries(self, node: mparser.BaseNode, args: T.Tuple[str, SourcesVarargsType], kwargs: kwtypes.Library) -> build.BothLibraries:
shared_lib = self.build_target(node, args, kwargs, build.SharedLibrary)
static_lib = self.build_target(node, args, kwargs, build.StaticLibrary)
preferred_library = self.coredata.get_option(OptionKey('default_both_libraries'))
if preferred_library == 'auto':
preferred_library = self.coredata.get_option(OptionKey('default_library'))
if preferred_library == 'both':
preferred_library = 'shared'
if self.backend.name == 'xcode':
# Xcode is a bit special in that you can't (at least for the moment)
@ -3261,7 +3266,7 @@ class Interpreter(InterpreterBase, HoldableObject):
# Keep only compilers used for linking
static_lib.compilers = {k: v for k, v in static_lib.compilers.items() if k in compilers.clink_langs}
return build.BothLibraries(shared_lib, static_lib)
return build.BothLibraries(shared_lib, static_lib, preferred_library)
def build_library(self, node: mparser.BaseNode, args: T.Tuple[str, SourcesVarargsType], kwargs: kwtypes.Library):
default_library = self.coredata.get_option(OptionKey('default_library', subproject=self.subproject))

@ -63,6 +63,7 @@ _BUILTIN_NAMES = {
'buildtype',
'debug',
'default_library',
'default_both_libraries',
'errorlogs',
'genvslite',
'install_umask',
@ -624,6 +625,7 @@ BUILTIN_CORE_OPTIONS: T.Dict['OptionKey', 'BuiltinOption'] = OrderedDict([
(OptionKey('debug'), BuiltinOption(UserBooleanOption, 'Enable debug symbols and other information', True)),
(OptionKey('default_library'), BuiltinOption(UserComboOption, 'Default library type', 'shared', choices=['shared', 'static', 'both'],
yielding=False)),
(OptionKey('default_both_libraries'), BuiltinOption(UserComboOption, 'Default library type for both_libraries', 'shared', choices=['shared', 'static', 'auto'])),
(OptionKey('errorlogs'), BuiltinOption(UserBooleanOption, "Whether to print the logs from failing tests", True)),
(OptionKey('install_umask'), BuiltinOption(UserUmaskOption, 'Default umask to apply on permissions of installed files', '022')),
(OptionKey('layout'), BuiltinOption(UserComboOption, 'Build directory layout', 'mirror', choices=['mirror', 'flat'])),

@ -0,0 +1,44 @@
project(
'test both libraries',
'c',
meson_version: '>= 1.6.0',
)
expected = 0
with_library = library(
'with_library',
files('src/library.c'),
c_shared_args: ['-DEXPORT'],
)
with_library_dep = declare_dependency(
link_with: with_library,
)
if get_option('default_library') == 'shared'
expected += 1
elif get_option('default_library') == 'both'
if get_option('default_both_libraries') in ['shared', 'auto']
expected += 1
endif
endif
mainlink = executable(
'mainlink',
files('src/main.c'),
c_args: [f'-DEXPECTED=@expected@'],
link_with: [with_library],
)
test('link with', mainlink)
maindep = executable(
'maindep',
files('src/main.c'),
c_args: [f'-DEXPECTED=@expected@'],
dependencies: [with_library_dep],
)
test('use dep', maindep)

@ -0,0 +1,15 @@
#pragma once
#if defined EXPORT
#if defined _WIN32 || defined __CYGWIN__
#define API __declspec(dllexport)
#else
#if defined __GNUC__
#define API __attribute__((visibility("default")))
#else
#define API
#endif
#endif
#else
#define API
#endif

@ -0,0 +1,10 @@
#include "library.h"
int library_function(void)
{
#if defined EXPORT
return 1;
#else
return 0;
#endif
}

@ -0,0 +1,5 @@
#pragma once
#include "api.h"
int API library_function(void);

@ -0,0 +1,8 @@
#include "library.h"
int main(void)
{
int sum = library_function();
return sum == EXPECTED ? 0 : sum;
}

@ -0,0 +1,16 @@
{
"matrix": {
"options": {
"default_library": [
{ "val": "shared" },
{ "val": "static" },
{ "val": "both" }
],
"default_both_libraries": [
{ "val": "shared" },
{ "val": "static" },
{ "val": "auto" }
]
}
}
}
Loading…
Cancel
Save