diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-02-21 16:49:41 +0100 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-06-06 18:27:01 +0200 |
commit | e1863719cb7b72630dba885ac5c6dd19c758619f (patch) | |
tree | 30ce66fd22f778459e59087e2cd7541ad0bc8b60 /mesonbuild/dependencies/base.py | |
parent | a9a3b3ffe6bb13d03799070ef551c56645f51527 (diff) | |
download | meson-e1863719cb7b72630dba885ac5c6dd19c758619f.zip meson-e1863719cb7b72630dba885ac5c6dd19c758619f.tar.gz meson-e1863719cb7b72630dba885ac5c6dd19c758619f.tar.bz2 |
cmake: Made CMake executable finding availiable for other functions
Diffstat (limited to 'mesonbuild/dependencies/base.py')
-rw-r--r-- | mesonbuild/dependencies/base.py | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index a6fb0b6..9a14232 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -1059,10 +1059,43 @@ class CMakeDependency(ExternalDependency): # List of successfully found modules self.found_modules = [] + self.cmakebin, self.cmakevers, for_machine = self.find_cmake_binary(environment, self.want_cross, self.silent) + if self.cmakebin is False: + self.cmakebin = None + msg = 'No CMake binary for machine %s not found. Giving up.' % for_machine + if self.required: + raise DependencyException(msg) + mlog.debug(msg) + return + + if CMakeDependency.class_cmakeinfo[for_machine] is None: + CMakeDependency.class_cmakeinfo[for_machine] = self._get_cmake_info() + self.cmakeinfo = CMakeDependency.class_cmakeinfo[for_machine] + if self.cmakeinfo is None: + raise self._gen_exception('Unable to obtain CMake system information') + + modules = [(x, True) for x in stringlistify(extract_as_list(kwargs, 'modules'))] + modules += [(x, False) for x in stringlistify(extract_as_list(kwargs, 'optional_modules'))] + cm_path = stringlistify(extract_as_list(kwargs, 'cmake_module_path')) + cm_path = [x if os.path.isabs(x) else os.path.join(environment.get_source_dir(), x) for x in cm_path] + cm_args = stringlistify(extract_as_list(kwargs, 'cmake_args')) + if cm_path: + cm_args.append('-DCMAKE_MODULE_PATH=' + ';'.join(cm_path)) + + pref_path = self.env.coredata.builtins_per_machine[for_machine]['cmake_prefix_path'].value + if pref_path: + cm_args.append('-DCMAKE_PREFIX_PATH={}'.format(';'.join(pref_path))) + + if not self._preliminary_find_check(name, cm_path, pref_path, environment.machines[for_machine]): + return + self._detect_dep(name, modules, cm_args) + + @staticmethod + def find_cmake_binary(environment: Environment, want_cross: bool = False, silent: bool = False) -> Tuple[str, str, MachineChoice]: # When finding dependencies for cross-compiling, we don't care about # the 'native' CMake binary # TODO: Test if this works as expected - if environment.is_cross_build() and not self.want_cross: + if environment.is_cross_build() and not want_cross: for_machine = MachineChoice.BUILD else: for_machine = MachineChoice.HOST @@ -1097,54 +1130,24 @@ class CMakeDependency(ExternalDependency): for potential_cmakebin in search(): mlog.debug('Trying CMake binary {} for machine {} at {}' .format(potential_cmakebin.name, for_machine, potential_cmakebin.command)) - version_if_ok = self.check_cmake(potential_cmakebin) + version_if_ok = CMakeDependency.check_cmake(potential_cmakebin) if not version_if_ok: continue - if not self.silent: + if not silent: mlog.log('Found CMake:', mlog.bold(potential_cmakebin.get_path()), '(%s)' % version_if_ok) CMakeDependency.class_cmakebin[for_machine] = potential_cmakebin CMakeDependency.class_cmakevers[for_machine] = version_if_ok break else: - if not self.silent: + if not silent: mlog.log('Found CMake:', mlog.red('NO')) # Set to False instead of None to signify that we've already # searched for it and not found it CMakeDependency.class_cmakebin[for_machine] = False CMakeDependency.class_cmakevers[for_machine] = None - self.cmakebin = CMakeDependency.class_cmakebin[for_machine] - self.cmakevers = CMakeDependency.class_cmakevers[for_machine] - if self.cmakebin is False: - self.cmakebin = None - msg = 'No CMake binary for machine %s not found. Giving up.' % for_machine - if self.required: - raise DependencyException(msg) - mlog.debug(msg) - return - - if CMakeDependency.class_cmakeinfo[for_machine] is None: - CMakeDependency.class_cmakeinfo[for_machine] = self._get_cmake_info() - self.cmakeinfo = CMakeDependency.class_cmakeinfo[for_machine] - if self.cmakeinfo is None: - raise self._gen_exception('Unable to obtain CMake system information') - - modules = [(x, True) for x in stringlistify(extract_as_list(kwargs, 'modules'))] - modules += [(x, False) for x in stringlistify(extract_as_list(kwargs, 'optional_modules'))] - cm_path = stringlistify(extract_as_list(kwargs, 'cmake_module_path')) - cm_path = [x if os.path.isabs(x) else os.path.join(environment.get_source_dir(), x) for x in cm_path] - cm_args = stringlistify(extract_as_list(kwargs, 'cmake_args')) - if cm_path: - cm_args.append('-DCMAKE_MODULE_PATH=' + ';'.join(cm_path)) - - pref_path = self.env.coredata.builtins_per_machine[for_machine]['cmake_prefix_path'].value - if pref_path: - cm_args.append('-DCMAKE_PREFIX_PATH={}'.format(';'.join(pref_path))) - - if not self._preliminary_find_check(name, cm_path, pref_path, environment.machines[for_machine]): - return - self._detect_dep(name, modules, cm_args) + return CMakeDependency.class_cmakebin[for_machine], CMakeDependency.class_cmakevers[for_machine], for_machine def __repr__(self): s = '<{0} {1}: {2} {3}>' @@ -1841,7 +1844,8 @@ set(CMAKE_SIZEOF_VOID_P "{}") def get_methods(): return [DependencyMethods.CMAKE] - def check_cmake(self, cmakebin): + @staticmethod + def check_cmake(cmakebin): if not cmakebin.found(): mlog.log('Did not find CMake {!r}'.format(cmakebin.name)) return None |