sourceset: add all_dependencies() method

'if_true' sources should be built with their dependencies, as
illustrated by test case change.

Ideally, I think we would want only the files with the dependencies to
be built with the flags, but that would probably change the way
sourceset are used.
pull/5769/head
Marc-André Lureau 6 years ago committed by Jussi Pakkanen
parent 940ebd658b
commit 8ba1405742
  1. 11
      docs/markdown/SourceSet-module.md
  2. 4
      docs/markdown/snippets/source_set_enhancements.md
  3. 9
      mesonbuild/modules/sourceset.py
  4. 8
      test cases/common/222 source set realistic example/meson.build
  5. 6
      test cases/common/222 source set realistic example/zlib.cc

@ -149,6 +149,17 @@ sources are included (if any).
**Returns**: a list of file objects
#### `all_dependencies()` *(since 0.52.0)*
``` meson
list source_set.all_dependencies(...)
```
Returns a list of all dependencies that were placed in the source set
using `add` (including nested source sets) and that were found.
**Returns**: a list of dependencies
#### `apply()`
``` meson

@ -0,0 +1,4 @@
## Enhancements to the source_set module
`SourceSet` objects now provide the `all_dependencies()` method, that
complement the existing `all_sources()` method.

@ -41,6 +41,7 @@ class SourceSetHolder(MutableInterpreterObject, ObjectHolder):
'add': self.add_method,
'add_all': self.add_all_method,
'all_sources': self.all_sources_method,
'all_dependencies': self.all_dependencies_method,
'apply': self.apply_method,
})
@ -131,6 +132,14 @@ class SourceSetHolder(MutableInterpreterObject, ObjectHolder):
files = self.collect(lambda x: True, True)
return list(files.sources)
@noKwargs
@noPosargs
@FeatureNew('source_set.all_dependencies() method', '0.52.0')
def all_dependencies_method(self, args, kwargs):
self.frozen = True
files = self.collect(lambda x: True, True)
return list(files.dependencies)
@permittedKwargs(['strict'])
def apply_method(self, args, kwargs):
if len(args) != 1:

@ -11,14 +11,15 @@ endif
ss = import('sourceset')
kconfig = import('unstable-kconfig')
zlib = dependency('zlib', version : '>=1.2.8', required: false)
zlib = declare_dependency(compile_args: '-DZLIB=1')
another = declare_dependency(compile_args: '-DANOTHER=1')
not_found = dependency('not-found', required: false)
common = ss.source_set()
specific = ss.source_set()
common.add(files('main.cc'))
common.add(when: zlib, if_true: files('zlib.cc'))
common.add(when: [zlib, another], if_true: files('zlib.cc'))
common.add(when: not_found,
if_true: files('was-found.cc'),
if_false: files('not-found.cc'))
@ -31,7 +32,8 @@ if meson.is_unity()
common = ss.source_set()
endif
common_lib = static_library('common', common.all_sources())
common_lib = static_library('common', common.all_sources(),
dependencies: common.all_dependencies())
targets = [ 'arm', 'aarch64', 'x86' ]
target_dirs = { 'arm' : 'arm', 'aarch64' : 'arm', 'x86': 'x86' }

@ -6,8 +6,10 @@ struct ZLibDependency : Dependency {
};
void ZLibDependency::initialize() {
std::cout << ANSI_START << "hello from zlib"
<< ANSI_END << std::endl;
if (ZLIB && ANOTHER) {
std::cout << ANSI_START << "hello from zlib"
<< ANSI_END << std::endl;
}
}
ZLibDependency zlib;

Loading…
Cancel
Save