Skip to content

Commit 0d0e484

Browse files
authored
Merge pull request #6279 from star-hengxing/midl
Add msvc midl support
2 parents 4aae3d6 + c9f6541 commit 0d0e484

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 ruki
18+
-- @file find_midl.lua
19+
--
20+
21+
-- imports
22+
import("core.project.config")
23+
import("lib.detect.find_program")
24+
import("lib.detect.find_programver")
25+
26+
-- find midl
27+
--
28+
-- @param opt the argument options, e.g. {version = true}
29+
--
30+
-- @return program, version
31+
--
32+
-- @code
33+
-- local midl = find_midl()
34+
-- @endcode
35+
--
36+
function main(opt)
37+
opt = opt or {}
38+
opt.check = opt.check or "/confirm"
39+
opt.command = opt.command or "/confirm"
40+
opt.parse = opt.parse or function (output) return output:match("Version (%d+%.%d+%.%d+)%s") end
41+
42+
local envs = opt.envs
43+
if envs and envs.WindowsSdkDir and envs.WindowsSDKVersion then
44+
local toolchain = opt.toolchain
45+
local arch = toolchain and toolchain:arch() or config.arch()
46+
local bindir = path.join(envs.WindowsSdkDir, "bin", envs.WindowsSDKVersion, arch)
47+
if os.isdir(bindir) then
48+
opt.paths = opt.paths or {}
49+
table.insert(opt.paths, bindir)
50+
end
51+
end
52+
53+
local program = find_program(opt.program or "midl", opt)
54+
55+
local version = nil
56+
if program and opt and opt.version then
57+
version = find_programver(program, opt)
58+
end
59+
return program, version
60+
end
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 ruki
18+
-- @file xmake.lua
19+
--
20+
21+
-- add *.idl for rc file
22+
rule("platform.windows.idl")
23+
set_extensions(".idl")
24+
25+
on_config(function (target)
26+
local autogendir = path.join(target:autogendir(), "platform/windows/idl")
27+
os.mkdir(autogendir)
28+
target:add("includedirs", autogendir, {public = true})
29+
end)
30+
31+
before_buildcmd_file(function (target, batchcmds, sourcefile, opt)
32+
import("lib.detect.find_tool")
33+
34+
local msvc = target:toolchain("msvc") or target:toolchain("clang-cl") or target:toolchain("clang")
35+
local midl = assert(find_tool("midl", {envs = msvc:runenvs(), toolchain = msvc}), "midl not found!")
36+
37+
local name = path.basename(sourcefile)
38+
local autogendir = path.join(target:autogendir(), "platform/windows/idl")
39+
40+
local flags = {"/nologo"}
41+
table.join2(flags, table.wrap(target:values("idl.flags")))
42+
table.join2(flags, {
43+
"/out", path(autogendir),
44+
"/header", name .. ".h",
45+
"/iid", name .. "_i.c",
46+
"/proxy", name .. "_p.c",
47+
"/tlb", name .. ".tlb",
48+
path(sourcefile)
49+
})
50+
51+
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.idl %s", sourcefile)
52+
batchcmds:vrunv(midl.program, flags, {envs = msvc:runenvs()})
53+
54+
local iid_file = path.join(autogendir, name .. "_i.c")
55+
local objectfile = target:objectfile(iid_file)
56+
table.insert(target:objectfiles(), objectfile)
57+
58+
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", iid_file)
59+
batchcmds:compile(iid_file, objectfile)
60+
61+
batchcmds:add_depfiles(sourcefile, iid_file)
62+
batchcmds:set_depmtime(os.mtime(objectfile))
63+
batchcmds:set_depcache(target:dependfile(objectfile))
64+
end)

xmake/rules/platform/xmake.lua

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ rule("platform.wasm")
2424

2525
rule("platform.windows")
2626
add_deps("platform.windows.def")
27+
add_deps("platform.windows.idl")
2728
if is_host("windows") then
2829
add_deps("platform.windows.manifest")
2930
end

0 commit comments

Comments
 (0)