diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 778a4d6015d4..686f9a989908 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -91,6 +91,7 @@ from . import primitives as P_OBJ from pathlib import Path +from enum import Enum import os import shutil import uuid @@ -239,6 +240,16 @@ def dump_value(self, arr, list_sep, indent): KwargInfo('verbose', bool, default=False, since='0.62.0'), ] +class InterpreterRuleRelaxation(Enum): + ''' Defines specific relaxations of the Meson rules. + + This is intended to be used for automatically converted + projects (CMake subprojects, build system mixing) that + generate a Meson AST via introspection, etc. + ''' + + ALLOW_BUILD_DIR_FILE_REFFERENCES = 1 + permitted_dependency_kwargs = { 'allow_fallback', 'cmake_args', @@ -278,6 +289,7 @@ def __init__( mock: bool = False, ast: T.Optional[mparser.CodeBlockNode] = None, is_translated: bool = False, + relaxations: T.Optional[T.Set[InterpreterRuleRelaxation]] = None, user_defined_options: T.Optional['argparse.Namespace'] = None, ) -> None: super().__init__(_build.environment.get_source_dir(), subdir, subproject) @@ -293,6 +305,7 @@ def __init__( self.subproject_directory_name = subdir.split(os.path.sep)[-1] self.subproject_dir = subproject_dir self.option_file = os.path.join(self.source_root, self.subdir, 'meson_options.txt') + self.relaxations = relaxations or set() if not mock and ast is None: self.load_root_meson_file() self.sanity_check_ast() @@ -936,11 +949,13 @@ def _do_subproject_meson(self, subp_name: str, subdir: str, kwargs: kwargs.DoSubproject, ast: T.Optional[mparser.CodeBlockNode] = None, build_def_files: T.Optional[T.List[str]] = None, - is_translated: bool = False) -> SubprojectHolder: + is_translated: bool = False, + relaxations: T.Optional[T.Set[InterpreterRuleRelaxation]] = None) -> SubprojectHolder: with mlog.nested(subp_name): new_build = self.build.copy() subi = Interpreter(new_build, self.backend, subp_name, subdir, self.subproject_dir, default_options, ast=ast, is_translated=is_translated, + relaxations=relaxations, user_defined_options=self.user_defined_options) # Those lists are shared by all interpreters. That means that # even if the subproject fails, any modification that the subproject @@ -1015,7 +1030,15 @@ def _do_subproject_cmake(self, subp_name: str, subdir: str, subdir_abs: str, mlog.cmd_ci_include(meson_filename) mlog.log() - result = self._do_subproject_meson(subp_name, subdir, default_options, kwargs, ast, [str(f) for f in cm_int.bs_files], is_translated=True) + result = self._do_subproject_meson( + subp_name, subdir, default_options, + kwargs, ast, + [str(f) for f in cm_int.bs_files], + is_translated=True, + relaxations={ + InterpreterRuleRelaxation.ALLOW_BUILD_DIR_FILE_REFFERENCES, + } + ) result.cm_interpreter = cm_int mlog.log() @@ -2864,6 +2887,8 @@ def validate_installable_file(fpath: Path) -> bool: inputtype = 'directory' else: inputtype = 'file' + if InterpreterRuleRelaxation.ALLOW_BUILD_DIR_FILE_REFFERENCES in self.relaxations and builddir in norm.parents: + return if srcdir not in norm.parents: # Grabbing files outside the source tree is ok. # This is for vendor stuff like: diff --git a/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt index 6258ca0b4aa5..07501174990c 100644 --- a/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt +++ b/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt @@ -17,7 +17,7 @@ generate_export_header(cmModLib) set_target_properties(cmModLib PROPERTIES VERSION 1.0.1) -add_executable(testEXE main.cpp) +add_executable(testEXE main.cpp "${CMAKE_CURRENT_BINARY_DIR}/config.h") target_link_libraries(cmModLib ZLIB::ZLIB) target_link_libraries(cmModLibStatic ;ZLIB::ZLIB;)