summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChan Lee <[email protected]>2025-01-22 17:25:06 +0800
committerChan Lee <[email protected]>2025-01-22 17:25:06 +0800
commitbb89dfcc8a32c401b2208ce9c1f8a1862bb5a574 (patch)
tree82f71a4c2cfc0343660297ac199fd2b7bc2e61a6
parentc61d7bb40353b161da913bdcbc6fa399e36164a1 (diff)
Add `qt_host` option to enable cross-platform Qt Builds using host SDK tools
-rw-r--r--xmake/modules/detect/sdks/find_qt.lua65
-rw-r--r--xmake/platforms/bsd/xmake.lua2
-rw-r--r--xmake/platforms/haiku/xmake.lua2
-rw-r--r--xmake/platforms/linux/xmake.lua2
-rw-r--r--xmake/platforms/macosx/xmake.lua2
-rw-r--r--xmake/platforms/windows/xmake.lua2
-rw-r--r--xmake/rules/qt/deploy/android.lua24
-rw-r--r--xmake/rules/qt/deploy/macosx.lua6
-rw-r--r--xmake/rules/qt/env/xmake.lua7
-rw-r--r--xmake/rules/qt/install/mingw.lua6
-rw-r--r--xmake/rules/qt/install/windows.lua16
-rw-r--r--xmake/rules/qt/load.lua7
-rw-r--r--xmake/rules/qt/moc/xmake.lua14
-rw-r--r--xmake/rules/qt/qmltyperegistrar/xmake.lua15
-rw-r--r--xmake/rules/qt/qrc/xmake.lua14
-rw-r--r--xmake/rules/qt/ts/xmake.lua27
-rw-r--r--xmake/rules/qt/ui/xmake.lua14
17 files changed, 155 insertions, 70 deletions
diff --git a/xmake/modules/detect/sdks/find_qt.lua b/xmake/modules/detect/sdks/find_qt.lua
index 1a9e79f76..d720ac8b8 100644
--- a/xmake/modules/detect/sdks/find_qt.lua
+++ b/xmake/modules/detect/sdks/find_qt.lua
@@ -190,11 +190,21 @@ function _find_qmake(sdkdir, sdkver)
end
-- get qt environment
-function _get_qtenvs(qmake)
+function _get_qtenvs(qmake, sdkdir)
local envs = {}
+ local run_args = {"-query"}
+ if sdkdir then
+ local conf_paths = {path.join(sdkdir, "bin", "target_qt.conf"), path.join(sdkdir, "bin", "qt.conf")}
+ for _, conf_path in ipairs(conf_paths) do
+ if os.isfile(conf_path) then
+ table.join2(run_args, {"-qtconf", conf_path})
+ break
+ end
+ end
+ end
local results = try {
function ()
- return os.iorunv(qmake, {"-query"})
+ return os.iorunv(qmake, run_args)
end,
catch {
function (errors)
@@ -215,24 +225,44 @@ function _get_qtenvs(qmake)
end
end
+-- Verify and correct the Qt SDK version for cross-compiling.
+-- qmake reports its own version (QT_VERSION), not the version specified in the SDK's configuration files.
+function _tryfix_sdkver_for_cross(sdkdir, sdkver)
+ local qconfig_path = sdkdir and path.join(sdkdir, "mkspecs", "qconfig.pri")
+ if not sdkver or not os.isfile(qconfig_path) then
+ return sdkver
+ end
+ -- Extract the actual SDK version from qconfig.pri
+ local qconfig = io.readfile(qconfig_path)
+ local actual_sdkver = qconfig and qconfig:match("QT_VERSION%s*=%s*(%S+)") -- Expected format: QT_VERSION = x.y.z
+ if not actual_sdkver then
+ return sdkver
+ end
+ if sdkver ~= actual_sdkver then
+ wprint("Host Qt SDK version (%s) differs from Target Qt SDK version (%s). To prevent build issues, please ensure both use the same version.", sdkver, actual_sdkver);
+ end
+ return actual_sdkver
+end
+
-- find qt sdk toolchains
-function _find_qt(sdkdir, sdkver)
+function _find_qt(sdkdir, sdkver, sdkdir_host)
-- find qmake
- local qmake = _find_qmake(sdkdir, sdkver)
+ local qmake = _find_qmake(sdkdir_host or sdkdir, sdkver)
if not qmake then
return
end
-- get qt environments
- local qtenvs = _get_qtenvs(qmake)
+ local located_sdkdir = sdkdir and _find_sdkdir(sdkdir, sdkver)
+ local qtenvs = _get_qtenvs(qmake, located_sdkdir or sdkdir)
if not qtenvs then
return
end
-- get qt toolchains
sdkdir = qtenvs.QT_INSTALL_PREFIX
- local sdkver = qtenvs.QT_VERSION
+ local sdkver = _tryfix_sdkver_for_cross(sdkdir, qtenvs.QT_VERSION)
local bindir = qtenvs.QT_INSTALL_BINS
local libexecdir = qtenvs.QT_INSTALL_LIBEXECS
local qmldir = qtenvs.QT_INSTALL_QML
@@ -259,6 +289,16 @@ function _find_qt(sdkdir, sdkver)
-- TODO
end
end
+
+ if sdkdir_host then
+ local located_sdkdir_host = _find_sdkdir(sdkdir_host, sdkver)
+ local qtenvs_host = _get_qtenvs(qmake, located_sdkdir_host or sdkdir_host)
+ if qtenvs_host then
+ bindir_host = qtenvs_host.QT_HOST_BINS or qtenvs_host.QT_INSTALL_BINS or bindir_host
+ libexecdir_host = qtenvs_host.QT_HOST_LIBEXECS or qtenvs_host.QT_INSTALL_LIBEXECS or libexecdir_host
+ end
+ end
+
return {sdkdir = sdkdir, bindir = bindir, bindir_host = bindir_host, libexecdir = libexecdir, libexecdir_host = libexecdir_host, libdir = libdir, includedir = includedir, qmldir = qmldir, pluginsdir = pluginsdir, mkspecsdir = mkspecsdir, sdkver = sdkver}
end
@@ -282,13 +322,16 @@ function main(sdkdir, opt)
-- attempt to load cache first
local key = "detect.sdks.find_qt"
- local cacheinfo = detectcache:get(key) or {}
+ local cacheinfo = (sdkdir and detectcache:get2(key, sdkdir)) or detectcache:get(key) or {}
if not opt.force and cacheinfo.qt and cacheinfo.qt.sdkdir and os.isdir(cacheinfo.qt.sdkdir) then
return cacheinfo.qt
end
-- find qt
- local qt = _find_qt(sdkdir or config.get("qt") or global.get("qt") or config.get("sdk"), opt.version or config.get("qt_sdkver"))
+ local sdkdir = sdkdir or config.get("qt") or global.get("qt") or config.get("sdk")
+ local sdkver = opt.version or config.get("qt_sdkver")
+ local sdkdir_host = opt.sdkdir_host or config.get("qt_host") or global.get("qt_host")
+ local qt = _find_qt(sdkdir, sdkver, sdkdir_host)
if qt then
-- save to config
@@ -314,7 +357,11 @@ function main(sdkdir, opt)
-- save to cache
cacheinfo.qt = qt or false
- detectcache:set(key, cacheinfo)
+ if sdkdir then
+ detectcache:set2(key, sdkdir, cacheinfo)
+ else
+ detectcache:set(key, cacheinfo)
+ end
detectcache:save()
return qt
end
diff --git a/xmake/platforms/bsd/xmake.lua b/xmake/platforms/bsd/xmake.lua
index 4b09fa68d..268941462 100644
--- a/xmake/platforms/bsd/xmake.lua
+++ b/xmake/platforms/bsd/xmake.lua
@@ -39,6 +39,7 @@ platform("bsd")
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
+ , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
, {nil, "qt_sdkver", "kv", "auto", "The Qt SDK Version" }
}
@@ -48,6 +49,7 @@ platform("bsd")
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
+ , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
}
}
diff --git a/xmake/platforms/haiku/xmake.lua b/xmake/platforms/haiku/xmake.lua
index ba215545e..aef1d9b71 100644
--- a/xmake/platforms/haiku/xmake.lua
+++ b/xmake/platforms/haiku/xmake.lua
@@ -37,6 +37,7 @@ platform("haiku")
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
+ , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
, {nil, "qt_sdkver", "kv", "auto", "The Qt SDK Version" }
}
@@ -46,6 +47,7 @@ platform("haiku")
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
+ , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
}
}
diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua
index e4d57b533..ec2b6e74b 100644
--- a/xmake/platforms/linux/xmake.lua
+++ b/xmake/platforms/linux/xmake.lua
@@ -38,6 +38,7 @@ platform("linux")
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
+ , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
, {nil, "qt_sdkver", "kv", "auto", "The Qt SDK Version" }
, {category = "Vcpkg Configuration" }
, {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" }
@@ -49,6 +50,7 @@ platform("linux")
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
+ , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
, {category = "Vcpkg Configuration" }
, {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" }
}
diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua
index 74e50fb50..6cd854ff8 100644
--- a/xmake/platforms/macosx/xmake.lua
+++ b/xmake/platforms/macosx/xmake.lua
@@ -47,6 +47,7 @@ platform("macosx")
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
+ , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
, {nil, "qt_sdkver", "kv", "auto", "The Qt SDK Version" }
, {category = "Vcpkg Configuration" }
, {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" }
@@ -63,6 +64,7 @@ platform("macosx")
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
+ , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
, {category = "Vcpkg Configuration" }
, {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" }
}
diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua
index 2b1bf4014..d87d99fa8 100644
--- a/xmake/platforms/windows/xmake.lua
+++ b/xmake/platforms/windows/xmake.lua
@@ -47,6 +47,7 @@ platform("windows")
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
+ , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
, {nil, "qt_sdkver", "kv", "auto", "The Qt SDK Version" }
, {category = "WDK Configuration" }
, {nil, "wdk", "kv", "auto", "The WDK Directory" }
@@ -71,6 +72,7 @@ platform("windows")
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
+ , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
, {category = "WDK Configuration" }
, {nil, "wdk", "kv", "auto", "The WDK Directory" }
, {category = "Vcpkg Configuration" }
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).