Skip to content

Commit

Permalink
cmake: Add rule relaxations for CMake subprojects
Browse files Browse the repository at this point in the history
fixes #10566
  • Loading branch information
mensinda authored and nirbheek committed Aug 12, 2022
1 parent bc2305e commit ce9364d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 27 additions & 2 deletions mesonbuild/interpreter/interpreter.py
Expand Up @@ -91,6 +91,7 @@
from . import primitives as P_OBJ

from pathlib import Path
from enum import Enum
import os
import shutil
import uuid
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
Expand Up @@ -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;)
Expand Down

0 comments on commit ce9364d

Please sign in to comment.