From 4ca746deb79da42b865fe76d68349722e78cc9f7 Mon Sep 17 00:00:00 2001 From: ligazetom Date: Thu, 9 Jan 2025 16:42:38 +0100 Subject: [PATCH] Allow for cmake w-flags addition --- mesonbuild/cmake/__init__.py | 3 ++- mesonbuild/cmake/common.py | 17 +++++++++++++++++ mesonbuild/modules/cmake.py | 8 +++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/mesonbuild/cmake/__init__.py b/mesonbuild/cmake/__init__.py index 607df8977cf6..600e327c3295 100644 --- a/mesonbuild/cmake/__init__.py +++ b/mesonbuild/cmake/__init__.py @@ -15,12 +15,13 @@ 'TargetOptions', 'language_map', 'cmake_defines_to_args', + 'cmake_warning_flags_to_args', 'check_cmake_args', 'cmake_is_debug', 'resolve_cmake_trace_targets', ] -from .common import CMakeException, TargetOptions, cmake_defines_to_args, language_map, check_cmake_args, cmake_is_debug +from .common import CMakeException, TargetOptions, cmake_defines_to_args, cmake_warning_flags_to_args, language_map, check_cmake_args, cmake_is_debug from .executor import CMakeExecutor from .interpreter import CMakeInterpreter from .toolchain import CMakeToolchain, CMakeExecScope diff --git a/mesonbuild/cmake/common.py b/mesonbuild/cmake/common.py index d9ff559971f7..6dfd1715660e 100644 --- a/mesonbuild/cmake/common.py +++ b/mesonbuild/cmake/common.py @@ -51,6 +51,9 @@ 'MESON_CMAKE_ROOT', ] +blacklist_cmake_warning_flags = [ +] + def cmake_is_debug(env: 'Environment') -> bool: if OptionKey('b_vscrt') in env.coredata.optstore: is_debug = env.coredata.get_option(OptionKey('buildtype')) == 'debug' @@ -130,6 +133,20 @@ def cmake_defines_to_args(raw: T.List[T.Dict[str, TYPE_var]], permissive: bool = return res +def cmake_warning_flags_to_args(raw: T.List[str], permissive: bool = False) -> T.List[str]: + res: T.List[str] = [] + + for flag in raw: + if flag in blacklist_cmake_warning_flags: + # idk something something + #mlog.warning('Setting', mlog.bold(flag), 'is not supported. See the meson docs for cross compilation support:') + #mlog.warning(' - URL: https://mesonbuild.com/CMake-module.html#cross-compilation') + #mlog.warning(' --> Ignoring this option') + continue + res += [f'-W{flag}'] + + return res + # TODO: this function will become obsolete once the `cmake_args` kwarg is dropped def check_cmake_args(args: T.List[str]) -> T.List[str]: res: T.List[str] = [] diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py index 2168aaa516c0..4600cb6f47a8 100644 --- a/mesonbuild/modules/cmake.py +++ b/mesonbuild/modules/cmake.py @@ -11,7 +11,7 @@ from .. import build, mesonlib, mlog, dependencies from ..options import OptionKey -from ..cmake import TargetOptions, cmake_defines_to_args +from ..cmake import TargetOptions, cmake_defines_to_args, cmake_warning_flags_to_args from ..interpreter import SubprojectHolder from ..interpreter.type_checking import REQUIRED_KW, INSTALL_DIR_KW, NoneType, in_set_validator from ..interpreterbase import ( @@ -191,6 +191,7 @@ def __init__(self) -> None: self.methods.update( { 'add_cmake_defines': self.add_cmake_defines, + 'add_cmake_warning_flags': self.add_cmake_warning_flags, 'set_override_option': self.set_override_option, 'set_install': self.set_install, 'append_compile_args': self.append_compile_args, @@ -209,6 +210,11 @@ def _get_opts(self, kwargs: TargetKW) -> SingleTargetOptions: def add_cmake_defines(self, state: ModuleState, args: T.Tuple[T.List[T.Dict[str, TYPE_var]]], kwargs: TYPE_kwargs) -> None: self.cmake_options += cmake_defines_to_args(args[0]) + @typed_pos_args('subproject_options.add_cmake_warning_flags', varargs=str) + @noKwargs + def add_cmake_warning_flags(self, state: ModuleState, args: T.Tuple[T.List[str]], kwargs: TYPE_kwargs) -> None: + self.cmake_options += cmake_warning_flags_to_args(args[0]) + @typed_pos_args('subproject_options.set_override_option', str, str) @typed_kwargs('subproject_options.set_override_option', _TARGET_KW) def set_override_option(self, state: ModuleState, args: T.Tuple[str, str], kwargs: TargetKW) -> None: