aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-08-04 22:38:04 +0300
committerGitHub <noreply@github.com>2017-08-04 22:38:04 +0300
commite95ba1ada5e0f98daa0bca78440eb5ceef78ef7e (patch)
treea4f7f1553f8322848f91acd4cfa085630d1f8c8d
parentbc5982142ff8961b276b5ab4b3a800932a4c03e8 (diff)
parent12a5a50058cc3c6184d2d02a60dc578c2ec5d8d8 (diff)
downloadmeson-e95ba1ada5e0f98daa0bca78440eb5ceef78ef7e.zip
meson-e95ba1ada5e0f98daa0bca78440eb5ceef78ef7e.tar.gz
meson-e95ba1ada5e0f98daa0bca78440eb5ceef78ef7e.tar.bz2
Merge pull request #2113 from nyorain/vulkan
Vulkan dependency module
-rw-r--r--docs/markdown/Release-notes-for-0.42.0.md5
-rw-r--r--mesonbuild/dependencies/__init__.py3
-rw-r--r--mesonbuild/dependencies/ui.py78
-rw-r--r--test cases/frameworks/17 vulkan/meson.build7
-rw-r--r--test cases/frameworks/17 vulkan/vulkanprog.c26
5 files changed, 117 insertions, 2 deletions
diff --git a/docs/markdown/Release-notes-for-0.42.0.md b/docs/markdown/Release-notes-for-0.42.0.md
index f0ea534..9b2df63 100644
--- a/docs/markdown/Release-notes-for-0.42.0.md
+++ b/docs/markdown/Release-notes-for-0.42.0.md
@@ -83,3 +83,8 @@ flag manually, e.g. via `link_args` to a target. This is not
recommended because having multiple rpath causes them to stomp on each
other. This warning will become a hard error in some future release.
+## Vulkan dependency module
+
+Vulkan can now be used as native dependency. The dependency module will detect
+the VULKAN_SDK environment variable or otherwise try to receive the vulkan
+library and header via pkgconfig or from the system.
diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py
index 3d41a2b..f153b97 100644
--- a/mesonbuild/dependencies/__init__.py
+++ b/mesonbuild/dependencies/__init__.py
@@ -19,7 +19,7 @@ from .base import ( # noqa: F401
from .dev import GMockDependency, GTestDependency, LLVMDependency, ValgrindDependency
from .misc import BoostDependency, Python3Dependency, ThreadDependency
from .platform import AppleFrameworks
-from .ui import GLDependency, GnuStepDependency, Qt4Dependency, Qt5Dependency, SDL2Dependency, WxDependency
+from .ui import GLDependency, GnuStepDependency, Qt4Dependency, Qt5Dependency, SDL2Dependency, WxDependency, VulkanDependency
packages.update({
@@ -44,4 +44,5 @@ packages.update({
'qt5': Qt5Dependency,
'sdl2': SDL2Dependency,
'wxwidgets': WxDependency,
+ 'vulkan': VulkanDependency,
})
diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py
index 1c59a41..99e017b 100644
--- a/mesonbuild/dependencies/ui.py
+++ b/mesonbuild/dependencies/ui.py
@@ -24,7 +24,7 @@ from collections import OrderedDict
from .. import mlog
from .. import mesonlib
from ..mesonlib import MesonException, Popen_safe, version_compare
-from ..environment import for_windows
+from ..environment import for_windows, detect_cpu
from .base import DependencyException, DependencyMethods
from .base import ExternalDependency, ExternalProgram
@@ -493,3 +493,79 @@ class WxDependency(ExternalDependency):
pass
WxDependency.wxconfig_found = False
mlog.log('Found wx-config:', mlog.red('NO'))
+
+class VulkanDependency(ExternalDependency):
+ def __init__(self, environment, kwargs):
+ super().__init__('vulkan', environment, None, kwargs)
+
+ if DependencyMethods.PKGCONFIG in self.methods:
+ try:
+ pcdep = PkgConfigDependency('vulkan', environment, kwargs)
+ if pcdep.found():
+ self.type_name = 'pkgconfig'
+ self.is_found = True
+ self.compile_args = pcdep.get_compile_args()
+ self.link_args = pcdep.get_link_args()
+ self.version = pcdep.get_version()
+ return
+ except Exception:
+ pass
+
+ if DependencyMethods.SYSTEM in self.methods:
+ try:
+ self.vulkan_sdk = os.environ['VULKAN_SDK']
+ if not os.path.isabs(self.vulkan_sdk):
+ raise DependencyException('VULKAN_SDK must be an absolute path.')
+ except KeyError:
+ self.vulkan_sdk = None
+
+ if self.vulkan_sdk:
+ # TODO: this config might not work on some platforms, fix bugs as reported
+ # we should at least detect other 64-bit platforms (e.g. armv8)
+ lib_name = 'vulkan'
+ if mesonlib.is_windows():
+ lib_name = 'vulkan-1'
+ lib_dir = 'Lib32'
+ inc_dir = 'Include'
+ if detect_cpu({}) == 'x86_64':
+ lib_dir = 'Lib'
+ else:
+ lib_name = 'vulkan'
+ lib_dir = 'lib'
+ inc_dir = 'include'
+
+ # make sure header and lib are valid
+ inc_path = os.path.join(self.vulkan_sdk, inc_dir)
+ header = os.path.join(inc_path, 'vulkan', 'vulkan.h')
+ lib_path = os.path.join(self.vulkan_sdk, lib_dir)
+ find_lib = self.compiler.find_library(lib_name, environment, lib_path)
+
+ if not find_lib:
+ raise DependencyException('VULKAN_SDK point to invalid directory (no lib)')
+
+ if not os.path.isfile(header):
+ raise DependencyException('VULKAN_SDK point to invalid directory (no include)')
+
+ self.type_name = 'vulkan_sdk'
+ self.is_found = True
+ 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)
+ self.version = '1'
+ return
+ else:
+ # simply try to guess it, usually works on linux
+ libs = self.compiler.find_library('vulkan', environment, [])
+ if libs is not None and self.compiler.has_header('vulkan/vulkan.h', '', environment):
+ self.type_name = 'system'
+ self.is_found = True
+ self.version = 1 # TODO
+ for lib in libs:
+ self.link_args.append(lib)
+ return
+
+ def get_methods(self):
+ return [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM]
diff --git a/test cases/frameworks/17 vulkan/meson.build b/test cases/frameworks/17 vulkan/meson.build
new file mode 100644
index 0000000..54f1d47
--- /dev/null
+++ b/test cases/frameworks/17 vulkan/meson.build
@@ -0,0 +1,7 @@
+project('vulkan test', 'c')
+
+vulkan_dep = dependency('vulkan')
+
+e = executable('vulkanprog', 'vulkanprog.c', dependencies : vulkan_dep)
+
+test('vulkantest', e)
diff --git a/test cases/frameworks/17 vulkan/vulkanprog.c b/test cases/frameworks/17 vulkan/vulkanprog.c
new file mode 100644
index 0000000..1c1c58a
--- /dev/null
+++ b/test cases/frameworks/17 vulkan/vulkanprog.c
@@ -0,0 +1,26 @@
+#include <vulkan/vulkan.h>
+#include <stdio.h>
+
+int main()
+{
+ VkInstanceCreateInfo instance_create_info = {
+ VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ };
+
+ // we don't actually require instance creation to succeed since
+ // we cannot expect test environments to have a vulkan driver installed.
+ // As long as this does not produce as segmentation fault or similar,
+ // everything's alright.
+ VkInstance instance;
+ if(vkCreateInstance(&instance_create_info, NULL, &instance) == VK_SUCCESS)
+ vkDestroyInstance(instance, NULL);
+
+ return 0;
+} \ No newline at end of file