zengine-old/engine/xmake/gen/meta_refl.lua
2024-04-29 15:00:09 +08:00

62 lines
2.1 KiB
Lua

import("core.project.depend")
function cmd_compile(genfile, sourcefile, template, macro, define)
import("find_sdk")
local meta = find_sdk.find_my_program("refl")
template = template or path.join(meta.sdkdir, "template")
if not macro then --优先使用库定义
macro = path.join(os.projectdir(), "engine/3rdparty/zlib/include/refl/macro.h")
if not os.exists(macro) then
macro = path.join(os.curdir(), "macro.h")
end
end
argv = {"build", sourcefile, "-o", genfile, "-t", template, "-m", macro}
if define then
table.insert(argv, "-d")
table.insert(argv, define)
end
print("cmd_meta_compile", genfile)
os.runv(meta.program, argv)
return argv
end
function _listen_gen_file(target, batch, template, macro, define)
genfile, sourcefile = batch[1], batch[2]
local dependfile = target:dependfile(genfile)
depend.on_changed(
function()
cmd_compile(batch[1], batch[2], template, macro, define)
end,
{dependfile = dependfile, files = sourcefile}
)
end
function gen(target)
local gen_batch = target:data("codegen.batch")
if not gen_batch then
return
end
local template = target:extraconf("rules", "c++.codegen", "template")
local macro = target:extraconf("rules", "c++.codegen", "macro")
local define = target:extraconf("rules", "c++.codegen", "define")
for _, batch in ipairs(gen_batch) do
if batch[2] then
_listen_gen_file(target, batch, template, macro, define)
end
end
end
function main(target, headerfiles)
local sourcedir = path.join(target:autogendir({root = true}), target:plat(), "inl")
if not os.isdir(sourcedir) then
os.mkdir(sourcedir)
end
target:add("includedirs", sourcedir, {public = true})
local gen_batch = {}
for idx, headerfile in pairs(headerfiles) do
-- batch
sourcefile = path.join(sourcedir, path.basename(headerfile) .. "_gen.inl")
table.insert(gen_batch, {sourcefile, headerfile})
end
-- save unit batch
target:data_set("codegen.batch", gen_batch)
end