summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRedbeanw44602 <[email protected]>2025-05-16 15:12:40 +0800
committerRedbeanw44602 <[email protected]>2025-05-16 15:12:40 +0800
commitd42c60e222e69d0589f23a3ed70e7e95bcf0e475 (patch)
treeb1bb2277fdb4e0522f9fdbbe51456576a0523200
parent77bd76e903cf2dbcef1ca7e4e1fa495edc6432fb (diff)
add `detect.sdks.find_dia_sdk`.
-rw-r--r--xmake/modules/detect/sdks/find_dia_sdk.lua111
1 files changed, 111 insertions, 0 deletions
diff --git a/xmake/modules/detect/sdks/find_dia_sdk.lua b/xmake/modules/detect/sdks/find_dia_sdk.lua
new file mode 100644
index 000000000..770e1d4d8
--- /dev/null
+++ b/xmake/modules/detect/sdks/find_dia_sdk.lua
@@ -0,0 +1,111 @@
+--!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 redbeanw
+-- @file find_dia_sdk.lua
+--
+
+-- imports
+import("core.project.config")
+import("core.tool.toolchain")
+import("detect.sdks.find_vstudio")
+
+function _is_sdkdir_valid(sdkdir)
+ return os.isfile(path.join(sdkdir, "lib", "diaguids.lib"))
+end
+
+function _find_sdkdir(sdkdir, opt)
+ if not sdkdir then
+ local vsdir = os.getenv("VSInstallDir")
+ if not vsdir then
+ if opt.toolchain then
+ vcvars = opt.toolchain:config("vcvars")
+ if vcvars then
+ vsdir = vcvars["VSInstallDir"]
+ end
+ end
+ end
+ if not vsdir then
+ local msvc = toolchain.load("msvc")
+ if msvc and msvc:check() then
+ local vcvars = msvc:config("vcvars")
+ if vcvars then
+ vsdir = vcvars["VSInstallDir"]
+ end
+ end
+ end
+ if vsdir then
+ sdkdir = path.join(vsdir, "DIA SDK")
+ else
+ return
+ end
+ end
+
+ if not _is_sdkdir_valid(sdkdir) then
+ sdkdir = path.join(sdkdir, "DIA SDK")
+ end
+
+ return _is_sdkdir_valid(sdkdir) and sdkdir or nil
+end
+
+-- find DIA SDK
+--
+-- @param sdkdir the DIA SDK directory
+-- @param opt the argument options, e.g. {toolchain = ..., arch = ...}
+--
+-- @return the DIA SDK. e.g. {sdkdir = ..., linkdirs = ..., includedirs = ...}
+--
+-- @code
+--
+-- local toolchains = find_dia_sdk("/opt/msvc/DIA SDK")
+--
+-- @endcode
+--
+function main(sdkdir, opt)
+
+ -- init options
+ opt = opt or {}
+ sdkdir = _find_sdkdir(sdkdir, opt)
+ if not sdkdir then
+ return
+ end
+
+ -- get arch
+ local arch = opt.arch or config.get("arch")
+ if arch then
+ local supported_arch = {
+ x64 = "amd64",
+ arm = "arm",
+ arm64 = "arm64"
+ }
+ arch = supported_arch[arch]
+ end
+
+ if not arch then
+ return
+ end
+
+ return {
+ sdkdir = sdkdir,
+ linkdirs = {
+ path.join(sdkdir, "lib", arch),
+ path.join(sdkdir, "bin", arch)
+ },
+ includedirs = {
+ path.join(sdkdir, "include", arch)
+ }
+ }
+end \ No newline at end of file