preprocess: Add dependencies kwarg

pull/10930/head
Xavier Claessens 2 years ago committed by Xavier Claessens
parent c2a55bfe43
commit d21b64487e
  1. 6
      docs/markdown/snippets/preprocess.md
  2. 4
      docs/yaml/objects/compiler.yaml
  3. 3
      mesonbuild/interpreter/compiler.py
  4. 2
      test cases/common/259 preprocess/bar.c
  5. 4
      test cases/common/259 preprocess/meson.build

@ -0,0 +1,6 @@
## compiler.preprocess()
Dependencies keyword argument can now be passed to `compiler.preprocess()` to
add include directories or compiler arguments.
Generated sources such as custom targets are now allowed too.

@ -617,3 +617,7 @@ methods:
type: list[str] type: list[str]
description: | description: |
Extra flags to pass to the preprocessor Extra flags to pass to the preprocessor
dependencies:
type: dep | list[dep]
description: Additionally dependencies required.
since: 1.1.0

@ -87,6 +87,7 @@ if T.TYPE_CHECKING:
output: str output: str
compile_args: T.List[str] compile_args: T.List[str]
include_directories: T.List[build.IncludeDirs] include_directories: T.List[build.IncludeDirs]
dependencies: T.List[dependencies.Dependency]
class _TestMode(enum.Enum): class _TestMode(enum.Enum):
@ -760,6 +761,7 @@ class CompilerHolder(ObjectHolder['Compiler']):
KwargInfo('output', str, default='@PLAINNAME@.i'), KwargInfo('output', str, default='@PLAINNAME@.i'),
KwargInfo('compile_args', ContainerTypeInfo(list, str), listify=True, default=[]), KwargInfo('compile_args', ContainerTypeInfo(list, str), listify=True, default=[]),
_INCLUDE_DIRS_KW, _INCLUDE_DIRS_KW,
_DEPENDENCIES_KW.evolve(since='1.1.0'),
) )
def preprocess_method(self, args: T.Tuple[T.List['mesonlib.FileOrString']], kwargs: 'PreprocessKW') -> T.List[build.CustomTargetIndex]: def preprocess_method(self, args: T.Tuple[T.List['mesonlib.FileOrString']], kwargs: 'PreprocessKW') -> T.List[build.CustomTargetIndex]:
compiler = self.compiler.get_preprocessor() compiler = self.compiler.get_preprocessor()
@ -771,6 +773,7 @@ class CompilerHolder(ObjectHolder['Compiler']):
f'{self.compiler.language}_args': kwargs['compile_args'], f'{self.compiler.language}_args': kwargs['compile_args'],
'build_by_default': False, 'build_by_default': False,
'include_directories': kwargs['include_directories'], 'include_directories': kwargs['include_directories'],
'dependencies': kwargs['dependencies'],
} }
tg_name = f'preprocessor_{next(self.preprocess_uid)}' tg_name = f'preprocessor_{next(self.preprocess_uid)}'
tg = build.CompileTarget( tg = build.CompileTarget(

@ -1,3 +1,3 @@
int @BAR@(void) { int @BAR@(void) {
return BAR; return BAR + PLOP;
} }

@ -13,7 +13,9 @@ bar_c = custom_target(
capture: true, capture: true,
) )
pp_files = cc.preprocess('foo.c', bar_c, output: '@PLAINNAME@') dep = declare_dependency(compile_args: '-DPLOP=0')
pp_files = cc.preprocess('foo.c', bar_c, output: '@PLAINNAME@', dependencies: dep)
foreach f : pp_files foreach f : pp_files
message(f.full_path()) message(f.full_path())

Loading…
Cancel
Save