diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2019-07-24 18:46:13 +0400 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-08-04 21:44:52 +0300 |
commit | 8ba14057421928b15a485214ac7023d246bfab7c (patch) | |
tree | 108c5faf51aa12b29c9a285e60e7a8ff13d57d3d | |
parent | 940ebd658b9e7bf1679bd8fbfbcb6b429d80424a (diff) | |
download | meson-8ba14057421928b15a485214ac7023d246bfab7c.zip meson-8ba14057421928b15a485214ac7023d246bfab7c.tar.gz meson-8ba14057421928b15a485214ac7023d246bfab7c.tar.bz2 |
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.
-rw-r--r-- | docs/markdown/SourceSet-module.md | 11 | ||||
-rw-r--r-- | docs/markdown/snippets/source_set_enhancements.md | 4 | ||||
-rw-r--r-- | mesonbuild/modules/sourceset.py | 9 | ||||
-rw-r--r-- | test cases/common/222 source set realistic example/meson.build | 8 | ||||
-rw-r--r-- | test cases/common/222 source set realistic example/zlib.cc | 6 |
5 files changed, 33 insertions, 5 deletions
diff --git a/docs/markdown/SourceSet-module.md b/docs/markdown/SourceSet-module.md index fee643a..4b34ff7 100644 --- a/docs/markdown/SourceSet-module.md +++ b/docs/markdown/SourceSet-module.md @@ -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 diff --git a/docs/markdown/snippets/source_set_enhancements.md b/docs/markdown/snippets/source_set_enhancements.md new file mode 100644 index 0000000..08e0ae3 --- /dev/null +++ b/docs/markdown/snippets/source_set_enhancements.md @@ -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. diff --git a/mesonbuild/modules/sourceset.py b/mesonbuild/modules/sourceset.py index fc46a7a..a14bd70 100644 --- a/mesonbuild/modules/sourceset.py +++ b/mesonbuild/modules/sourceset.py @@ -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: diff --git a/test cases/common/222 source set realistic example/meson.build b/test cases/common/222 source set realistic example/meson.build index 2a9475a..ea91e29 100644 --- a/test cases/common/222 source set realistic example/meson.build +++ b/test cases/common/222 source set realistic example/meson.build @@ -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' } diff --git a/test cases/common/222 source set realistic example/zlib.cc b/test cases/common/222 source set realistic example/zlib.cc index 909d744..434e0b7 100644 --- a/test cases/common/222 source set realistic example/zlib.cc +++ b/test cases/common/222 source set realistic example/zlib.cc @@ -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; |