modules/cmake: Add a found() method to the cmake subproject

Just like the native meson subproject has.
pull/6603/head
Dylan Baker 5 years ago committed by Nirbheek Chauhan
parent 52d36aaec1
commit 73ddc01477
  1. 2
      docs/markdown/CMake-module.md
  2. 8
      mesonbuild/modules/cmake.py
  3. 1
      test cases/cmake/1 basic/meson.build
  4. 1
      test cases/cmake/9 disabled subproject/meson.build

@ -99,6 +99,8 @@ and supports the following methods:
- `get_variable(name)` fetches the specified variable from inside - `get_variable(name)` fetches the specified variable from inside
the subproject. Usually `dependency()` or `target()` should be the subproject. Usually `dependency()` or `target()` should be
preferred to extract build targets. preferred to extract build targets.
- `found` returns true if the subproject is available, otherwise false
*new in in 0.53.2*
## CMake configuration files ## CMake configuration files

@ -66,6 +66,7 @@ class CMakeSubprojectHolder(InterpreterObject, ObjectHolder):
'target': self.target, 'target': self.target,
'target_type': self.target_type, 'target_type': self.target_type,
'target_list': self.target_list, 'target_list': self.target_list,
'found': self.found_method,
}) })
def _args_to_info(self, args): def _args_to_info(self, args):
@ -110,6 +111,13 @@ class CMakeSubprojectHolder(InterpreterObject, ObjectHolder):
def target_list(self, args, kwargs): def target_list(self, args, kwargs):
return self.held_object.cm_interpreter.target_list() 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): class CmakeModule(ExtensionModule):
cmake_detected = False cmake_detected = False
cmake_root = None cmake_root = None

@ -5,6 +5,7 @@ cm = import('cmake')
sub_pro = cm.subproject('cmMod') sub_pro = cm.subproject('cmMod')
sub_dep = sub_pro.dependency('cmModLib++') 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_list() == ['cmModLib++'], 'There should be exactly one target')
assert(sub_pro.target_type('cmModLib++') == 'shared_library', 'Target type should be shared_library') assert(sub_pro.target_type('cmModLib++') == 'shared_library', 'Target type should be shared_library')

@ -3,3 +3,4 @@ project('cmakeSubTest', ['c', 'cpp'])
cm = import('cmake') cm = import('cmake')
sub_pro = cm.subproject('nothinig', required: false) sub_pro = cm.subproject('nothinig', required: false)
assert(not sub_pro.found(), 'subproject found() reports wrong value')

Loading…
Cancel
Save