diff options
| author | xq114 <[email protected]> | 2022-09-05 15:01:38 +0800 |
|---|---|---|
| committer | xq114 <[email protected]> | 2022-09-05 15:01:38 +0800 |
| commit | a3015f45b428eb239238156da8794dec398f8c1f (patch) | |
| tree | 6b38ee089c7420c35adb517ce641a798c896735b | |
| parent | cfa0c527f0b86daaa906d93c499eceea7785ba0e (diff) | |
move find_vulkansdk to sdk detection
| -rw-r--r-- | xmake/modules/detect/packages/find_vulkansdk.lua | 30 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_vulkansdk.lua | 100 |
2 files changed, 102 insertions, 28 deletions
diff --git a/xmake/modules/detect/packages/find_vulkansdk.lua b/xmake/modules/detect/packages/find_vulkansdk.lua index 902fdd498..efce6adeb 100644 --- a/xmake/modules/detect/packages/find_vulkansdk.lua +++ b/xmake/modules/detect/packages/find_vulkansdk.lua @@ -19,8 +19,7 @@ -- -- imports -import("lib.detect.find_path") -import("lib.detect.find_library") +import("detect.sdks.find_vulkansdk") -- find vulkansdk -- @@ -30,30 +29,5 @@ import("lib.detect.find_library") -- function main(opt) - -- init search paths - local paths = - { - "$(env VK_SDK_PATH)", - "$(env VULKAN_SDK)" - } - - -- find library - local result = {links = {}, linkdirs = {}, includedirs = {}} - local libname = (opt.plat == "windows" and "vulkan-1" or "vulkan") - local libsuffix = ((opt.plat == "windows" and opt.arch == "x86") and "lib32" or "lib") - local binsuffix = ((opt.plat == "windows" and opt.arch == "x86") and "bin32" or "bin") - local linkinfo = find_library(libname, paths, {suffixes = libsuffix}) - if linkinfo then - result.sdkdir = path.directory(linkinfo.linkdir) - result.bindir = path.join(result.sdkdir, binsuffix) - table.insert(result.linkdirs, linkinfo.linkdir) - table.insert(result.links, libname) - else - -- not found? - return - end - - -- find include - table.insert(result.includedirs, find_path(path.join("vulkan", "vulkan.h"), paths, {suffixes = "include"})) - return result + return find_vulkansdk() end diff --git a/xmake/modules/detect/sdks/find_vulkansdk.lua b/xmake/modules/detect/sdks/find_vulkansdk.lua new file mode 100644 index 000000000..5cea9dce4 --- /dev/null +++ b/xmake/modules/detect/sdks/find_vulkansdk.lua @@ -0,0 +1,100 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author xq114 +-- @file find_vulkansdk.lua +-- + +-- imports +import("lib.detect.find_file") +import("lib.detect.find_path") +import("lib.detect.find_library") +import("lib.detect.find_programver") + +-- find vulkan sdk info executable +function _find_vkinfo() + + -- init search paths + local paths = + { + "$(env VK_SDK_PATH)", + "$(env VULKAN_SDK)" + } + + -- find vulkan sdk info + local vkinfo + if is_host("windows") then + if is_arch("x86") then + vkinfo = find_file("vulkaninfoSDK.exe", paths, {suffixes = {"bin32"}}) + else + vkinfo = find_file("vulkaninfoSDK.exe", paths, {suffixes = {"bin"}}) + end + elseif is_host("linux") then + vkinfo = find_file("vulkaninfo", paths, {suffixes = {"bin"}}) + end + + return vkinfo +end + +-- 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) + + -- find vkinfo + local vkinfo = _find_vkinfo() + if not vkinfo then + -- not found? + return + end + local sdkdir = path.directory(path.directory(vkinfo)) + + -- find api version + local apiver = find_programver(vkinfo, {command = "--summary", parse = "Vulkan Instance Version: (%d+%.%d+%.%d+)"}) + + -- initialize result + local result = {sdkdir = sdkdir, apiversion = apiver, links = {}, linkdirs = {}, includedirs = {}} + local binsuffix = ((is_host("windows") and is_arch("x86")) and "bin32" or "bin") + result.bindir = path.join(result.sdkdir, binsuffix) + + -- find library + local libname = (is_host("windows") and "vulkan-1" or "vulkan") + local libsuffix = ((is_host("windows") and is_arch("x86")) and "lib32" or "lib") + local linkinfo = find_library(libname, sdkdir, {suffixes = libsuffix}) + if linkinfo then + table.insert(result.linkdirs, linkinfo.linkdir) + table.insert(result.links, libname) + else + -- not found? + return + end + + -- find headers + local incdir = find_path(path.join("vulkan", "vulkan.h"), sdkdir, {suffixes = {"include"}}) + if incdir then + table.insert(result.includedirs, incdir) + else + -- not found? + return + end + + -- return + print(result) + return result +end |
