zengine/engine/xmake/rule_plugin/make_plugin.lua

37 lines
1.5 KiB
Lua
Raw Normal View History

2024-07-20 18:04:19 +08:00
import("core.project.depend")
function cmd_compile(target, genfile, file)
2024-07-31 10:48:28 +08:00
import("core.project.project")
2024-08-03 17:56:38 +08:00
local name = target:name()
2024-07-31 10:48:28 +08:00
local pub_deps = target:values("module.public_dependencies")
local cpp_content = "inline void __" .. name .. "__module::InitMetaData(void){\n"
cpp_content = cpp_content.."\tmInfo.name = \"" .. name.."\";\n"
cpp_content = cpp_content.."\tmInfo.dependencies = {\n "
for k,dep in ipairs(pub_deps) do
local deptarget = project.target(dep)
if deptarget then
local kind = deptarget:kind()
local version = deptarget:version() or "0.0"
cpp_content = cpp_content.."\t\t{\"" .. dep .. "\", \""..version.."\", \""..kind.."\" },\n"
end
end
cpp_content = cpp_content.sub(cpp_content, 1, -3)
cpp_content = cpp_content.."\n\t};\n};"
print("cmd_compile plugin ", genfile)
io.writefile(genfile, cpp_content)
2024-07-20 18:04:19 +08:00
end
function main(target, file)
2024-07-31 10:48:28 +08:00
local sourcedir = path.join(target:autogendir({root = true}), target:plat(), "inl")
2024-07-20 18:04:19 +08:00
if not os.isdir(sourcedir) then
os.mkdir(sourcedir)
end
2024-07-31 10:48:28 +08:00
target:add("includedirs", sourcedir, {public = true})
local genfile = path.join(sourcedir, target:name() .. ".plugin.inl")
2024-07-20 18:04:19 +08:00
local dependfile = target:dependfile(genfile)
2024-07-31 10:48:28 +08:00
local sourcefile = string.lower(path.join(target:scriptdir(), file))
2024-07-20 18:04:19 +08:00
depend.on_changed(
function()
cmd_compile(target, genfile, file)
end,
2024-07-31 10:48:28 +08:00
{dependfile = dependfile, files = sourcefile}
2024-07-20 18:04:19 +08:00
)
end