diff options
| author | GooRoo <[email protected]> | 2025-07-22 15:35:01 +0200 |
|---|---|---|
| committer | GooRoo <[email protected]> | 2025-07-22 15:35:01 +0200 |
| commit | 578512e809caf73dea0f086e31bfd627a1243188 (patch) | |
| tree | b2cb2d3558eda3a832f36a4a384647a9791aec8e | |
| parent | 30c391ef694cad88de2bf8c67cda153e9943c8b2 (diff) | |
fix(qt.qmltyperegistrar): Collect metatypes info
Instead of passing all JSON-files generated by MOC directly into `qmltyperegistrar`, combine them into a single JSON-file first using MOC.
Resolves #6647.
| -rw-r--r-- | xmake/rules/qt/moc/xmake.lua | 17 | ||||
| -rw-r--r-- | xmake/rules/qt/qmltyperegistrar/xmake.lua | 29 |
2 files changed, 35 insertions, 11 deletions
diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua index 696a7ffdd..dfd194ffe 100644 --- a/xmake/rules/qt/moc/xmake.lua +++ b/xmake/rules/qt/moc/xmake.lua @@ -22,12 +22,14 @@ rule("qt.moc") add_deps("qt.env") add_orders("qt.ui", "qt.moc") set_extensions(".h", ".hpp") - before_buildcmd_file(function (target, batchcmds, sourcefile, opt) - import("core.tool.compiler") + + on_config(function (target) import("lib.detect.find_file") - -- get moc + -- get qt local qt = assert(target:data("qt"), "Qt not found!") + + -- get moc local search_dirs = {} if qt.bindir_host then table.insert(search_dirs, qt.bindir_host) end if qt.bindir then table.insert(search_dirs, qt.bindir) end @@ -36,6 +38,15 @@ rule("qt.moc") local moc = find_file(is_host("windows") and "moc.exe" or "moc", search_dirs) assert(moc and os.isexec(moc), "moc not found!") + -- save moc + target:data_set("qt.moc", moc) + end) + + before_buildcmd_file(function (target, batchcmds, sourcefile, opt) + import("core.tool.compiler") + + local moc = target:data("qt.moc") + -- get c++ source file for moc -- -- add_files("mainwindow.h") -> moc_MainWindow.cpp diff --git a/xmake/rules/qt/qmltyperegistrar/xmake.lua b/xmake/rules/qt/qmltyperegistrar/xmake.lua index 45914c501..851658ec4 100644 --- a/xmake/rules/qt/qmltyperegistrar/xmake.lua +++ b/xmake/rules/qt/qmltyperegistrar/xmake.lua @@ -57,9 +57,12 @@ rule("qt.qmltyperegistrar") -- add qmltypes target:add("installfiles", path.join(target:get("targetdir"), "plugin.qmltypes"), { prefixdir = path.join("bin", table.unpack(importname:split(".", { plain = true }))) }) - local sourcefile = path.join(target:autogendir(), "rules", "qt", "qmltyperegistrar", target:name() .. "_qmltyperegistrations.cpp") + local genbasename = path.join(target:autogendir(), "rules", "qt", "qmltyperegistrar", target:name()) + local metatypesfile = genbasename .. "_metatypes.json" + local sourcefile = genbasename .. "_qmltyperegistrations.cpp" local sourcefile_dir = path.directory(sourcefile) os.mkdir(sourcefile_dir) + target:data_set("qt.qmlplugin.metatypesfile", metatypesfile) target:data_set("qt.qmlplugin.sourcefile", sourcefile) -- add moc arguments @@ -72,16 +75,17 @@ rule("qt.qmltyperegistrar") end) on_buildcmd_files(function(target, batchcmds, sourcebatch, opt) - -- setup qmltyperegistrar arguments + local moc = target:data("qt.moc") local qmltyperegistrar = target:data("qt.qmltyperegistrar") + local metatypesfile = target:data("qt.qmlplugin.metatypesfile") local sourcefile = target:data("qt.qmlplugin.sourcefile") local importname = target:values("qt.qmlplugin.import_name") local majorversion = target:values("qt.qmlplugin.majorversion") or 1 local minorversion = target:values("qt.qmlplugin.minorversion") or 0 - local metatypefiles = {} + local metatype_files = {} for _, mocedfile in ipairs(sourcebatch.sourcefiles) do target:add("includedirs", path.directory(mocedfile)) local basename = path.basename(mocedfile) @@ -90,20 +94,29 @@ rule("qt.qmltyperegistrar") filename_moc = basename .. ".moc" end local sourcefile_moc = target:autogenfile(path.join(path.directory(mocedfile), filename_moc)) - table.insert(metatypefiles, path(sourcefile_moc .. ".json")) + table.insert(metatype_files, path(sourcefile_moc .. ".json")) end + -- generate a common metatypes.json file + -- @see https://github.com/xmake-io/xmake/issues/6647 + local moc_args = { + "--collect-json", + "-o", metatypesfile + } + batchcmds:show_progress(opt.progress, "${color.build.object}generating.qt.qmltyperegistrar %s", path.filename(metatypesfile)) + batchcmds:vrunv(moc, table.join(moc_args, metatype_files)) + + -- gen sourcefile local args = { "--generate-qmltypes=" .. target:get("targetdir") .. "/plugin.qmltypes", "--import-name=" .. importname, "--major-version=" .. majorversion, "--minor-version=" .. minorversion, - "-o", sourcefile + "-o", sourcefile, + metatypesfile } - - -- gen sourcefile batchcmds:show_progress(opt.progress, "${color.build.object}generating.qt.qmltyperegistrar %s", path.filename(sourcefile)) - batchcmds:vrunv(qmltyperegistrar, table.join(args, metatypefiles)) + batchcmds:vrunv(qmltyperegistrar, args) -- add objectfile local objectfile = target:objectfile(sourcefile) |
