From e36f713a7f5cc10d3f8adc7ae1c73ef6cce51082 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Tue, 13 Oct 2020 16:47:23 +0200 Subject: include_type: Add CMake subporject dependency method (fixes #6879) --- docs/markdown/CMake-module.md | 5 ++++- docs/markdown/snippets/cmake_include_type.md | 5 +++++ mesonbuild/modules/cmake.py | 13 ++++++++++--- test cases/cmake/1 basic/meson.build | 3 ++- 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 docs/markdown/snippets/cmake_include_type.md diff --git a/docs/markdown/CMake-module.md b/docs/markdown/CMake-module.md index 48c3d75..f811ab4 100644 --- a/docs/markdown/CMake-module.md +++ b/docs/markdown/CMake-module.md @@ -133,7 +133,10 @@ kept for compatibility. It will not work together with the `options` kwarg. This object is returned by the `subproject` function described above and supports the following methods: - - `dependency(target)` returns a dependency object for any CMake target. + - `dependency(target)` returns a dependency object for any CMake target. The + `include_type` kwarg *(new in 0.56.0)* controls the include type of the + returned dependency object similar to the same kwarg in the + [`dependency()`](Reference-manual.md#dependency) function. - `include_directories(target)` returns a meson `include_directories()` object for the specified target. Using this function is not necessary if the dependency object is used. diff --git a/docs/markdown/snippets/cmake_include_type.md b/docs/markdown/snippets/cmake_include_type.md new file mode 100644 index 0000000..f8637c0 --- /dev/null +++ b/docs/markdown/snippets/cmake_include_type.md @@ -0,0 +1,5 @@ +## `include_type` support for the CMake subproject object dependency method + +The `dependency()` method of the CMake subproject object now also supports the +`include_type` kwarg which is similar to the sane kwarg in the `dependency()` +function. diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py index 2383753..35c85a7 100644 --- a/mesonbuild/modules/cmake.py +++ b/mesonbuild/modules/cmake.py @@ -20,7 +20,7 @@ from . import ExtensionModule, ModuleReturnValue from .. import build, dependencies, mesonlib, mlog from ..cmake import SingleTargetOptions, TargetOptions, cmake_defines_to_args -from ..interpreter import ConfigurationDataHolder, InterpreterException, SubprojectHolder +from ..interpreter import ConfigurationDataHolder, InterpreterException, SubprojectHolder, DependencyHolder from ..interpreterbase import ( InterpreterObject, ObjectHolder, @@ -105,11 +105,18 @@ class CMakeSubprojectHolder(InterpreterObject, ObjectHolder): def get_variable(self, args, kwargs): return self.held_object.get_variable_method(args, kwargs) - @noKwargs + @FeatureNewKwargs('dependency', '0.56.0', ['include_type']) + @permittedKwargs({'include_type'}) @stringArgs def dependency(self, args, kwargs): info = self._args_to_info(args) - return self.get_variable([info['dep']], kwargs) + orig = self.get_variable([info['dep']], {}) + assert isinstance(orig, DependencyHolder) + actual = orig.include_type_method([], {}) + if 'include_type' in kwargs and kwargs['include_type'] != actual: + mlog.debug('Current include type is {}. Converting to requested {}'.format(actual, kwargs['include_type'])) + return orig.as_system_method([kwargs['include_type']], {}) + return orig @noKwargs @stringArgs diff --git a/test cases/cmake/1 basic/meson.build b/test cases/cmake/1 basic/meson.build index 19c87c4..2464739 100644 --- a/test cases/cmake/1 basic/meson.build +++ b/test cases/cmake/1 basic/meson.build @@ -3,11 +3,12 @@ project('cmakeSubTest', ['c', 'cpp']) cm = import('cmake') sub_pro = cm.subproject('cmMod') -sub_dep = sub_pro.dependency('cmModLib++') +sub_dep = sub_pro.dependency('cmModLib++', include_type: 'system') assert(sub_pro.found(), 'found() method reports not found, but should be found') assert(sub_pro.target_list() == ['cmModLib++'], 'There should be exactly one target') assert(sub_pro.target_type('cmModLib++') == 'shared_library', 'Target type should be shared_library') +assert(sub_dep.include_type() == 'system', 'the include_type kwarg of dependency() works') exe1 = executable('main', ['main.cpp'], dependencies: [sub_dep]) test('test1', exe1) -- cgit v1.1