From 5f1da86a9b3ed75c49df7073962c4e9b6a43d497 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Fri, 16 Oct 2020 20:44:04 +0200 Subject: cmake: ignore CMAKE_TOOLCHAIN_FILE and CMAKE_PROJECT_INCLUDE to avoid conflicts with the meson CMake logic --- mesonbuild/cmake/__init__.py | 3 ++- mesonbuild/cmake/common.py | 24 ++++++++++++++++++++++++ mesonbuild/cmake/interpreter.py | 5 ++++- mesonbuild/dependencies/base.py | 3 ++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/mesonbuild/cmake/__init__.py b/mesonbuild/cmake/__init__.py index 9840a5f..b13b5a8 100644 --- a/mesonbuild/cmake/__init__.py +++ b/mesonbuild/cmake/__init__.py @@ -31,9 +31,10 @@ __all__ = [ 'parse_generator_expressions', 'language_map', 'cmake_defines_to_args', + 'check_cmake_args', ] -from .common import CMakeException, SingleTargetOptions, TargetOptions, cmake_defines_to_args, language_map +from .common import CMakeException, SingleTargetOptions, TargetOptions, cmake_defines_to_args, language_map, check_cmake_args from .client import CMakeClient from .executor import CMakeExecutor from .fileapi import CMakeFileAPI diff --git a/mesonbuild/cmake/common.py b/mesonbuild/cmake/common.py index 3534ec0..fe98497 100644 --- a/mesonbuild/cmake/common.py +++ b/mesonbuild/cmake/common.py @@ -32,6 +32,11 @@ language_map = { 'swift': 'Swift', } +blacklist_cmake_defs = [ + 'CMAKE_TOOLCHAIN_FILE', + 'CMAKE_PROJECT_INCLUDE', +] + class CMakeException(MesonException): pass @@ -83,6 +88,11 @@ def cmake_defines_to_args(raw: T.Any, permissive: bool = False) -> T.List[str]: raise MesonException('Invalid CMake defines. Expected a dict, but got a {}'.format(type(i).__name__)) for key, val in i.items(): assert isinstance(key, str) + if key in blacklist_cmake_defs: + mlog.warning('Setting', mlog.bold(key), '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 if isinstance(val, (str, int, float)): res += ['-D{}={}'.format(key, val)] elif isinstance(val, bool): @@ -93,6 +103,20 @@ def cmake_defines_to_args(raw: T.Any, permissive: bool = False) -> T.List[str]: return res +# TODO: this functuin will become obsolete once the `cmake_args` kwarg is dropped +def check_cmake_args(args: T.List[str]) -> T.List[str]: + res = [] # type: T.List[str] + dis = ['-D' + x for x in blacklist_cmake_defs] + assert dis # Ensure that dis is not empty. + for i in args: + if any([i.startswith(x) for x in dis]): + mlog.warning('Setting', mlog.bold(i), '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 += [i] + return res + class CMakeInclude: def __init__(self, path: Path, isSystem: bool = False): self.path = path diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py index 03ed90d..bac9dad 100644 --- a/mesonbuild/cmake/interpreter.py +++ b/mesonbuild/cmake/interpreter.py @@ -15,7 +15,7 @@ # This class contains the basic functionality needed to run any interpreter # or an interpreter-based tool. -from .common import CMakeException, CMakeTarget, TargetOptions, CMakeConfiguration, language_map +from .common import CMakeException, CMakeTarget, TargetOptions, CMakeConfiguration, language_map, check_cmake_args from .client import CMakeClient, RequestCMakeInputs, RequestConfigure, RequestCompute, RequestCodeModel, ReplyCMakeInputs, ReplyCodeModel from .fileapi import CMakeFileAPI from .executor import CMakeExecutor @@ -862,6 +862,9 @@ class CMakeInterpreter: toolchain = CMakeToolchain(self.env, self.for_machine, CMakeExecScope.SUBPROJECT, self.build_dir.parent, preload_file) toolchain_file = toolchain.write() + # TODO: drop this check once the deprecated `cmake_args` kwarg is removed + extra_cmake_options = check_cmake_args(extra_cmake_options) + generator = backend_generator_map[self.backend_name] cmake_args = [] cmake_args += ['-G', generator] diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 2e56565..3a5f5f8 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -34,7 +34,7 @@ from .. import mesonlib from ..compilers import clib_langs from ..envconfig import get_env_var from ..environment import BinaryTable, Environment, MachineInfo -from ..cmake import CMakeExecutor, CMakeTraceParser, CMakeException, CMakeToolchain, CMakeExecScope +from ..cmake import CMakeExecutor, CMakeTraceParser, CMakeException, CMakeToolchain, CMakeExecScope, check_cmake_args from ..mesonlib import MachineChoice, MesonException, OrderedSet, PerMachine from ..mesonlib import Popen_safe, version_compare_many, version_compare, listify, stringlistify, extract_as_list, split_args from ..mesonlib import Version, LibType @@ -1100,6 +1100,7 @@ class CMakeDependency(ExternalDependency): self.traceparser = CMakeTraceParser(self.cmakebin.version(), self._get_build_dir()) cm_args = stringlistify(extract_as_list(kwargs, 'cmake_args')) + cm_args = check_cmake_args(cm_args) if CMakeDependency.class_cmakeinfo[self.for_machine] is None: CMakeDependency.class_cmakeinfo[self.for_machine] = self._get_cmake_info(cm_args) self.cmakeinfo = CMakeDependency.class_cmakeinfo[self.for_machine] -- cgit v1.1 From 36cde6f91e0710b9c6ee87bd055383e52525fa75 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Fri, 16 Oct 2020 22:43:20 +0200 Subject: cmake: Ignore additional internal CMake variables --- mesonbuild/cmake/common.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mesonbuild/cmake/common.py b/mesonbuild/cmake/common.py index fe98497..4bcc4d9 100644 --- a/mesonbuild/cmake/common.py +++ b/mesonbuild/cmake/common.py @@ -35,6 +35,15 @@ language_map = { blacklist_cmake_defs = [ 'CMAKE_TOOLCHAIN_FILE', 'CMAKE_PROJECT_INCLUDE', + 'MESON_PRELOAD_FILE', + 'MESON_PS_CMAKE_CURRENT_BINARY_DIR', + 'MESON_PS_CMAKE_CURRENT_SOURCE_DIR', + 'MESON_PS_DELAYED_CALLS', + 'MESON_PS_LOADED', + 'MESON_FIND_ROOT_PATH', + 'MESON_CMAKE_SYSROOT', + 'MESON_PATHS_LIST', + 'MESON_CMAKE_ROOT', ] class CMakeException(MesonException): -- cgit v1.1