diff options
| author | ruki <[email protected]> | 2025-07-24 09:55:18 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-24 09:55:18 +0800 |
| commit | 990cde63dbdf3002940698fd59dde5c236731f0f (patch) | |
| tree | dff97264936c389cfee1b5d143251a30903a8b3c | |
| parent | fa658ed8e123d87e7dd0351e8682f39a857a5e8c (diff) | |
| parent | 3c66df3f0fca6594d4f018c6e6ef03857aabc007 (diff) | |
Merge pull request #6648 from GooRoo/qmltyperegistrar-fix
fix(qt.qmltyperegistrar): Collect metatypes info
| -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..cf84c7db2 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 = path(genbasename .. "_metatypes.json") + local sourcefile = path(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) |
