| 1 |
# SPDX-License-Identifier: Apache-2.0 |
| 2 |
# Copyright 2018 The Meson development team |
| 3 |
|
| 4 |
from __future__ import annotations |
| 5 |
import re |
| 6 |
import os, os.path, pathlib |
| 7 |
import shutil |
| 8 |
import typing as T |
| 9 |
|
| 10 |
from . import ExtensionModule, ModuleReturnValue, ModuleObject, ModuleInfo |
| 11 |
|
| 12 |
from .. import build, mesonlib, mlog, dependencies |
| 13 |
from ..options import OptionKey |
| 14 |
from ..cmake import TargetOptions, cmake_defines_to_args |
| 15 |
from ..dependencies.cmake import CMakeDependency |
| 16 |
from ..interpreter import SubprojectHolder |
| 17 |
from ..interpreter.type_checking import NATIVE_KW, REQUIRED_KW, INSTALL_DIR_KW, INCLUDE_TYPE, NoneType, in_set_validator |
| 18 |
from ..interpreterbase import ( |
| 19 |
FeatureNew, |
| 20 |
|
| 21 |
noPosargs, |
| 22 |
noKwargs, |
| 23 |
|
| 24 |
InvalidArguments, |
| 25 |
InterpreterException, |
| 26 |
|
| 27 |
typed_pos_args, |
| 28 |
typed_kwargs, |
| 29 |
KwargInfo, |
| 30 |
ContainerTypeInfo, |
| 31 |
) |
| 32 |
|
| 33 |
if T.TYPE_CHECKING: |
| 34 |
from typing_extensions import TypedDict |
| 35 |
|
| 36 |
from . import ModuleState |
| 37 |
from ..cmake.common import SingleTargetOptions |
| 38 |
from ..dependencies.base import IncludeType |
| 39 |
from ..environment import Environment |
| 40 |
from ..interpreter import Interpreter, kwargs |
| 41 |
from ..interpreterbase import TYPE_kwargs, TYPE_var, InterpreterObject |
| 42 |
|
| 43 |
class WriteBasicPackageVersionFile(TypedDict): |
| 44 |
|
| 45 |
arch_independent: bool |
| 46 |
compatibility: str |
| 47 |
install_dir: T.Optional[str] |
| 48 |
name: str |
| 49 |
version: str |
| 50 |
|
| 51 |
class ConfigurePackageConfigFile(TypedDict): |
| 52 |
|
| 53 |
configuration: T.Union[build.ConfigurationData, dict] |
| 54 |
input: T.Union[str, mesonlib.File] |
| 55 |
install_dir: T.Optional[str] |
| 56 |
name: str |
| 57 |
|
| 58 |
class Subproject(kwargs.ExtractRequired): |
| 59 |
|
| 60 |
options: T.Optional[CMakeSubprojectOptions] |
| 61 |
cmake_options: T.List[str] |
| 62 |
native: mesonlib.MachineChoice |
| 63 |
|
| 64 |
class TargetKW(TypedDict): |
| 65 |
|
| 66 |
target: T.Optional[str] |
| 67 |
|
| 68 |
class DependencyKW(TypedDict): |
| 69 |
|
| 70 |
include_type: IncludeType |
| 71 |
|
| 72 |
|
| 73 |
_TARGET_KW = KwargInfo('target', (str, NoneType)) |
| 74 |
|
| 75 |
COMPATIBILITIES = ['AnyNewerVersion', 'SameMajorVersion', 'SameMinorVersion', 'ExactVersion'] |
| 76 |
|
| 77 |
# Taken from https://github.com/Kitware/CMake/blob/master/Modules/CMakePackageConfigHelpers.cmake |
| 78 |
PACKAGE_INIT_BASE = ''' |
| 79 |
####### Expanded from \\@PACKAGE_INIT\\@ by configure_package_config_file() ####### |
| 80 |
####### Any changes to this file will be overwritten by the next CMake run #### |
| 81 |
####### The input file was @inputFileName@ ######## |
| 82 |
|
| 83 |
get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/@PACKAGE_RELATIVE_PATH@" ABSOLUTE) |
| 84 |
''' |
| 85 |
PACKAGE_INIT_EXT = ''' |
| 86 |
# Use original install prefix when loaded through a "/usr move" |
| 87 |
# cross-prefix symbolic link such as /lib -> /usr/lib. |
| 88 |
get_filename_component(_realCurr "${CMAKE_CURRENT_LIST_DIR}" REALPATH) |
| 89 |
get_filename_component(_realOrig "@absInstallDir@" REALPATH) |
| 90 |
if(_realCurr STREQUAL _realOrig) |
| 91 |
set(PACKAGE_PREFIX_DIR "@installPrefix@") |
| 92 |
endif() |
| 93 |
unset(_realOrig) |
| 94 |
unset(_realCurr) |
| 95 |
''' |
| 96 |
PACKAGE_INIT_SET_AND_CHECK = ''' |
| 97 |
macro(set_and_check _var _file) |
| 98 |
set(${_var} "${_file}") |
| 99 |
if(NOT EXISTS "${_file}") |
| 100 |
message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !") |
| 101 |
endif() |
| 102 |
endmacro() |
| 103 |
#################################################################################### |
| 104 |
''' |
| 105 |
|
| 106 |
class CMakeSubproject(ModuleObject): |
| 107 |
def __init__(self, subp: SubprojectHolder): |
| 108 |
assert subp.cm_interpreter is not None |
| 109 |
super().__init__() |
| 110 |
self.subp = subp |
| 111 |
self.cm_interpreter = subp.cm_interpreter |
| 112 |
self.methods.update({'get_variable': self.get_variable, |
| 113 |
'dependency': self.dependency, |
| 114 |
'include_directories': self.include_directories, |
| 115 |
'target': self.target, |
| 116 |
'target_type': self.target_type, |
| 117 |
'target_list': self.target_list, |
| 118 |
'found': self.found_method, |
| 119 |
}) |
| 120 |
|
| 121 |
def _args_to_info(self, tgt: str) -> T.Dict[str, str]: |
| 122 |
res = self.cm_interpreter.target_info(tgt) |
| 123 |
if res is None: |
| 124 |
raise InterpreterException(f'The CMake target {tgt} does not exist\n' + |
| 125 |
' Use the following command in your meson.build to list all available targets:\n\n' + |
| 126 |
' message(\'CMake targets:\\n - \' + \'\\n - \'.join(<cmake_subproject>.target_list()))') |
| 127 |
|
| 128 |
# Make sure that all keys are present (if not this is a bug) |
| 129 |
assert all(x in res for x in ['inc', 'src', 'dep', 'tgt', 'func']) |
| 130 |
return res |
| 131 |
|
| 132 |
@noKwargs |
| 133 |
@typed_pos_args('cmake.subproject.get_variable', str, optargs=[str]) |
| 134 |
def get_variable(self, state: ModuleState, args: T.Tuple[str, T.Optional[str]], kwargs: TYPE_kwargs) -> T.Union[TYPE_var, InterpreterObject]: |
| 135 |
return self.subp.get_variable(args, kwargs) |
| 136 |
|
| 137 |
@typed_pos_args('cmake.subproject.dependency', str) |
| 138 |
@typed_kwargs('cmake.subproject.dependency', INCLUDE_TYPE.evolve(since='0.56.0')) |
| 139 |
def dependency(self, state: ModuleState, args: T.Tuple[str], kwargs: DependencyKW) -> dependencies.Dependency: |
| 140 |
info = self._args_to_info(args[0]) |
| 141 |
if info['func'] == 'executable': |
| 142 |
raise InvalidArguments(f'{args[0]} is an executable and does not support the dependency() method. Use target() instead.') |
| 143 |
if info['dep'] is None: |
| 144 |
raise InvalidArguments(f'{args[0]} does not support the dependency() method. Use target() instead.') |
| 145 |
orig = self.get_variable(state, [info['dep']], {}) |
| 146 |
assert isinstance(orig, dependencies.Dependency) |
| 147 |
if kwargs['include_type'] != 'preserve' and kwargs['include_type'] != orig.include_type: |
| 148 |
mlog.debug('Current include type is {}. Converting to requested {}'.format(orig.include_type, kwargs['include_type'])) |
| 149 |
return orig.generate_system_dependency(kwargs['include_type']) |
| 150 |
return orig |
| 151 |
|
| 152 |
@noKwargs |
| 153 |
@typed_pos_args('cmake.subproject.include_directories', str) |
| 154 |
def include_directories(self, state: ModuleState, args: T.Tuple[str], kwargs: TYPE_kwargs) -> T.List[build.IncludeDirs]: |
| 155 |
info = self._args_to_info(args[0]) |
| 156 |
inc = self.get_variable(state, [info['inc']], kwargs) |
| 157 |
assert isinstance(inc, list), 'for mypy' |
| 158 |
assert isinstance(inc[0], build.IncludeDirs), 'for mypy' |
| 159 |
return inc |
| 160 |
|
| 161 |
@noKwargs |
| 162 |
@typed_pos_args('cmake.subproject.target', str) |
| 163 |
def target(self, state: ModuleState, args: T.Tuple[str], kwargs: TYPE_kwargs) -> build.Target: |
| 164 |
info = self._args_to_info(args[0]) |
| 165 |
tgt = self.get_variable(state, [info['tgt']], kwargs) |
| 166 |
assert isinstance(tgt, build.Target), 'for mypy' |
| 167 |
return tgt |
| 168 |
|
| 169 |
@noKwargs |
| 170 |
@typed_pos_args('cmake.subproject.target_type', str) |
| 171 |
def target_type(self, state: ModuleState, args: T.Tuple[str], kwargs: TYPE_kwargs) -> str: |
| 172 |
info = self._args_to_info(args[0]) |
| 173 |
return info['func'] |
| 174 |
|
| 175 |
@noPosargs |
| 176 |
@noKwargs |
| 177 |
def target_list(self, state: ModuleState, args: TYPE_var, kwargs: TYPE_kwargs) -> T.List[str]: |
| 178 |
return self.cm_interpreter.target_list() |
| 179 |
|
| 180 |
@noPosargs |
| 181 |
@noKwargs |
| 182 |
@FeatureNew('CMakeSubproject.found()', '0.53.2') |
| 183 |
def found_method(self, state: ModuleState, args: TYPE_var, kwargs: TYPE_kwargs) -> bool: |
| 184 |
return self.subp is not None |
| 185 |
|
| 186 |
|
| 187 |
class CMakeSubprojectOptions(ModuleObject): |
| 188 |
def __init__(self) -> None: |
| 189 |
super().__init__() |
| 190 |
self.cmake_options: T.List[str] = [] |
| 191 |
self.target_options = TargetOptions() |
| 192 |
|
| 193 |
self.methods.update( |
| 194 |
{ |
| 195 |
'add_cmake_defines': self.add_cmake_defines, |
| 196 |
'set_override_option': self.set_override_option, |
| 197 |
'set_install': self.set_install, |
| 198 |
'append_compile_args': self.append_compile_args, |
| 199 |
'append_link_args': self.append_link_args, |
| 200 |
'clear': self.clear, |
| 201 |
} |
| 202 |
) |
| 203 |
|
| 204 |
def _get_opts(self, kwargs: TargetKW) -> SingleTargetOptions: |
| 205 |
if kwargs['target'] is not None: |
| 206 |
return self.target_options[kwargs['target']] |
| 207 |
return self.target_options.global_options |
| 208 |
|
| 209 |
@typed_pos_args('subproject_options.add_cmake_defines', varargs=dict) |
| 210 |
@noKwargs |
| 211 |
def add_cmake_defines(self, state: ModuleState, args: T.Tuple[T.List[T.Dict[str, TYPE_var]]], kwargs: TYPE_kwargs) -> None: |
| 212 |
self.cmake_options += cmake_defines_to_args(args[0]) |
| 213 |
|
| 214 |
@typed_pos_args('subproject_options.set_override_option', str, str) |
| 215 |
@typed_kwargs('subproject_options.set_override_option', _TARGET_KW) |
| 216 |
def set_override_option(self, state: ModuleState, args: T.Tuple[str, str], kwargs: TargetKW) -> None: |
| 217 |
self._get_opts(kwargs).set_opt(args[0], args[1]) |
| 218 |
|
| 219 |
@typed_pos_args('subproject_options.set_install', bool) |
| 220 |
@typed_kwargs('subproject_options.set_install', _TARGET_KW) |
| 221 |
def set_install(self, state: ModuleState, args: T.Tuple[bool], kwargs: TargetKW) -> None: |
| 222 |
self._get_opts(kwargs).set_install(args[0]) |
| 223 |
|
| 224 |
@typed_pos_args('subproject_options.append_compile_args', str, varargs=str, min_varargs=1) |
| 225 |
@typed_kwargs('subproject_options.append_compile_args', _TARGET_KW) |
| 226 |
def append_compile_args(self, state: ModuleState, args: T.Tuple[str, T.List[str]], kwargs: TargetKW) -> None: |
| 227 |
self._get_opts(kwargs).append_args(args[0], args[1]) |
| 228 |
|
| 229 |
@typed_pos_args('subproject_options.append_link_args', varargs=str, min_varargs=1) |
| 230 |
@typed_kwargs('subproject_options.append_link_args', _TARGET_KW) |
| 231 |
def append_link_args(self, state: ModuleState, args: T.Tuple[T.List[str]], kwargs: TargetKW) -> None: |
| 232 |
self._get_opts(kwargs).append_link_args(args[0]) |
| 233 |
|
| 234 |
@noPosargs |
| 235 |
@noKwargs |
| 236 |
def clear(self, state: ModuleState, args: TYPE_var, kwargs: TYPE_kwargs) -> None: |
| 237 |
self.cmake_options.clear() |
| 238 |
self.target_options = TargetOptions() |
| 239 |
|
| 240 |
|
| 241 |
class CmakeModule(ExtensionModule): |
| 242 |
cmake_detected = False |
| 243 |
cmake_root: str |
| 244 |
|
| 245 |
INFO = ModuleInfo('cmake', '0.50.0') |
| 246 |
|
| 247 |
def __init__(self, interpreter: Interpreter) -> None: |
| 248 |
super().__init__(interpreter) |
| 249 |
self.methods.update({ |
| 250 |
'write_basic_package_version_file': self.write_basic_package_version_file, |
| 251 |
'configure_package_config_file': self.configure_package_config_file, |
| 252 |
'subproject': self.subproject, |
| 253 |
'subproject_options': self.subproject_options, |
| 254 |
}) |
| 255 |
|
| 256 |
def detect_voidp_size(self, env: Environment) -> int: |
| 257 |
compilers = env.coredata.compilers.host |
| 258 |
compiler = compilers.get('c', None) |
| 259 |
if not compiler: |
| 260 |
compiler = compilers.get('cpp', None) |
| 261 |
|
| 262 |
if not compiler: |
| 263 |
raise mesonlib.MesonException('Requires a C or C++ compiler to compute sizeof(void *).') |
| 264 |
|
| 265 |
return compiler.sizeof('void *', '')[0] |
| 266 |
|
| 267 |
def detect_cmake(self, state: ModuleState) -> bool: |
| 268 |
if self.cmake_detected: |
| 269 |
return True |
| 270 |
|
| 271 |
cmakebin = state.find_program('cmake', silent=False) |
| 272 |
if not cmakebin.found(): |
| 273 |
return False |
| 274 |
|
| 275 |
# Try different CMake generators since specifying no generator may fail |
| 276 |
# in cygwin for some reason |
| 277 |
for gen in CMakeDependency.class_cmake_generators: |
| 278 |
cmd = cmakebin.get_command() + ['--system-information'] |
| 279 |
if gen: |
| 280 |
cmd += ['-G', gen] |
| 281 |
p, stdout, stderr = mesonlib.Popen_safe(cmd)[0:3] |
| 282 |
if p.returncode == 0: |
| 283 |
break |
| 284 |
else: |
| 285 |
mlog.log(f'error retrieving cmake information: returnCode={p.returncode} stdout={stdout} stderr={stderr}') |
| 286 |
return False |
| 287 |
|
| 288 |
match = re.search('\nCMAKE_ROOT \\"([^"]+)"\n', stdout.strip()) |
| 289 |
if not match: |
| 290 |
mlog.log('unable to determine cmake root') |
| 291 |
return False |
| 292 |
|
| 293 |
cmakePath = pathlib.PurePath(match.group(1)) |
| 294 |
self.cmake_root = os.path.join(*cmakePath.parts) |
| 295 |
self.cmake_detected = True |
| 296 |
return True |
| 297 |
|
| 298 |
@noPosargs |
| 299 |
@typed_kwargs( |
| 300 |
'cmake.write_basic_package_version_file', |
| 301 |
KwargInfo('arch_independent', bool, default=False, since='0.62.0'), |
| 302 |
KwargInfo('compatibility', str, default='AnyNewerVersion', validator=in_set_validator(set(COMPATIBILITIES))), |
| 303 |
KwargInfo('name', str, required=True), |
| 304 |
KwargInfo('version', str, required=True), |
| 305 |
INSTALL_DIR_KW, |
| 306 |
) |
| 307 |
def write_basic_package_version_file(self, state: ModuleState, args: TYPE_var, kwargs: 'WriteBasicPackageVersionFile') -> ModuleReturnValue: |
| 308 |
arch_independent = kwargs['arch_independent'] |
| 309 |
compatibility = kwargs['compatibility'] |
| 310 |
name = kwargs['name'] |
| 311 |
version = kwargs['version'] |
| 312 |
|
| 313 |
if not self.detect_cmake(state): |
| 314 |
raise mesonlib.MesonException('Unable to find cmake') |
| 315 |
|
| 316 |
pkgroot = pkgroot_name = kwargs['install_dir'] |
| 317 |
if pkgroot is None: |
| 318 |
libdir = state.environment.coredata.optstore.get_value_for(OptionKey('libdir')) |
| 319 |
assert isinstance(libdir, str), 'for mypy' |
| 320 |
pkgroot = os.path.join(libdir, 'cmake', name) |
| 321 |
pkgroot_name = os.path.join('{libdir}', 'cmake', name) |
| 322 |
|
| 323 |
template_file = os.path.join(self.cmake_root, 'Modules', f'BasicConfigVersion-{compatibility}.cmake.in') |
| 324 |
if not os.path.exists(template_file): |
| 325 |
raise mesonlib.MesonException(f'your cmake installation doesn\'t support the {compatibility} compatibility') |
| 326 |
|
| 327 |
version_file = os.path.join(state.environment.scratch_dir, f'{name}ConfigVersion.cmake') |
| 328 |
|
| 329 |
conf: T.Dict[str, T.Union[str, bool, int]] = { |
| 330 |
'CVF_VERSION': version, |
| 331 |
'CMAKE_SIZEOF_VOID_P': str(self.detect_voidp_size(state.environment)), |
| 332 |
'CVF_ARCH_INDEPENDENT': arch_independent, |
| 333 |
} |
| 334 |
mesonlib.do_conf_file(template_file, version_file, build.ConfigurationData(conf), 'meson') |
| 335 |
|
| 336 |
res = build.Data([mesonlib.File(True, state.environment.get_scratch_dir(), version_file)], pkgroot, pkgroot_name, None, state.subproject) |
| 337 |
return ModuleReturnValue(res, [res]) |
| 338 |
|
| 339 |
def create_package_file(self, infile: str, outfile: str, PACKAGE_RELATIVE_PATH: str, extra: str, confdata: build.ConfigurationData) -> None: |
| 340 |
package_init = PACKAGE_INIT_BASE.replace('@PACKAGE_RELATIVE_PATH@', PACKAGE_RELATIVE_PATH) |
| 341 |
package_init = package_init.replace('@inputFileName@', os.path.basename(infile)) |
| 342 |
package_init += extra |
| 343 |
package_init += PACKAGE_INIT_SET_AND_CHECK |
| 344 |
|
| 345 |
try: |
| 346 |
with open(infile, encoding='utf-8') as fin: |
| 347 |
data = fin.readlines() |
| 348 |
except Exception as e: |
| 349 |
raise mesonlib.MesonException(f'Could not read input file {infile}: {e!s}') |
| 350 |
|
| 351 |
result = [] |
| 352 |
regex = mesonlib.get_variable_regex('cmake@') |
| 353 |
for line in data: |
| 354 |
line = line.replace('@PACKAGE_INIT@', package_init) |
| 355 |
line, _missing = mesonlib.do_replacement(regex, line, 'cmake@', confdata) |
| 356 |
|
| 357 |
result.append(line) |
| 358 |
|
| 359 |
outfile_tmp = outfile + "~" |
| 360 |
with open(outfile_tmp, "w", encoding='utf-8') as fout: |
| 361 |
fout.writelines(result) |
| 362 |
|
| 363 |
shutil.copymode(infile, outfile_tmp) |
| 364 |
mesonlib.replace_if_different(outfile, outfile_tmp) |
| 365 |
|
| 366 |
@noPosargs |
| 367 |
@typed_kwargs( |
| 368 |
'cmake.configure_package_config_file', |
| 369 |
KwargInfo('configuration', (build.ConfigurationData, dict), required=True), |
| 370 |
KwargInfo('input', |
| 371 |
(str, mesonlib.File, ContainerTypeInfo(list, mesonlib.File)), required=True, |
| 372 |
validator=lambda x: 'requires exactly one file' if isinstance(x, list) and len(x) != 1 else None, |
| 373 |
convertor=lambda x: x[0] if isinstance(x, list) else x), |
| 374 |
KwargInfo('name', str, required=True), |
| 375 |
INSTALL_DIR_KW, |
| 376 |
) |
| 377 |
def configure_package_config_file(self, state: ModuleState, args: TYPE_var, kwargs: 'ConfigurePackageConfigFile') -> build.Data: |
| 378 |
inputfile = kwargs['input'] |
| 379 |
if isinstance(inputfile, str): |
| 380 |
inputfile = mesonlib.File.from_source_file(state.environment.source_dir, state.subdir, inputfile) |
| 381 |
|
| 382 |
ifile_abs = inputfile.absolute_path(state.environment.source_dir, state.environment.build_dir) |
| 383 |
|
| 384 |
name = kwargs['name'] |
| 385 |
|
| 386 |
(ofile_path, ofile_fname) = os.path.split(os.path.join(state.subdir, f'{name}Config.cmake')) |
| 387 |
ofile_abs = os.path.join(state.environment.build_dir, ofile_path, ofile_fname) |
| 388 |
|
| 389 |
install_dir = kwargs['install_dir'] |
| 390 |
if install_dir is None: |
| 391 |
libdir = state.environment.coredata.optstore.get_value_for(OptionKey('libdir')) |
| 392 |
assert isinstance(libdir, str), 'for mypy' |
| 393 |
install_dir = os.path.join(libdir, 'cmake', name) |
| 394 |
|
| 395 |
conf = kwargs['configuration'] |
| 396 |
if isinstance(conf, dict): |
| 397 |
FeatureNew.single_use('cmake.configure_package_config_file dict as configuration', '0.62.0', state.subproject, location=state.current_node) |
| 398 |
conf = build.ConfigurationData(conf) |
| 399 |
|
| 400 |
prefix = state.environment.coredata.optstore.get_value_for(OptionKey('prefix')) |
| 401 |
assert isinstance(prefix, str), 'for mypy' |
| 402 |
abs_install_dir = install_dir |
| 403 |
if not os.path.isabs(abs_install_dir): |
| 404 |
abs_install_dir = os.path.join(prefix, install_dir) |
| 405 |
|
| 406 |
# path used in cmake scripts are POSIX even on Windows |
| 407 |
PACKAGE_RELATIVE_PATH = pathlib.PurePath(os.path.relpath(prefix, abs_install_dir)).as_posix() |
| 408 |
extra = '' |
| 409 |
if re.match('^(/usr)?/lib(64)?/.+', abs_install_dir): |
| 410 |
extra = PACKAGE_INIT_EXT.replace('@absInstallDir@', abs_install_dir) |
| 411 |
extra = extra.replace('@installPrefix@', prefix) |
| 412 |
|
| 413 |
self.create_package_file(ifile_abs, ofile_abs, PACKAGE_RELATIVE_PATH, extra, conf) |
| 414 |
conf.used = True |
| 415 |
|
| 416 |
conffile = os.path.normpath(inputfile.relative_name()) |
| 417 |
self.interpreter.build_def_files.add(conffile) |
| 418 |
|
| 419 |
res = build.Data([mesonlib.File(True, ofile_path, ofile_fname)], install_dir, install_dir, None, state.subproject) |
| 420 |
self.interpreter.build.data.append(res) |
| 421 |
|
| 422 |
return res |
| 423 |
|
| 424 |
@FeatureNew('subproject', '0.51.0') |
| 425 |
@typed_pos_args('cmake.subproject', str) |
| 426 |
@typed_kwargs( |
| 427 |
'cmake.subproject', |
| 428 |
REQUIRED_KW, |
| 429 |
NATIVE_KW.evolve(since='1.12.0'), |
| 430 |
KwargInfo('options', (CMakeSubprojectOptions, NoneType), since='0.55.0'), |
| 431 |
KwargInfo( |
| 432 |
'cmake_options', |
| 433 |
ContainerTypeInfo(list, str), |
| 434 |
default=[], |
| 435 |
listify=True, |
| 436 |
deprecated='0.55.0', |
| 437 |
deprecated_message='Use options instead', |
| 438 |
), |
| 439 |
) |
| 440 |
def subproject(self, state: ModuleState, args: T.Tuple[str], kwargs_: Subproject) -> T.Union[SubprojectHolder, CMakeSubproject]: |
| 441 |
if kwargs_['cmake_options'] and kwargs_['options'] is not None: |
| 442 |
raise InterpreterException('"options" cannot be used together with "cmake_options"') |
| 443 |
subp_name = mesonlib.SubProject(args[0]) |
| 444 |
kw: kwargs.DoSubproject = { |
| 445 |
'required': kwargs_['required'], |
| 446 |
'options': kwargs_['options'], |
| 447 |
'cmake_options': kwargs_['cmake_options'], |
| 448 |
'default_options': {}, |
| 449 |
'version': [], |
| 450 |
'for_machine': kwargs_['native'], |
| 451 |
} |
| 452 |
subp = self.interpreter.do_subproject(subp_name, kw, force_method='cmake') |
| 453 |
if not subp.found(): |
| 454 |
return subp |
| 455 |
return CMakeSubproject(subp) |
| 456 |
|
| 457 |
@FeatureNew('subproject_options', '0.55.0') |
| 458 |
@noKwargs |
| 459 |
@noPosargs |
| 460 |
def subproject_options(self, state: ModuleState, args: TYPE_var, kwargs: TYPE_kwargs) -> CMakeSubprojectOptions: |
| 461 |
return CMakeSubprojectOptions() |
| 462 |
|
| 463 |
def initialize(interp: Interpreter) -> CmakeModule: |
| 464 |
return CmakeModule(interp) |