diff options
Diffstat (limited to 'mesonbuild/compilers/compilers.py')
| -rw-r--r-- | mesonbuild/compilers/compilers.py | 78 |
1 files changed, 50 insertions, 28 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 9e99706c0..5854c9e60 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -9,6 +9,7 @@ import contextlib, os.path, re import enum import itertools import typing as T +from dataclasses import dataclass from functools import lru_cache from .. import coredata @@ -34,6 +35,7 @@ if T.TYPE_CHECKING: CompilerType = T.TypeVar('CompilerType', bound='Compiler') _T = T.TypeVar('_T') + UserOptionType = T.TypeVar('UserOptionType', bound=coredata.UserOption) """This file contains the data files of all compilers Meson knows about. To support a new compiler, add its information below. @@ -206,36 +208,46 @@ clike_debug_args: T.Dict[bool, T.List[str]] = { MSCRT_VALS = ['none', 'md', 'mdd', 'mt', 'mtd'] -base_options: 'KeyedOptionDictType' = { - OptionKey('b_pch'): coredata.UserBooleanOption('Use precompiled headers', True), - OptionKey('b_lto'): coredata.UserBooleanOption('Use link time optimization', False), - OptionKey('b_lto_threads'): coredata.UserIntegerOption('Use multiple threads for Link Time Optimization', (None, None, 0)), - OptionKey('b_lto_mode'): coredata.UserComboOption('Select between different LTO modes.', - ['default', 'thin'], - 'default'), - OptionKey('b_thinlto_cache'): coredata.UserBooleanOption('Use LLVM ThinLTO caching for faster incremental builds', False), - OptionKey('b_thinlto_cache_dir'): coredata.UserStringOption('Directory to store ThinLTO cache objects', ''), - OptionKey('b_sanitize'): coredata.UserComboOption('Code sanitizer to use', - ['none', 'address', 'thread', 'undefined', 'memory', 'leak', 'address,undefined'], - 'none'), - OptionKey('b_lundef'): coredata.UserBooleanOption('Use -Wl,--no-undefined when linking', True), - OptionKey('b_asneeded'): coredata.UserBooleanOption('Use -Wl,--as-needed when linking', True), - OptionKey('b_pgo'): coredata.UserComboOption('Use profile guided optimization', - ['off', 'generate', 'use'], - 'off'), - OptionKey('b_coverage'): coredata.UserBooleanOption('Enable coverage tracking.', False), - OptionKey('b_colorout'): coredata.UserComboOption('Use colored output', - ['auto', 'always', 'never'], - 'always'), - OptionKey('b_ndebug'): coredata.UserComboOption('Disable asserts', ['true', 'false', 'if-release'], 'false'), - OptionKey('b_staticpic'): coredata.UserBooleanOption('Build static libraries as position independent', True), - OptionKey('b_pie'): coredata.UserBooleanOption('Build executables as position independent', False), - OptionKey('b_bitcode'): coredata.UserBooleanOption('Generate and embed bitcode (only macOS/iOS/tvOS)', False), - OptionKey('b_vscrt'): coredata.UserComboOption('VS run-time library type to use.', - MSCRT_VALS + ['from_buildtype', 'static_from_buildtype'], - 'from_buildtype'), +@dataclass +class BaseOption(T.Generic[coredata._T, coredata._U]): + opt_type: T.Type[coredata._U] + description: str + default: T.Any = None + choices: T.Any = None + + def init_option(self, name: OptionKey) -> coredata._U: + keywords = {'value': self.default} + if self.choices: + keywords['choices'] = self.choices + return self.opt_type(name.name, self.description, **keywords) + +BASE_OPTIONS: T.Mapping[OptionKey, BaseOption] = { + OptionKey('b_pch'): BaseOption(coredata.UserBooleanOption, 'Use precompiled headers', True), + OptionKey('b_lto'): BaseOption(coredata.UserBooleanOption, 'Use link time optimization', False), + OptionKey('b_lto_threads'): BaseOption(coredata.UserIntegerOption, 'Use multiple threads for Link Time Optimization', (None, None, 0)), + OptionKey('b_lto_mode'): BaseOption(coredata.UserComboOption, 'Select between different LTO modes.', 'default', + choices=['default', 'thin']), + OptionKey('b_thinlto_cache'): BaseOption(coredata.UserBooleanOption, 'Use LLVM ThinLTO caching for faster incremental builds', False), + OptionKey('b_thinlto_cache_dir'): BaseOption(coredata.UserStringOption, 'Directory to store ThinLTO cache objects', ''), + OptionKey('b_sanitize'): BaseOption(coredata.UserComboOption, 'Code sanitizer to use', 'none', + choices=['none', 'address', 'thread', 'undefined', 'memory', 'leak', 'address,undefined']), + OptionKey('b_lundef'): BaseOption(coredata.UserBooleanOption, 'Use -Wl,--no-undefined when linking', True), + OptionKey('b_asneeded'): BaseOption(coredata.UserBooleanOption, 'Use -Wl,--as-needed when linking', True), + OptionKey('b_pgo'): BaseOption(coredata.UserComboOption, 'Use profile guided optimization', 'off', + choices=['off', 'generate', 'use']), + OptionKey('b_coverage'): BaseOption(coredata.UserBooleanOption, 'Enable coverage tracking.', False), + OptionKey('b_colorout'): BaseOption(coredata.UserComboOption, 'Use colored output', 'always', + choices=['auto', 'always', 'never']), + OptionKey('b_ndebug'): BaseOption(coredata.UserComboOption, 'Disable asserts', 'false', choices=['true', 'false', 'if-release']), + OptionKey('b_staticpic'): BaseOption(coredata.UserBooleanOption, 'Build static libraries as position independent', True), + OptionKey('b_pie'): BaseOption(coredata.UserBooleanOption, 'Build executables as position independent', False), + OptionKey('b_bitcode'): BaseOption(coredata.UserBooleanOption, 'Generate and embed bitcode (only macOS/iOS/tvOS)', False), + OptionKey('b_vscrt'): BaseOption(coredata.UserComboOption, 'VS run-time library type to use.', 'from_buildtype', + choices=MSCRT_VALS + ['from_buildtype', 'static_from_buildtype']), } +base_options: KeyedOptionDictType = {key: base_opt.init_option(key) for key, base_opt in BASE_OPTIONS.items()} + def option_enabled(boptions: T.Set[OptionKey], options: 'KeyedOptionDictType', option: OptionKey) -> bool: try: @@ -577,6 +589,14 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta): """ return [] + def create_option(self, option_type: T.Type[UserOptionType], option_key: OptionKey, *args: T.Any, **kwargs: T.Any) -> T.Tuple[OptionKey, UserOptionType]: + return option_key, option_type(f'{self.language}_{option_key.name}', *args, **kwargs) + + @staticmethod + def update_options(options: MutableKeyedOptionDictType, *args: T.Tuple[OptionKey, UserOptionType]) -> MutableKeyedOptionDictType: + options.update(args) + return options + def get_options(self) -> 'MutableKeyedOptionDictType': return {} @@ -1346,10 +1366,12 @@ def get_global_options(lang: str, link_options = env.options.get(largkey, []) cargs = coredata.UserArrayOption( + f'{lang}_{argkey.name}', description + ' compiler', comp_options, split_args=True, allow_dups=True) largs = coredata.UserArrayOption( + f'{lang}_{largkey.name}', description + ' linker', link_options, split_args=True, allow_dups=True) |
