Skip to content

Commit 84b0e0a

Browse files
authored
Merge pull request #6456 from Redbeanw44602/find-vs-dia-sdk
Add `detect.sdks.find_dia_sdk`.
2 parents 285b19a + 86eceab commit 84b0e0a

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, TBOOX Open Source Group.
16+
--
17+
-- @author redbeanw
18+
-- @file find_dia_sdk.lua
19+
--
20+
21+
-- imports
22+
import("core.project.config")
23+
import("core.base.option")
24+
import("core.tool.toolchain")
25+
import("core.cache.detectcache")
26+
import("detect.sdks.find_vstudio")
27+
28+
function _is_sdkdir_valid(sdkdir)
29+
return os.isfile(path.join(sdkdir, "lib", "diaguids.lib"))
30+
end
31+
32+
function _find_sdkdir(sdkdir, opt)
33+
if not sdkdir then
34+
local vsdir = os.getenv("VSInstallDir")
35+
if not vsdir then
36+
if opt.toolchain then
37+
vcvars = opt.toolchain:config("vcvars")
38+
if vcvars then
39+
vsdir = vcvars["VSInstallDir"]
40+
end
41+
end
42+
end
43+
if not vsdir then
44+
local msvc = toolchain.load("msvc", {plat = opt.plat or config.get("plat"), arch = opt.arch or config.get("arch")})
45+
if msvc and msvc:check() then
46+
local vcvars = msvc:config("vcvars")
47+
if vcvars then
48+
vsdir = vcvars["VSInstallDir"]
49+
end
50+
end
51+
end
52+
if vsdir then
53+
sdkdir = path.join(vsdir, "DIA SDK")
54+
else
55+
return
56+
end
57+
end
58+
59+
if not _is_sdkdir_valid(sdkdir) then
60+
sdkdir = path.join(sdkdir, "DIA SDK")
61+
end
62+
63+
return _is_sdkdir_valid(sdkdir) and sdkdir or nil
64+
end
65+
66+
function _find_dia_sdk(sdkdir, opt)
67+
-- get sdkdir
68+
sdkdir = _find_sdkdir(sdkdir, opt)
69+
if not sdkdir then
70+
return
71+
end
72+
73+
-- get arch
74+
local arch = opt.arch or config.get("arch")
75+
if arch then
76+
local supported_arch = {
77+
x64 = "amd64",
78+
arm = "arm",
79+
arm64 = "arm64"
80+
}
81+
arch = supported_arch[arch]
82+
end
83+
if not arch then
84+
return
85+
end
86+
87+
return {
88+
sdkdir = sdkdir,
89+
linkdirs = {
90+
path.join(sdkdir, "lib", arch),
91+
path.join(sdkdir, "bin", arch)
92+
},
93+
includedirs = {
94+
path.join(sdkdir, "include", arch)
95+
}
96+
}
97+
end
98+
99+
-- find DIA SDK
100+
--
101+
-- @param sdkdir the DIA SDK directory
102+
-- @param opt the argument options, e.g. {toolchain = ..., plat = ..., arch = ..., force = false, verbose = false}
103+
--
104+
-- @return the DIA SDK. e.g. {sdkdir = ..., linkdirs = ..., includedirs = ...}
105+
--
106+
-- @code
107+
--
108+
-- local toolchains = find_dia_sdk("/opt/msvc/DIA SDK")
109+
--
110+
-- @endcode
111+
--
112+
function main(sdkdir, opt)
113+
-- init options
114+
opt = opt or {}
115+
116+
-- attempt to load cache first
117+
local key = "detect.sdks.find_dia_sdk"
118+
local cacheinfo = detectcache:get(key) or {}
119+
if not opt.force and cacheinfo.dia_sdk and os.isdir(cacheinfo.dia_sdk.sdkdir) then
120+
return cacheinfo.dia_sdk
121+
end
122+
123+
-- find dia sdk
124+
local dia_sdk = _find_dia_sdk(sdkdir, opt)
125+
if dia_sdk then
126+
if opt.verbose or option.get("verbose") then
127+
cprint("checking for DIA SDK directory ... ${color.success}%s", dia_sdk.sdkdir)
128+
end
129+
else
130+
if opt.verbose or option.get("verbose") then
131+
cprint("checking for DIA SDK directory ... ${color.nothing}${text.nothing}")
132+
end
133+
end
134+
135+
-- save to cache
136+
cacheinfo.dia_sdk = dia_sdk or false
137+
detectcache:set(key, cacheinfo)
138+
detectcache:save()
139+
return dia_sdk
140+
end

0 commit comments

Comments
 (0)