diff options
| author | Chan Lee <[email protected]> | 2025-01-22 17:25:06 +0800 |
|---|---|---|
| committer | Chan Lee <[email protected]> | 2025-01-22 17:25:06 +0800 |
| commit | bb89dfcc8a32c401b2208ce9c1f8a1862bb5a574 (patch) | |
| tree | 82f71a4c2cfc0343660297ac199fd2b7bc2e61a6 /xmake/rules | |
| parent | c61d7bb40353b161da913bdcbc6fa399e36164a1 (diff) | |
Add `qt_host` option to enable cross-platform Qt Builds using host SDK tools
Diffstat (limited to 'xmake/rules')
| -rw-r--r-- | xmake/rules/qt/deploy/android.lua | 24 | ||||
| -rw-r--r-- | xmake/rules/qt/deploy/macosx.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/qt/env/xmake.lua | 7 | ||||
| -rw-r--r-- | xmake/rules/qt/install/mingw.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/qt/install/windows.lua | 16 | ||||
| -rw-r--r-- | xmake/rules/qt/load.lua | 7 | ||||
| -rw-r--r-- | xmake/rules/qt/moc/xmake.lua | 14 | ||||
| -rw-r--r-- | xmake/rules/qt/qmltyperegistrar/xmake.lua | 15 | ||||
| -rw-r--r-- | xmake/rules/qt/qrc/xmake.lua | 14 | ||||
| -rw-r--r-- | xmake/rules/qt/ts/xmake.lua | 27 | ||||
| -rw-r--r-- | xmake/rules/qt/ui/xmake.lua | 14 |
11 files changed, 89 insertions, 61 deletions
diff --git a/xmake/rules/qt/deploy/android.lua b/xmake/rules/qt/deploy/android.lua index 9299c61e0..524afe533 100644 --- a/xmake/rules/qt/deploy/android.lua +++ b/xmake/rules/qt/deploy/android.lua @@ -71,10 +71,10 @@ function main(target, opt) end -- get androiddeployqt - local androiddeployqt = path.join(qt.bindir, "androiddeployqt" .. (is_host("windows") and ".exe" or "")) - if not os.isexec(androiddeployqt) and qt.bindir_host then - androiddeployqt = path.join(qt.bindir_host, "androiddeployqt" .. (is_host("windows") and ".exe" or "")) - end + 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 + local androiddeployqt = find_file("androiddeployqt" .. (is_host("windows") and ".exe" or ""), search_dirs) assert(os.isexec(androiddeployqt), "androiddeployqt not found!") -- get working directory @@ -152,18 +152,18 @@ function main(target, opt) settings_file:print(' "target-architecture": "%s",', target_arch) settings_file:print(' "qml-root-path": "%s",', _escape_path(os.projectdir())) -- for 6.2.x - local qmlimportscanner = path.join(qt.libexecdir, "qmlimportscanner") - if not os.isexec(qmlimportscanner) and qt.libexecdir_host then - qmlimportscanner = path.join(qt.libexecdir_host, "qmlimportscanner") - end + local search_dirs = {} + if qt.libexecdir_host then table.insert(search_dirs, qt.libexecdir_host) end + if qt.libexecdir then table.insert(search_dirs, qt.libexecdir) end + local qmlimportscanner = find_file("qmlimportscanner" .. (is_host("windows") and ".exe" or ""), search_dirs) if os.isexec(qmlimportscanner) then settings_file:print(' "qml-importscanner-binary": "%s",', _escape_path(qmlimportscanner)) end -- for 6.3.x - local rcc = path.join(qt.bindir, "rcc") - if not os.isexec(rcc) and qt.bindir_host then - rcc = path.join(qt.bindir_host, "rcc") - end + 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 + local rcc = find_file("rcc" .. (is_host("windows") and ".exe" or ""), search_dirs) if os.isexec(rcc) then settings_file:print(' "rcc-binary": "%s",', _escape_path(rcc)) end diff --git a/xmake/rules/qt/deploy/macosx.lua b/xmake/rules/qt/deploy/macosx.lua index 7cc056099..a184647fb 100644 --- a/xmake/rules/qt/deploy/macosx.lua +++ b/xmake/rules/qt/deploy/macosx.lua @@ -24,6 +24,7 @@ import("core.base.option") import("core.project.config") import("core.project.depend") import("core.tool.toolchain") +import("lib.detect.find_file") import("lib.detect.find_path") import("detect.sdks.find_qt") import("utils.progress") @@ -91,7 +92,10 @@ function main(target, opt) local qt = assert(find_qt(), "Qt SDK not found!") -- get macdeployqt - local macdeployqt = path.join(qt.bindir, "macdeployqt") + 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 + local macdeployqt = find_file("macdeployqt" .. (is_host("windows") and ".exe" or ""), search_dirs) assert(os.isexec(macdeployqt), "macdeployqt not found!") -- generate target app diff --git a/xmake/rules/qt/env/xmake.lua b/xmake/rules/qt/env/xmake.lua index afaf62ae4..8737d6385 100644 --- a/xmake/rules/qt/env/xmake.lua +++ b/xmake/rules/qt/env/xmake.lua @@ -33,7 +33,12 @@ rule("qt.env") local qmlimportpath = target:values("qt.env.qmlimportpath") or {} if target:is_plat("windows") or (target:is_plat("mingw") and is_host("windows")) then - target:add("runenvs", "PATH", qt.bindir) + if qt.bindir_host then + target:add("runenvs", "PATH", qt.bindir_host) + end + if qt.bindir then + target:add("runenvs", "PATH", qt.bindir) + end table.insert(qmlimportpath, qt.qmldir) -- add targetdir in QML2_IMPORT_PATH in case of the user have qml plugins table.insert(qmlimportpath, target:targetdir()) diff --git a/xmake/rules/qt/install/mingw.lua b/xmake/rules/qt/install/mingw.lua index 9bf282c23..4e3fe6d19 100644 --- a/xmake/rules/qt/install/mingw.lua +++ b/xmake/rules/qt/install/mingw.lua @@ -23,6 +23,7 @@ import("core.base.option") import("core.project.config") import("core.tool.toolchain") import("lib.detect.find_path") +import("lib.detect.find_file") import("detect.sdks.find_qt") -- get install directory @@ -42,7 +43,10 @@ function main(target, opt) local qt = assert(find_qt(), "Qt SDK not found!") -- get windeployqt - local windeployqt = path.join(qt.bindir, "windeployqt.exe") + 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 + local windeployqt = find_file("windeployqt" .. (is_host("windows") and ".exe" or ""), search_dirs) assert(os.isexec(windeployqt), "windeployqt.exe not found!") -- find qml directory diff --git a/xmake/rules/qt/install/windows.lua b/xmake/rules/qt/install/windows.lua index 7b8436e1b..0eca909e9 100644 --- a/xmake/rules/qt/install/windows.lua +++ b/xmake/rules/qt/install/windows.lua @@ -22,6 +22,7 @@ import("core.base.option") import("core.project.config") import("core.tool.toolchain") +import("lib.detect.find_file") import("lib.detect.find_path") import("detect.sdks.find_qt") @@ -42,7 +43,10 @@ function main(target, opt) local qt = assert(find_qt(), "Qt SDK not found!") -- get windeployqt - local windeployqt = path.join(qt.bindir, "windeployqt.exe") + 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 + local windeployqt = find_file("windeployqt" .. (is_host("windows") and ".exe" or ""), search_dirs) assert(os.isexec(windeployqt), "windeployqt.exe not found!") -- find qml directory @@ -73,9 +77,15 @@ function main(target, opt) end -- bind qt bin path -- https://github.com/xmake-io/xmake/issues/4297 - if qt.bindir then + if qt.bindir_host or qt.bindir then envs = envs or {} - envs.PATH = {qt.bindir} + envs.PATH = {} + if qt.bindir_host then + table.insert(envs.PATH, qt.bindir_host) + end + if qt.bindir then + table.insert(envs.PATH, qt.bindir) + end local curpath = os.getenv("PATH") if curpath then table.join2(envs.PATH, path.splitenv(curpath)) diff --git a/xmake/rules/qt/load.lua b/xmake/rules/qt/load.lua index c9269b0b6..7bf4ecac6 100644 --- a/xmake/rules/qt/load.lua +++ b/xmake/rules/qt/load.lua @@ -449,7 +449,12 @@ function main(target, opt) target:add("linkdirs", qt.libdir) target:add("syslinks", "ws2_32", "gdi32", "ole32", "advapi32", "shell32", "user32", "opengl32", "imm32", "winmm", "iphlpapi") -- for debugger, https://github.com/xmake-io/xmake-vscode/issues/225 - target:add("runenvs", "PATH", qt.bindir) + if qt.bindir_host then + target:add("runenvs", "PATH", qt.bindir_host) + end + if qt.bindir then + target:add("runenvs", "PATH", qt.bindir) + end elseif target:is_plat("mingw") then target:set("frameworks", nil) -- we need to fix it, because gcc maybe does not work on latest mingw when `-isystem D:\a\_temp\msys64\mingw64\include` is passed. diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua index d4272b688..2807f2bc9 100644 --- a/xmake/rules/qt/moc/xmake.lua +++ b/xmake/rules/qt/moc/xmake.lua @@ -24,16 +24,16 @@ rule("qt.moc") set_extensions(".h", ".hpp") before_buildcmd_file(function (target, batchcmds, sourcefile, opt) import("core.tool.compiler") + import("lib.detect.find_file") -- get moc local qt = assert(target:data("qt"), "Qt not found!") - local moc = path.join(qt.bindir, is_host("windows") and "moc.exe" or "moc") - if not os.isexec(moc) and qt.libexecdir then - moc = path.join(qt.libexecdir, is_host("windows") and "moc.exe" or "moc") - end - if not os.isexec(moc) and qt.libexecdir_host then - moc = path.join(qt.libexecdir_host, is_host("windows") and "moc.exe" or "moc") - end + 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 + if qt.libexecdir_host then table.insert(search_dirs, qt.libexecdir_host) end + if qt.libexecdir then table.insert(search_dirs, qt.libexecdir) end + local moc = find_file(is_host("windows") and "moc.exe" or "moc", search_dirs) assert(moc and os.isexec(moc), "moc not found!") -- get c++ source file for moc diff --git a/xmake/rules/qt/qmltyperegistrar/xmake.lua b/xmake/rules/qt/qmltyperegistrar/xmake.lua index 8e25f109e..3d6245e2f 100644 --- a/xmake/rules/qt/qmltyperegistrar/xmake.lua +++ b/xmake/rules/qt/qmltyperegistrar/xmake.lua @@ -23,17 +23,18 @@ rule("qt.qmltyperegistrar") set_extensions(".h", ".hpp") on_config(function(target) + import("lib.detect.find_file") + -- 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 + 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 + if qt.libexecdir_host then table.insert(search_dirs, qt.libexecdir_host) end + if qt.libexecdir then table.insert(search_dirs, qt.libexecdir) end + local qmltyperegistrar = find_file(is_host("windows") and "qmltyperegistrar.exe" or "qmltyperegistrar", search_dirs) assert(qmltyperegistrar and os.isexec(qmltyperegistrar), "qmltyperegistrar not found!") -- set targetdir diff --git a/xmake/rules/qt/qrc/xmake.lua b/xmake/rules/qt/qrc/xmake.lua index 084a7fff0..9af30118c 100644 --- a/xmake/rules/qt/qrc/xmake.lua +++ b/xmake/rules/qt/qrc/xmake.lua @@ -22,16 +22,16 @@ rule("qt.qrc") add_deps("qt.env") set_extensions(".qrc") on_config(function (target) + import("lib.detect.find_file") -- get rcc local qt = assert(target:data("qt"), "Qt not found!") - local rcc = path.join(qt.bindir, is_host("windows") and "rcc.exe" or "rcc") - if not os.isexec(rcc) and qt.libexecdir then - rcc = path.join(qt.libexecdir, is_host("windows") and "rcc.exe" or "rcc") - end - if not os.isexec(rcc) and qt.libexecdir_host then - rcc = path.join(qt.libexecdir_host, is_host("windows") and "rcc.exe" or "rcc") - end + 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 + if qt.libexecdir_host then table.insert(search_dirs, qt.libexecdir_host) end + if qt.libexecdir then table.insert(search_dirs, qt.libexecdir) end + local rcc = find_file(is_host("windows") and "rcc.exe" or "rcc", search_dirs) assert(os.isexec(rcc), "rcc not found!") -- save rcc diff --git a/xmake/rules/qt/ts/xmake.lua b/xmake/rules/qt/ts/xmake.lua index 95e44d2a2..9f8a8e59c 100644 --- a/xmake/rules/qt/ts/xmake.lua +++ b/xmake/rules/qt/ts/xmake.lua @@ -3,6 +3,8 @@ rule("qt.ts") set_extensions(".ts") on_config(function (target) + import("lib.detect.find_file") + -- get source file local lupdate_argv = {"-no-obsolete"} local sourcefile_ts @@ -20,22 +22,19 @@ rule("qt.ts") if sourcefile_ts then -- get lupdate and lrelease local qt = assert(target:data("qt"), "qt not found!") - local lupdate = path.join(qt.bindir, is_host("windows") and "lupdate.exe" or "lupdate") - local lrelease = path.join(qt.bindir, is_host("windows") and "lrelease.exe" or "lrelease") - if not os.isexec(lupdate) and qt.libexecdir then - lupdate = path.join(qt.libexecdir, is_host("windows") and "lupdate.exe" or "lupdate") - end - if not os.isexec(lrelease) and qt.libexecdir then - lrelease = path.join(qt.libexecdir, is_host("windows") and "lrelease.exe" or "lrelease") - end - if not os.isexec(lupdate) and qt.libexecdir_host then - lupdate = path.join(qt.libexecdir_host, is_host("windows") and "lupdate.exe" or "lupdate") - end - if not os.isexec(lrelease) and qt.libexecdir_host then - lrelease = path.join(qt.libexecdir_host, is_host("windows") and "lrelease.exe" or "lrelease") - end + + 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 + if qt.libexecdir_host then table.insert(search_dirs, qt.libexecdir_host) end + if qt.libexecdir then table.insert(search_dirs, qt.libexecdir) end + + local lupdate = find_file(is_host("windows") and "lupdate.exe" or "lupdate", search_dirs) assert(os.isexec(lupdate), "lupdate not found!") + + local lrelease = find_file(is_host("windows") and "lrelease.exe" or "lrelease", search_dirs) assert(os.isexec(lrelease), "lrelease not found!") + for _, tsfile in ipairs(sourcefile_ts) do local tsargv = {} table.join2(tsargv, lupdate_argv) diff --git a/xmake/rules/qt/ui/xmake.lua b/xmake/rules/qt/ui/xmake.lua index b4f769050..2fdeb79f6 100644 --- a/xmake/rules/qt/ui/xmake.lua +++ b/xmake/rules/qt/ui/xmake.lua @@ -22,16 +22,16 @@ rule("qt.ui") add_deps("qt.env") set_extensions(".ui") on_config(function (target) + import("lib.detect.find_file") -- get uic local qt = assert(target:data("qt"), "Qt not found!") - local uic = path.join(qt.bindir, is_host("windows") and "uic.exe" or "uic") - if not os.isexec(uic) and qt.libexecdir then - uic = path.join(qt.libexecdir, is_host("windows") and "uic.exe" or "uic") - end - if not os.isexec(uic) and qt.libexecdir_host then - uic = path.join(qt.libexecdir_host, is_host("windows") and "uic.exe" or "uic") - end + 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 + if qt.libexecdir_host then table.insert(search_dirs, qt.libexecdir_host) end + if qt.libexecdir then table.insert(search_dirs, qt.libexecdir) end + local uic = find_file(is_host("windows") and "uic.exe" or "uic", search_dirs) assert(uic and os.isexec(uic), "uic not found!") -- add includedirs, @note we need to create this directory first to suppress warning (file not found). |
