|
| 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) |
0 commit comments