diff --git a/docs/markdown/snippets/hdf5_dependnecy_improvements.md b/docs/markdown/snippets/hdf5_dependnecy_improvements.md index 1f6b2e88f..857eb90e4 100644 --- a/docs/markdown/snippets/hdf5_dependnecy_improvements.md +++ b/docs/markdown/snippets/hdf5_dependnecy_improvements.md @@ -4,3 +4,6 @@ HDF5 has been improved so that the internal representations have been split. This allows selecting pkg-config and config-tool dependencies separately. Both work as proper dependencies of their type, so `get_variable` and similar now work correctly. + +It has also been fixed to use the selected compiler for the build instead of +the default compiler. diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 5827a4ef1..a6cfd5bf2 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -390,7 +390,7 @@ class CoreData: ) # type: PerMachine[T.defaultdict[str, OptionDictType]] self.base_options = {} # type: OptionDictType self.cross_files = self.__load_config_files(options, scratch_dir, 'cross') - self.compilers = PerMachine(OrderedDict(), OrderedDict()) + self.compilers = PerMachine(OrderedDict(), OrderedDict()) # type: PerMachine[T.Dict[str, Compiler]] build_cache = DependencyCache(self.builtins_per_machine, MachineChoice.BUILD) host_cache = DependencyCache(self.builtins_per_machine, MachineChoice.BUILD) diff --git a/mesonbuild/dependencies/hdf5.py b/mesonbuild/dependencies/hdf5.py index 10bdb2529..21f4e71f5 100644 --- a/mesonbuild/dependencies/hdf5.py +++ b/mesonbuild/dependencies/hdf5.py @@ -15,12 +15,13 @@ # This file contains the detection logic for miscellaneous external dependencies. import functools -import subprocess -import shutil +import os import re +import shutil +import subprocess from pathlib import Path -from ..mesonlib import OrderedSet +from ..mesonlib import OrderedSet, join_args from .base import ( DependencyException, DependencyMethods, ConfigToolDependency, PkgConfigDependency, factory_methods @@ -94,10 +95,13 @@ class HDF5ConfigToolDependency(ConfigToolDependency): raise DependencyException('Language {} is not supported with HDF5.'.format(language)) if language == 'c': + cenv = 'CC' tools = ['h5cc'] elif language == 'cpp': + cenv = 'CXX' tools = ['h5c++'] elif language == 'fortran': + cenv = 'FC' tools = ['h5fc'] else: raise DependencyException('How did you get here?') @@ -108,7 +112,17 @@ class HDF5ConfigToolDependency(ConfigToolDependency): nkwargs = kwargs.copy() nkwargs['tools'] = tools - super().__init__(name, environment, nkwargs, language) + # Override the compiler that the config tools are going to use by + # setting the environment variables that they use for the compiler and + # linkers. + compiler = environment.coredata.compilers[for_machine][language] + try: + os.environ['HDF5_{}'.format(cenv)] = join_args(compiler.get_exelist()) + os.environ['HDF5_{}LINKER'.format(cenv)] = join_args(compiler.get_linker_exelist()) + super().__init__(name, environment, nkwargs, language) + finally: + del os.environ['HDF5_{}'.format(cenv)] + del os.environ['HDF5_{}LINKER'.format(cenv)] if not self.is_found: return @@ -126,7 +140,7 @@ class HDF5ConfigToolDependency(ConfigToolDependency): nkwargs = kwargs.copy() nkwargs['language'] = 'c' # I'm being too clever for mypy and pylint - self.is_found = self._add_sub_dependency(hdf5_factory(environment, self.for_machine, nkwargs)) # type: ignore # pylint: disable=no-value-for-parameter + self.is_found = self._add_sub_dependency(hdf5_factory(environment, for_machine, nkwargs)) # type: ignore # pylint: disable=no-value-for-parameter def _sanitize_version(self, ver: str) -> str: v = re.search(r'\s*HDF5 Version: (\d+\.\d+\.\d+)', ver)