aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-02-18 15:03:21 -0800
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2020-02-19 07:07:35 +0530
commit73ddc014774102b378bb89bf9d4801d7b231b745 (patch)
tree1f478c6cb10c9ece2ec81d979be9b38e31c07223
parent52d36aaec13966b68994764191c8881edc92291e (diff)
downloadmeson-73ddc014774102b378bb89bf9d4801d7b231b745.zip
meson-73ddc014774102b378bb89bf9d4801d7b231b745.tar.gz
meson-73ddc014774102b378bb89bf9d4801d7b231b745.tar.bz2
modules/cmake: Add a found() method to the cmake subproject
Just like the native meson subproject has.
-rw-r--r--docs/markdown/CMake-module.md2
-rw-r--r--mesonbuild/modules/cmake.py8
-rw-r--r--test cases/cmake/1 basic/meson.build1
-rw-r--r--test cases/cmake/9 disabled subproject/meson.build3
4 files changed, 13 insertions, 1 deletions
diff --git a/docs/markdown/CMake-module.md b/docs/markdown/CMake-module.md
index a021396..a15e3c2 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 03176d8..6c4098b 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 8e1671a..19c87c4 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 ba38410..c153fa3 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')