Can use plain strings for include_directories.

pull/4711/head
Jussi Pakkanen 6 years ago
parent 6c76ac8017
commit 3a6e2aeed9
  1. 6
      docs/markdown/Reference-manual.md
  2. 16
      docs/markdown/snippets/includestr.md
  3. 17
      mesonbuild/interpreter.py
  4. 3
      test cases/common/19 includedir/src/meson.build
  5. 2
      test cases/common/84 declare dep/entity/meson.build

@ -349,7 +349,8 @@ keyword arguments.
- `compile_args`, compile arguments to use
- `dependencies`, other dependencies needed to use this dependency
- `include_directories`, the directories to add to header search path
- `include_directories`, the directories to add to header search path,
must be include_directories objects or, since 0.50.0, plain strings
- `link_args`, link arguments to use
- `link_with`, libraries to link against
- `link_whole`, libraries to link fully, same as [`executable`](#executable)
@ -530,7 +531,8 @@ be passed to [shared and static libraries](#library).
adds the current source and build directories to the include path,
defaults to `true`, since 0.42.0
- `include_directories` one or more objects created with the
`include_directories` function
`include_directories` function, or, since 0.50.0, strings, which
will be transparently expanded to include directory objects
- `install`, when set to true, this executable should be installed
- `install_dir` override install directory for this file. The value is
relative to the `prefix` specified. F.ex, if you want to install

@ -0,0 +1,16 @@
## `include_directories` accepts a string
The `include_directories` keyword argument now accepts plain strings
rather than an include directory object. Meson will transparently
expand it so that a declaration like this:
```meson
executable(..., include_directories: 'foo')
```
Is equivalent to this:
```meson
foo_inc = include_directories('foo')
executable(..., include_directories: inc)
```

@ -2209,7 +2209,7 @@ class Interpreter(InterpreterBase):
version = kwargs.get('version', self.project_version)
if not isinstance(version, str):
raise InterpreterException('Version must be a string.')
incs = extract_as_list(kwargs, 'include_directories', unholder=True)
incs = self.entries_to_incdirs(extract_as_list(kwargs, 'include_directories', unholder=True))
libs = extract_as_list(kwargs, 'link_with', unholder=True)
libs_whole = extract_as_list(kwargs, 'link_whole', unholder=True)
sources = extract_as_list(kwargs, 'sources')
@ -3708,6 +3708,19 @@ This will become a hard error in the future.''' % kwargs['input'])
self.build.data.append(build.Data([cfile], idir, install_mode))
return mesonlib.File.from_built_file(self.subdir, output)
def entries_to_incdirs(self, prospectives):
if not isinstance(prospectives, list):
return self.entries_to_incdirs([prospectives])[0]
result = []
for p in prospectives:
if isinstance(p, (IncludeDirsHolder, build.IncludeDirs)):
result.append(p)
elif isinstance(p, str):
result.append(self.build_incdir_object([p]))
else:
raise InterpreterException('Include directory objects can only be created from strings or include directories.')
return result
@permittedKwargs(permitted_kwargs['include_directories'])
@stringArgs
def func_include_directories(self, node, args, kwargs):
@ -4069,6 +4082,8 @@ Try setting b_lundef to false instead.'''.format(self.coredata.base_options['b_s
# passed to library() when default_library == 'static'.
kwargs = {k: v for k, v in kwargs.items() if k in targetclass.known_kwargs}
if 'include_directories' in kwargs:
kwargs['include_directories'] = self.entries_to_incdirs(kwargs['include_directories'])
target = targetclass(name, self.subdir, self.subproject, is_cross, sources, objs, self.environment, kwargs)
if is_cross:

@ -1,2 +1,5 @@
exe = executable('prog', 'prog.c', 'func.c', include_directories : inc)
test('inc test', exe)
exe2 = executable('prog2', 'prog.c', 'func.c', include_directories : '../include')
test('inc test 2', exe2)

@ -1,7 +1,7 @@
entity_lib = static_library('entity', 'entity1.c')
entity_dep = declare_dependency(link_with : [[entity_lib]],
include_directories : include_directories('.'),
include_directories : '.',
sources : 'entity2.c',
compile_args : ['-DUSING_ENT=1'],
version : '1.2.3',

Loading…
Cancel
Save