From 73ddc014774102b378bb89bf9d4801d7b231b745 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 18 Feb 2020 15:03:21 -0800 Subject: [PATCH] modules/cmake: Add a found() method to the cmake subproject Just like the native meson subproject has. --- docs/markdown/CMake-module.md | 2 ++ mesonbuild/modules/cmake.py | 8 ++++++++ test cases/cmake/1 basic/meson.build | 1 + test cases/cmake/9 disabled subproject/meson.build | 3 ++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/markdown/CMake-module.md b/docs/markdown/CMake-module.md index a02139644..a15e3c223 100644 --- a/docs/markdown/CMake-module.md +++ b/docs/markdown/CMake-module.md @@ -99,6 +99,8 @@ and supports the following methods: - `get_variable(name)` fetches the specified variable from inside the subproject. Usually `dependency()` or `target()` should be preferred to extract build targets. + - `found` returns true if the subproject is available, otherwise false + *new in in 0.53.2* ## CMake configuration files diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py index 03176d8a6..6c4098baa 100644 --- a/mesonbuild/modules/cmake.py +++ b/mesonbuild/modules/cmake.py @@ -66,6 +66,7 @@ class CMakeSubprojectHolder(InterpreterObject, ObjectHolder): 'target': self.target, 'target_type': self.target_type, 'target_list': self.target_list, + 'found': self.found_method, }) def _args_to_info(self, args): @@ -110,6 +111,13 @@ class CMakeSubprojectHolder(InterpreterObject, ObjectHolder): def target_list(self, args, kwargs): return self.held_object.cm_interpreter.target_list() + @noPosargs + @permittedKwargs({}) + @FeatureNew('CMakeSubproject.found()', '0.53.2') + def found_method(self, args, kwargs): + return self.held_object is not None + + class CmakeModule(ExtensionModule): cmake_detected = False cmake_root = None diff --git a/test cases/cmake/1 basic/meson.build b/test cases/cmake/1 basic/meson.build index 8e1671a33..19c87c441 100644 --- a/test cases/cmake/1 basic/meson.build +++ b/test cases/cmake/1 basic/meson.build @@ -5,6 +5,7 @@ cm = import('cmake') sub_pro = cm.subproject('cmMod') sub_dep = sub_pro.dependency('cmModLib++') +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') diff --git a/test cases/cmake/9 disabled subproject/meson.build b/test cases/cmake/9 disabled subproject/meson.build index ba38410d6..c153fa3a3 100644 --- a/test cases/cmake/9 disabled subproject/meson.build +++ b/test cases/cmake/9 disabled subproject/meson.build @@ -2,4 +2,5 @@ project('cmakeSubTest', ['c', 'cpp']) cm = import('cmake') -sub_pro = cm.subproject('nothinig', required: false) \ No newline at end of file +sub_pro = cm.subproject('nothinig', required: false) +assert(not sub_pro.found(), 'subproject found() reports wrong value')