From 9892551ea98b29ee5ae594491ff4dd58565c26ce Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Thu, 17 Dec 2020 11:01:06 +0100 Subject: Add support for windeployqt for Qt project install --- xmake/rules/qt/install/windows.lua | 86 ++++++++++++++++++++++++++++++++++++++ xmake/rules/qt/xmake.lua | 6 +++ 2 files changed, 92 insertions(+) create mode 100644 xmake/rules/qt/install/windows.lua diff --git a/xmake/rules/qt/install/windows.lua b/xmake/rules/qt/install/windows.lua new file mode 100644 index 000000000..9d0038fc1 --- /dev/null +++ b/xmake/rules/qt/install/windows.lua @@ -0,0 +1,86 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file macosx.lua +-- + +-- imports +import("core.theme.theme") +import("core.base.option") +import("core.project.config") +import("core.project.depend") +import("detect.sdks.find_vstudio") +import("private.utils.progress") + +-- install application package for windows +function main(target, opt) + + local targetfile = target:targetfile() + local installfile = path.join(target:installdir(), "bin", path.filename(targetfile)) + + -- need re-generate this app? + local dependfile = target:dependfile(targetfile) + + depend.on_changed(function () + -- do deploy + + -- get qt sdk + local qt = target:data("qt") + + -- get windeployqt + local windeployqt = path.join(qt.bindir, "windeployqt.exe") + assert(os.isexec(windeployqt), "windeployqt.exe not found!") + + -- find qml directory + local qmldir = nil + for _, sourcebatch in pairs(target:sourcebatches()) do + if sourcebatch.rulename == "qt.qrc" then + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + qmldir = find_path("*.qml", path.directory(sourcefile)) + if qmldir then + break + end + end + end + end + + -- find msvc to set VCINSTALLDIR env + local envs = nil + local msvc = toolchain.load("msvc", {plat = target:plat(), arch = target:arch()}) + if msvc then + local vcvars = msvc:config("vcvars") + if vcvars and vcvars.VSInstallDir then + envs = {VCINSTALLDIR = path.join(vcvars.VSInstallDir, "VC")} + end + end + + local argv = {"--force"} + if option.get("diagnosis") then + table.insert(argv, "--verbose=2") + elseif option.get("verbose") then + table.insert(argv, "--verbose=1") + else + table.insert(argv, "--verbose=0") + end + if qmldir then + table.insert(argv, "--qmldir=" .. qmldir) + end + table.insert(argv, installfile) + + os.vrunv(windeployqt, argv, {envs = envs}) + end, {dependfile = dependfile, files = targetfile}) +end diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua index afcaa7e83..07d59b31b 100644 --- a/xmake/rules/qt/xmake.lua +++ b/xmake/rules/qt/xmake.lua @@ -75,6 +75,8 @@ rule("qt.console") import("load")(target, {frameworks = {"QtCore"}}) end) + after_install("windows", "install.windows") + -- define rule: qt widgetapp rule("qt.widgetapp") add_deps("qt.ui", "qt.moc", "qt._wasm_app", "qt.qrc") @@ -94,6 +96,7 @@ rule("qt.widgetapp") -- install application for android on_install("android", "install.android") + after_install("windows", "install.windows") -- define rule: qt static widgetapp rule("qt.widgetapp_static") @@ -143,6 +146,7 @@ rule("qt.widgetapp_static") -- install application for android on_install("android", "install.android") + after_install("windows", "install.windows") -- define rule: qt quickapp rule("qt.quickapp") @@ -163,6 +167,7 @@ rule("qt.quickapp") -- install application for android on_install("android", "install.android") + after_install("windows", "install.windows") -- define rule: qt static quickapp rule("qt.quickapp_static") @@ -212,6 +217,7 @@ rule("qt.quickapp_static") -- install application for android on_install("android", "install.android") + after_install("windows", "install.windows") -- define rule: qt application (deprecated) rule("qt.application") -- cgit v1.3.1 From 21fcd32db014eabbb5a999deab4403930a095a83 Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Thu, 17 Dec 2020 11:03:20 +0100 Subject: Import toolchain --- xmake/rules/qt/install/windows.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/xmake/rules/qt/install/windows.lua b/xmake/rules/qt/install/windows.lua index 9d0038fc1..911a8fcd7 100644 --- a/xmake/rules/qt/install/windows.lua +++ b/xmake/rules/qt/install/windows.lua @@ -23,6 +23,7 @@ import("core.theme.theme") import("core.base.option") import("core.project.config") import("core.project.depend") +import("core.tool.toolchain") import("detect.sdks.find_vstudio") import("private.utils.progress") -- cgit v1.3.1 From dea1fb125f09841b11037bd6017f805a20da919f Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Thu, 17 Dec 2020 11:08:14 +0100 Subject: Fix depend file --- xmake/rules/qt/install/windows.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/rules/qt/install/windows.lua b/xmake/rules/qt/install/windows.lua index 911a8fcd7..0a542a537 100644 --- a/xmake/rules/qt/install/windows.lua +++ b/xmake/rules/qt/install/windows.lua @@ -34,7 +34,7 @@ function main(target, opt) local installfile = path.join(target:installdir(), "bin", path.filename(targetfile)) -- need re-generate this app? - local dependfile = target:dependfile(targetfile) + local dependfile = target:dependfile(installfile) depend.on_changed(function () -- do deploy @@ -83,5 +83,5 @@ function main(target, opt) table.insert(argv, installfile) os.vrunv(windeployqt, argv, {envs = envs}) - end, {dependfile = dependfile, files = targetfile}) + end, {dependfile = dependfile, files = installfile}) end -- cgit v1.3.1 From e96544dd1899b1d585c6c56c4f2a7061b942a11a Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Thu, 17 Dec 2020 11:59:03 +0100 Subject: Don't rely on dependency system --- xmake/rules/qt/install/windows.lua | 79 ++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/xmake/rules/qt/install/windows.lua b/xmake/rules/qt/install/windows.lua index 0a542a537..8b552212f 100644 --- a/xmake/rules/qt/install/windows.lua +++ b/xmake/rules/qt/install/windows.lua @@ -33,55 +33,50 @@ function main(target, opt) local targetfile = target:targetfile() local installfile = path.join(target:installdir(), "bin", path.filename(targetfile)) - -- need re-generate this app? - local dependfile = target:dependfile(installfile) + -- do deploy + + -- get qt sdk + local qt = target:data("qt") - depend.on_changed(function () - -- do deploy - - -- get qt sdk - local qt = target:data("qt") + -- get windeployqt + local windeployqt = path.join(qt.bindir, "windeployqt.exe") + assert(os.isexec(windeployqt), "windeployqt.exe not found!") - -- get windeployqt - local windeployqt = path.join(qt.bindir, "windeployqt.exe") - assert(os.isexec(windeployqt), "windeployqt.exe not found!") - - -- find qml directory - local qmldir = nil - for _, sourcebatch in pairs(target:sourcebatches()) do - if sourcebatch.rulename == "qt.qrc" then - for _, sourcefile in ipairs(sourcebatch.sourcefiles) do - qmldir = find_path("*.qml", path.directory(sourcefile)) - if qmldir then - break - end + -- find qml directory + local qmldir = nil + for _, sourcebatch in pairs(target:sourcebatches()) do + if sourcebatch.rulename == "qt.qrc" then + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + qmldir = find_path("*.qml", path.directory(sourcefile)) + if qmldir then + break end end end + end - -- find msvc to set VCINSTALLDIR env - local envs = nil - local msvc = toolchain.load("msvc", {plat = target:plat(), arch = target:arch()}) - if msvc then - local vcvars = msvc:config("vcvars") - if vcvars and vcvars.VSInstallDir then - envs = {VCINSTALLDIR = path.join(vcvars.VSInstallDir, "VC")} - end + -- find msvc to set VCINSTALLDIR env + local envs = nil + local msvc = toolchain.load("msvc", {plat = target:plat(), arch = target:arch()}) + if msvc then + local vcvars = msvc:config("vcvars") + if vcvars and vcvars.VSInstallDir then + envs = {VCINSTALLDIR = path.join(vcvars.VSInstallDir, "VC")} end + end - local argv = {"--force"} - if option.get("diagnosis") then - table.insert(argv, "--verbose=2") - elseif option.get("verbose") then - table.insert(argv, "--verbose=1") - else - table.insert(argv, "--verbose=0") - end - if qmldir then - table.insert(argv, "--qmldir=" .. qmldir) - end - table.insert(argv, installfile) + local argv = {"--force"} + if option.get("diagnosis") then + table.insert(argv, "--verbose=2") + elseif option.get("verbose") then + table.insert(argv, "--verbose=1") + else + table.insert(argv, "--verbose=0") + end + if qmldir then + table.insert(argv, "--qmldir=" .. qmldir) + end + table.insert(argv, installfile) - os.vrunv(windeployqt, argv, {envs = envs}) - end, {dependfile = dependfile, files = installfile}) + os.vrunv(windeployqt, argv, {envs = envs}) end -- cgit v1.3.1 From 68ae2e301eac32bbf87ae403895a4b1e6a3068b1 Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Thu, 17 Dec 2020 12:03:54 +0100 Subject: Remove useless import --- xmake/rules/qt/install/windows.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/xmake/rules/qt/install/windows.lua b/xmake/rules/qt/install/windows.lua index 8b552212f..fd7b4e5d6 100644 --- a/xmake/rules/qt/install/windows.lua +++ b/xmake/rules/qt/install/windows.lua @@ -19,21 +19,16 @@ -- -- imports -import("core.theme.theme") import("core.base.option") import("core.project.config") -import("core.project.depend") import("core.tool.toolchain") import("detect.sdks.find_vstudio") -import("private.utils.progress") -- install application package for windows function main(target, opt) local targetfile = target:targetfile() local installfile = path.join(target:installdir(), "bin", path.filename(targetfile)) - - -- do deploy -- get qt sdk local qt = target:data("qt") -- cgit v1.3.1 From 4392ac36fa097bba6a9493c1f90a0d1ff0954699 Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Thu, 17 Dec 2020 14:03:31 +0100 Subject: Fix imports --- xmake/rules/qt/install/windows.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/rules/qt/install/windows.lua b/xmake/rules/qt/install/windows.lua index fd7b4e5d6..03bd84f8f 100644 --- a/xmake/rules/qt/install/windows.lua +++ b/xmake/rules/qt/install/windows.lua @@ -22,7 +22,7 @@ import("core.base.option") import("core.project.config") import("core.tool.toolchain") -import("detect.sdks.find_vstudio") +import("lib.detect.find_path") -- install application package for windows function main(target, opt) -- cgit v1.3.1