diff options
author | Lucas Alber <lucasd.alber@gmail.com> | 2023-08-08 10:16:49 +0200 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2023-08-08 08:25:04 -0400 |
commit | a151b10988644b24dd45d0a912d5994edccbb6e0 (patch) | |
tree | 9f44d99aaf158cc7a963b89eacec778abc40bd0f | |
parent | 142dd17f5b7fbc4b2cd94f2af5bde1edfdb135be (diff) | |
download | meson-a151b10988644b24dd45d0a912d5994edccbb6e0.zip meson-a151b10988644b24dd45d0a912d5994edccbb6e0.tar.gz meson-a151b10988644b24dd45d0a912d5994edccbb6e0.tar.bz2 |
Detect version for Vulkan system dependency
-rw-r--r-- | mesonbuild/dependencies/ui.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index 1dffa1f..6de5534 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -17,11 +17,13 @@ from __future__ import annotations import os +import re import subprocess import typing as T from .. import mlog from .. import mesonlib +from ..compilers.compilers import CrossNoRunException from ..mesonlib import ( Popen_safe, extract_as_list, version_compare_many ) @@ -235,10 +237,6 @@ class VulkanDependencySystem(SystemDependency): self.compile_args.append('-I' + inc_path) self.link_args.append('-L' + lib_path) self.link_args.append('-l' + lib_name) - - # TODO: find a way to retrieve the version from the sdk? - # Usually it is a part of the path to it (but does not have to be) - return else: # simply try to guess it, usually works on linux libs = self.clib_compiler.find_library('vulkan', environment, []) @@ -246,7 +244,33 @@ class VulkanDependencySystem(SystemDependency): self.is_found = True for lib in libs: self.link_args.append(lib) - return + + if self.is_found: + get_version = '''\ +#include <stdio.h> +#include <vulkan/vulkan.h> + +int main() { + printf("%i.%i.%i", VK_VERSION_MAJOR(VK_HEADER_VERSION_COMPLETE), + VK_VERSION_MINOR(VK_HEADER_VERSION_COMPLETE), + VK_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE)); + return 0; +} +''' + try: + run = self.clib_compiler.run(get_version, environment, extra_args=self.compile_args) + except CrossNoRunException: + run = None + if run and run.compiled and run.returncode == 0: + self.version = run.stdout + elif self.vulkan_sdk: + # fall back to heuristics: detect version number in path + # matches the default install path on Windows + match = re.search(rf'VulkanSDK{re.escape(os.path.sep)}([0-9]+(?:\.[0-9]+)+)', self.vulkan_sdk) + if match: + self.version = match.group(1) + else: + mlog.warning(f'Environment variable VULKAN_SDK={self.vulkan_sdk} is present, but Vulkan version could not be extracted.') packages['gl'] = gl_factory = DependencyFactory( 'gl', |