def find_config(self, versions: T.List[str], returncode: int = 0, exclude_paths: T.Optional[T.List[str]] = None) \
            -> T.Tuple[T.Optional[T.List[str]], T.Optional[str]]:
        """Helper method that searches for config tool binaries in PATH and
        returns the one that best matches the given version requirements.
        """
        exclude_paths = [] if exclude_paths is None else exclude_paths
        best_match: T.Tuple[T.Optional[T.List[str]], T.Optional[str]] = (None, None)
        for potential_bin in find_external_program(
                self.env, self.for_machine, self.tool_name,
                self.tool_name, self.tools, exclude_paths=exclude_paths,
                allow_default_for_cross=self.allow_default_for_cross):
            if not potential_bin.found():
                continue
            tool = potential_bin.get_command()
            try:
                valid, version = self._check_and_get_version(tool, returncode)
            except (FileNotFoundError, PermissionError):
                continue
            if not valid:
                continue

            # Some tools, like pcap-config don't supply a version, but also
            # don't fail with --version, in that case just assume that there is
            # only one version and return it.
            if not version:
                return (tool, None)
            if versions:
                is_found = version_compare_many(version, versions)[0]
                # This allows returning a found version without a config tool,
                # which is useful to inform the user that you found version x,
                # but y was required.
                if not is_found:
                    tool = None
            if best_match[1]:
                if version_compare(version, '> {}'.format(best_match[1])):
                    best_match = (tool, version)
            else:
                best_match = (tool, version)

        return best_match
Helper method that searches for config tool binaries in PATH and
        returns the one that best matches the given version requirements.
        
mesonbuild/dependencies/configtool.py