Skip to content

Commit d42c60e

Browse files
committed
add detect.sdks.find_dia_sdk.
1 parent 77bd76e commit d42c60e

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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.tool.toolchain")
24+
import("detect.sdks.find_vstudio")
25+
26+
function _is_sdkdir_valid(sdkdir)
27+
return os.isfile(path.join(sdkdir, "lib", "diaguids.lib"))
28+
end
29+
30+
function _find_sdkdir(sdkdir, opt)
31+
if not sdkdir then
32+
local vsdir = os.getenv("VSInstallDir")
33+
if not vsdir then
34+
if opt.toolchain then
35+
vcvars = opt.toolchain:config("vcvars")
36+
if vcvars then
37+
vsdir = vcvars["VSInstallDir"]
38+
end
39+
end
40+
end
41+
if not vsdir then
42+
local msvc = toolchain.load("msvc")
43+
if msvc and msvc:check() then
44+
local vcvars = msvc:config("vcvars")
45+
if vcvars then
46+
vsdir = vcvars["VSInstallDir"]
47+
end
48+
end
49+
end
50+
if vsdir then
51+
sdkdir = path.join(vsdir, "DIA SDK")
52+
else
53+
return
54+
end
55+
end
56+
57+
if not _is_sdkdir_valid(sdkdir) then
58+
sdkdir = path.join(sdkdir, "DIA SDK")
59+
end
60+
61+
return _is_sdkdir_valid(sdkdir) and sdkdir or nil
62+
end
63+
64+
-- find DIA SDK
65+
--
66+
-- @param sdkdir the DIA SDK directory
67+
-- @param opt the argument options, e.g. {toolchain = ..., arch = ...}
68+
--
69+
-- @return the DIA SDK. e.g. {sdkdir = ..., linkdirs = ..., includedirs = ...}
70+
--
71+
-- @code
72+
--
73+
-- local toolchains = find_dia_sdk("/opt/msvc/DIA SDK")
74+
--
75+
-- @endcode
76+
--
77+
function main(sdkdir, opt)
78+
79+
-- init options
80+
opt = opt or {}
81+
sdkdir = _find_sdkdir(sdkdir, opt)
82+
if not sdkdir then
83+
return
84+
end
85+
86+
-- get arch
87+
local arch = opt.arch or config.get("arch")
88+
if arch then
89+
local supported_arch = {
90+
x64 = "amd64",
91+
arm = "arm",
92+
arm64 = "arm64"
93+
}
94+
arch = supported_arch[arch]
95+
end
96+
97+
if not arch then
98+
return
99+
end
100+
101+
return {
102+
sdkdir = sdkdir,
103+
linkdirs = {
104+
path.join(sdkdir, "lib", arch),
105+
path.join(sdkdir, "bin", arch)
106+
},
107+
includedirs = {
108+
path.join(sdkdir, "include", arch)
109+
}
110+
}
111+
end

0 commit comments

Comments
 (0)