diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2022-08-04 20:01:57 +0200 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2022-08-13 01:51:07 +0530 |
commit | ce9364d5dd3a085686f05f51bdfd1fbf465be7d6 (patch) | |
tree | e820e4d229bd45feeb543df7e59f763e0e5e8e21 | |
parent | bc2305e1ac044e338fa51f26041914f65184b737 (diff) | |
download | meson-ce9364d5dd3a085686f05f51bdfd1fbf465be7d6.zip meson-ce9364d5dd3a085686f05f51bdfd1fbf465be7d6.tar.gz meson-ce9364d5dd3a085686f05f51bdfd1fbf465be7d6.tar.bz2 |
cmake: Add rule relaxations for CMake subprojects
fixes #10566
-rw-r--r-- | mesonbuild/interpreter/interpreter.py | 29 | ||||
-rw-r--r-- | test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt | 2 |
2 files changed, 28 insertions, 3 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 778a4d6..686f9a9 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -91,6 +91,7 @@ from .type_checking import ( from . import primitives as P_OBJ from pathlib import Path +from enum import Enum import os import shutil import uuid @@ -239,6 +240,16 @@ TEST_KWARGS: T.List[KwargInfo] = [ 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 @@ class Interpreter(InterpreterBase, HoldableObject): 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 @@ class Interpreter(InterpreterBase, HoldableObject): 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 @@ class Interpreter(InterpreterBase, HoldableObject): 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 @@ class Interpreter(InterpreterBase, HoldableObject): 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 @@ Try setting b_lundef to false instead.'''.format(self.coredata.options[OptionKey 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 6258ca0..0750117 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;) |