diff options
| author | ruki <[email protected]> | 2023-05-23 23:52:40 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-05-23 23:52:40 +0800 |
| commit | 53f86ce179a1ae0b7f2cee85c806cd90209b0429 (patch) | |
| tree | 50883c1c99d691216cd7e83dc783d7e08fb5493c | |
| parent | 992cc3c22e49a7a7f8a47d6b10d34af0128c58af (diff) | |
improve to find_vulkansdk
| -rw-r--r-- | xmake/modules/detect/sdks/find_vulkansdk.lua | 61 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/pkgconfig.lua | 1 |
2 files changed, 39 insertions, 23 deletions
diff --git a/xmake/modules/detect/sdks/find_vulkansdk.lua b/xmake/modules/detect/sdks/find_vulkansdk.lua index cb9e0c980..6ddeddd27 100644 --- a/xmake/modules/detect/sdks/find_vulkansdk.lua +++ b/xmake/modules/detect/sdks/find_vulkansdk.lua @@ -24,29 +24,11 @@ import("lib.detect.find_file") import("lib.detect.find_path") import("lib.detect.find_library") import("lib.detect.find_programver") +import("lib.detect.find_package") --- find vulkansdk --- --- @param opt the package options. e.g. see the options of find_package() --- --- @return see the return value of find_package() --- -function main(opt) - - -- init option +-- find vulkan from paths +function _find_vulkan_from_paths(paths, opt) opt = opt or {} - - -- init search configs - local paths = - { - "$(env VK_SDK_PATH)", - "$(env VULKAN_SDK)" - } - if is_host("linux") then - -- we attempt to find vulkan from /usr, e.g. /usr/include/vulkan/vulkan.h - table.insert(paths, "/usr"); - table.insert(paths, "/usr/local") - end local arch = opt.arch or config.arch() or os.arch() local binsuffix = ((is_host("windows") and arch == "x86") and "bin32" or "bin") local libname = (is_host("windows") and "vulkan-1" or "vulkan") @@ -89,7 +71,42 @@ function main(opt) local apiver = find_programver(vkinfo, {command = "--summary", parse = "Vulkan Instance Version: (%d+%.%d+%.%d+)"}) result.apiversion = apiver end + return result +end + +-- find vulkan from system +function _find_vulkan_from_system(opt) + local result = find_package("pkgconfig::vulkan", table.join({version = true}, opt)) + if result then + result.apiversion = result.version + result.version = nil + if not result.apiversion then + local apiver = find_programver("vulkaninfo", {command = "--summary", parse = "Vulkan Instance Version: (%d+%.%d+%.%d+)"}) + result.apiversion = apiver + end + end + return result +end - -- return +-- find vulkansdk +-- +-- @param opt the package options. e.g. see the options of find_package() +-- +-- @return see the return value of find_package() +-- +function main(opt) + local paths = { + "$(env VK_SDK_PATH)", + "$(env VULKAN_SDK)" + } + local result = _find_vulkan_from_paths(paths, opt) + if not result then + result = _find_vulkan_from_system(opt) + end + if not result and is_host("linux") then + -- we attempt to find vulkan from /usr, e.g. /usr/include/vulkan/vulkan.h + paths = {"/usr", "/usr/local"} + result = _find_vulkan_from_paths(paths, opt) + end return result end diff --git a/xmake/modules/lib/detect/pkgconfig.lua b/xmake/modules/lib/detect/pkgconfig.lua index bd60c3769..ccf3f1e1f 100644 --- a/xmake/modules/lib/detect/pkgconfig.lua +++ b/xmake/modules/lib/detect/pkgconfig.lua @@ -195,7 +195,6 @@ function libinfo(name, opt) end end - -- get version local version = try { function() return os.iorunv(pkgconfig, {"--modversion", name}, {envs = envs}) end } if version then |
