summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2022-06-09 23:32:55 +0200
committerArthur LAURENT <[email protected]>2022-06-09 23:32:55 +0200
commit50f55f6e0e7ce6a5474fb5dd784c90321371396c (patch)
tree66a84b5fbf51f21c576f1d0d3022774325a78473
parenta3f81d902ec232527f7b21e08b33d97936fc98d2 (diff)
Add qt.quickplugin rule and support of qmltypesregistrar
-rw-r--r--xmake/rules/qt/moc/xmake.lua1
-rw-r--r--xmake/rules/qt/qmltyperegistrar/xmake.lua127
-rw-r--r--xmake/rules/qt/xmake.lua7
3 files changed, 135 insertions, 0 deletions
diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua
index 5a10f73f8..7cb62b9bb 100644
--- a/xmake/rules/qt/moc/xmake.lua
+++ b/xmake/rules/qt/moc/xmake.lua
@@ -78,6 +78,7 @@ rule("qt.moc")
table.insert(flags, pathitem)
end
end
+ local user_flags = target:get("qt.moc.flags") or {}
batchcmds:mkdir(path.directory(sourcefile_moc))
batchcmds:vrunv(moc, table.join(flags, path(sourcefile), "-o", path(sourcefile_moc)))
diff --git a/xmake/rules/qt/qmltyperegistrar/xmake.lua b/xmake/rules/qt/qmltyperegistrar/xmake.lua
new file mode 100644
index 000000000..96fcf4205
--- /dev/null
+++ b/xmake/rules/qt/qmltyperegistrar/xmake.lua
@@ -0,0 +1,127 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author arthapz
+-- @file xmake.lua
+--
+
+rule("qt.qmltyperegistrar")
+ add_deps("qt.env")
+ set_extensions(".h", ".hpp")
+
+ on_load(function(target)
+ -- get qt
+ local qt = assert(target:data("qt"), "qt not found!")
+
+ -- get qmltyperegistrar
+ local qmltyperegistrar = path.join(qt.bindir, is_host("windows") and "qmltyperegistrar.exe" or "qmltyperegistrar")
+ if not os.isexec(qmltyperegistrar) and qt.libexecdir then
+ qmltyperegistrar = path.join(qt.libexecdir, is_host("windows") and "qmltyperegistrar.exe" or "qmltyperegistrar")
+ end
+ if not os.isexec(qmltyperegistrar) and qt.libexecdir_host then
+ qmltyperegistrar = path.join(qt.libexecdir_host, is_host("windows") and "qmltyperegistrar.exe" or "qmltyperegistrar")
+ end
+ assert(qmltyperegistrar and os.isexec(qmltyperegistrar), "qmltyperegistrar not found!")
+
+ -- set targetdir
+ local importname = target:values("qml.plugin.importname")
+ local targetdir = path.join(target:targetdir(), "imports")
+ for _, dir in pairs(importname:split(".", { plain = true })) do
+ targetdir = path.join(targetdir, dir)
+ end
+
+ os.mkdir(targetdir)
+ target:set("targetdir", targetdir)
+
+ -- add qmldir
+ local qmldir = target:values("qml.plugin.qmldir")
+
+ if qmldir then
+ target:add("installfiles", qmldir)
+ end
+
+ local sourcefile = path.join(target:autogendir(), "rules", "qt", "qmltyperegistrar", target:name() .. "_qmltyperegistrations.cpp")
+ local sourcefile_dir = path.directory(sourcefile)
+ os.mkdir(sourcefile_dir)
+ target:data_set("qml.plugin.sourcefile", sourcefile)
+
+ -- add moc arguments
+ target:add("qt.moc.flags", "--output-json")
+
+ -- save qmltyperegistrar
+ target:data_set("qt.qmltyperegistrar", qmltyperegistrar)
+ -- save qmltyperegistrar
+ target:data_set("qml.plugin.qmltyperegistrar", qmltyperegistrar)
+ end)
+
+ on_buildcmd_files(function(target, batchcmds, sourcebatch, opt)
+ assert(target:values("qml.plugin.importname"), "QML plugin import name not set")
+
+ -- setup qmltyperegistrar arguments
+ local qmltyperegistrar = target:data("qt.qmltyperegistrar")
+ local sourcefile = target:data("qml.plugin.sourcefile")
+
+ local importname = target:values("qml.plugin.importname")
+ local majorversion = target:values("qml.plugin.majorversion") or 1
+ local minorversion = target:values("qml.plugin.minorversion") or 0
+
+ local metatypefiles = {}
+ for _, mocedfile in ipairs(sourcebatch.sourcefiles) do
+ target:add("includedirs", path.directory(mocedfile))
+ local basename = path.basename(mocedfile)
+ local filename_moc = "moc_" .. basename .. ".cpp"
+ if mocedfile:endswith(".cpp") then
+ filename_moc = basename .. ".moc"
+ end
+
+ local sourcefile_moc = target:autogenfile(path.join(path.directory(mocedfile), filename_moc))
+
+ table.insert(metatypefiles, path(sourcefile_moc .. ".json"))
+ end
+
+ local args = {
+ "--generate-qmltypes=" .. target:get("targetdir") .. "/plugin.qmltypes",
+ "--import-name=" .. importname,
+ "--major-version=" .. majorversion,
+ "--minor-version=" .. minorversion,
+ "-o", path(sourcefile)
+ }
+
+ -- gen sourcefile
+ batchcmds:show_progress(opt.progress, "${color.build.object}generate.qt.qmltyperegistrar %s", path.filename(sourcefile))
+ qmltype_source = os.vrunv(qmltyperegistrar, table.join(args, metatypefiles))
+
+ -- add objectfile
+ local objectfile = target:objectfile(sourcefile)
+ table.insert(target:objectfiles(), objectfile)
+
+ -- compile sourcefile
+ batchcmds:show_progress(opt.progress, "${color.build.object}compile.qt.qmltyperegistrar %s", path.filename(sourcefile))
+
+ batchcmds:compile(sourcefile, objectfile)
+
+ batchcmds:add_depfiles(sourcefile)
+ batchcmds:set_depmtime(os.mtime(objectfile))
+ batchcmds:set_depcache(target:dependfile(objectfile))
+ end)
+
+ after_build(function(target)
+ local qmldir = target:values("qml.plugin.qmldir")
+
+ if qmldir then
+ os.cp(qmldir, target:targetdir())
+ end
+ end) \ No newline at end of file
diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua
index b26a458a5..5ac3c9392 100644
--- a/xmake/rules/qt/xmake.lua
+++ b/xmake/rules/qt/xmake.lua
@@ -235,6 +235,13 @@ rule("qt.quickapp_static")
on_install("android", "install.android")
after_install("windows", "install.windows")
+-- define rule: qt quickplugin
+rule("qt.quickplugin")
+ add_deps("qt.shared", "qt.qmltyperegistrar")
+ on_load(function(target)
+ import("load")(target, {frameworks = { "QtCore", "QtGui", "QtQuick", "QtQml", "QtNetwork" }})
+ end)
+
-- define rule: qt application (deprecated)
rule("qt.application")
add_deps("qt.quickapp", "qt.ui")