interpreter, cmake: add native argument to subproject()

Extracted from a patch by Dylan Baker <dylan@pnwbakers.com>

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini
2025-12-16 11:05:23 +01:00
committed by Dylan Baker
parent 26e4e7d4ca
commit 192ac47bd4
2 changed files with 14 additions and 3 deletions

View File

@@ -14,7 +14,7 @@ from ..options import OptionKey
from ..cmake import TargetOptions, cmake_defines_to_args
from ..dependencies.cmake import CMakeDependency
from ..interpreter import SubprojectHolder
from ..interpreter.type_checking import REQUIRED_KW, INSTALL_DIR_KW, INCLUDE_TYPE, NoneType, in_set_validator
from ..interpreter.type_checking import NATIVE_KW, REQUIRED_KW, INSTALL_DIR_KW, INCLUDE_TYPE, NoneType, in_set_validator
from ..interpreterbase import (
FeatureNew,
@@ -59,6 +59,7 @@ if T.TYPE_CHECKING:
options: T.Optional[CMakeSubprojectOptions]
cmake_options: T.List[str]
native: mesonlib.MachineChoice
class TargetKW(TypedDict):
@@ -425,6 +426,7 @@ class CmakeModule(ExtensionModule):
@typed_kwargs(
'cmake.subproject',
REQUIRED_KW,
NATIVE_KW.evolve(since='1.12.0'),
KwargInfo('options', (CMakeSubprojectOptions, NoneType), since='0.55.0'),
KwargInfo(
'cmake_options',
@@ -445,7 +447,7 @@ class CmakeModule(ExtensionModule):
'cmake_options': kwargs_['cmake_options'],
'default_options': {},
'version': [],
'for_machine': mesonlib.MachineChoice.HOST,
'for_machine': kwargs_['native'],
}
subp = self.interpreter.do_subproject(subp_name, kw, force_method='cmake')
if not subp.found():

View File

@@ -1,4 +1,4 @@
project('cmakeSubTest_advanced', ['c', 'cpp'])
project('cmakeSubTest_advanced', ['c', 'cpp'], meson_version: '>= 1.12.0')
dep_test = dependency('ZLIB', method: 'cmake', required: false)
if not dep_test.found()
@@ -45,3 +45,12 @@ else
lib_version_ok = true
endif
assert(lib_version_ok, f'Shared library version @lib_file_name@ not picked up correctly')
# Test the "normal" subproject call for the build machine
sub_pro_b = cm.subproject('cmMod', native : true)
sub_dep_b = sub_pro_b.dependency('cmModLib')
sub_sta_b = sub_pro_b.dependency('cmModLibStatic')
# Build some files
exe1_b = executable('main1_b', ['main.cpp'], dependencies: [sub_dep_b], native : true)
exe2_b = executable('main2_b', ['main.cpp'], dependencies: [sub_sta_b], native : true)