summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-18 22:37:42 +0800
committerruki <[email protected]>2020-04-18 22:37:42 +0800
commit67d307e0ddad7a0988237a2fc3d34759c4561591 (patch)
treead6e42e023534587d9db2ccf3d0305d37a611bbe
parent0ef9076bdb3423f69a05d51389078cafe475d741 (diff)
improve qt and deploy
-rw-r--r--xmake/modules/detect/sdks/find_qt.lua16
-rw-r--r--xmake/rules/qt/deploy/android.lua82
-rw-r--r--xmake/rules/qt/load.lua13
3 files changed, 83 insertions, 28 deletions
diff --git a/xmake/modules/detect/sdks/find_qt.lua b/xmake/modules/detect/sdks/find_qt.lua
index 9062a9212..a6a5d20f6 100644
--- a/xmake/modules/detect/sdks/find_qt.lua
+++ b/xmake/modules/detect/sdks/find_qt.lua
@@ -46,17 +46,23 @@ function _find_sdkdir(sdkdir, sdkver)
elseif is_plat("mingw") then
table.insert(subdirs, path.join(sdkver or "*", is_arch("x86_64") and "mingw*_64" or "mingw*_32", "bin"))
elseif is_plat("android") then
- local subdir = "android_*"
+ local subdir
if is_arch("arm64-v8a") then
subdir = "android_arm64_v8a"
elseif is_arch("armeabi-v7a", "armeabi", "armv7-a", "armv5te") then -- armv7-a/armv5te are deprecated
subdir = "android_armv7"
- elseif is_arch("i386") then
+ elseif is_arch("x86", "i386") then -- i386 is deprecated
subdir = "android_x86"
+ elseif is_arch("x86_64") then
+ subdir = "android_x86_64"
end
- table.insert(subdirs, path.join(sdkver or "*", subdir, "bin"))
+ if subdir then
+ table.insert(subdirs, path.join(sdkver or "*", subdir, "bin"))
+ end
+ table.insert(subdirs, path.join(sdkver or "*", "android", "bin"))
+ else
+ table.insert(subdirs, path.join(sdkver or "*", "*", "bin"))
end
- table.insert(subdirs, path.join(sdkver or "*", "*", "bin"))
table.insert(subdirs, path.join("*", "bin"))
table.insert(subdirs, "bin")
@@ -96,8 +102,8 @@ function _find_sdkdir(sdkdir, sdkver)
end
end
else
- table.insert(pathes, "~/Qt")
table.insert(pathes, "~/Qt*")
+ table.insert(pathes, "~/Qt")
end
-- attempt to find qmake
diff --git a/xmake/rules/qt/deploy/android.lua b/xmake/rules/qt/deploy/android.lua
index f89c08aa1..e682c45a0 100644
--- a/xmake/rules/qt/deploy/android.lua
+++ b/xmake/rules/qt/deploy/android.lua
@@ -21,6 +21,7 @@
-- imports
import("core.theme.theme")
import("core.base.option")
+import("core.base.semver")
import("core.project.config")
-- escape path
@@ -81,6 +82,12 @@ function main(target, opt)
-- get android build-tools version
local android_build_toolver = assert(config.get("build_toolver"), "please run `xmake f --build_toolver=xxx` to set the android build-tools version!")
+ -- get qt sdk version
+ local qt_sdkver = config.get("qt_sdkver")
+ if qt_sdkver then
+ qt_sdkver = try { function () return semver.new(qt_sdkver) end}
+ end
+
-- get the target architecture
local target_archs =
{
@@ -97,35 +104,67 @@ function main(target, opt)
local target_arch = assert(target_archs[config.arch()], "unsupport target arch(%s)!", config.arch())
-- install target to android-build/libs first
- os.cp(target:targetfile(), path.join(android_buildir, "libs", target_arch, path.filename(target:targetfile())))
+ if qt_sdkver and qt_sdkver:ge("5.14") then
+ -- we need copy target to android-build/libs/armeabi/libxxx_armeabi.so after Qt 5.14.0
+ os.cp(target:targetfile(), path.join(android_buildir, "libs", target_arch, "lib" .. target:basename() .. "_" .. target_arch .. ".so"))
+ else
+ os.cp(target:targetfile(), path.join(android_buildir, "libs", target_arch, path.filename(target:targetfile())))
+ end
-- get stdcpp path
local stdcpp_path = path.join(ndk, "sources/cxx-stl/llvm-libc++/libs", target_arch, "libc++_shared.so")
+ if qt_sdkver and qt_sdkver:ge("5.14") then
+ local toolchain = path.directory(assert(config.get("bin"), "toolchain/bin directory not found!"))
+ stdcpp_path = path.join(toolchain, "sysroot", "usr", "lib")
+ end
-- get toolchain version
local ndk_toolchains_ver = config.get("ndk_toolchains_ver") or "4.9"
-- generate android-deployment-settings.json file
local android_deployment_settings = path.join(workdir, "android-deployment-settings.json")
- io.writefile(android_deployment_settings, format([[
- {
- "description": "This file is generated by qmake to be read by androiddeployqt and should not be modified by hand.",
- "qt": "%s",
- "sdk": "%s",
- "ndk": "%s",
- "sdkBuildToolsRevision": "%s",
- "toolchain-prefix": "llvm",
- "tool-prefix": "llvm",
- "toolchain-version": "%s",
- "ndk-host": "%s",
- "target-architecture": "%s",
- "qml-root-path": "%s",
- "stdcpp-path": "%s",
- "useLLVM": true,
- "application-binary": "%s"
- }]], _escape_path(qt.sdkdir), _escape_path(android_sdkdir), _escape_path(ndk),
- android_build_toolver, ndk_toolchains_ver, ndk_host, target_arch,
- _escape_path(os.projectdir()), _escape_path(stdcpp_path), _escape_path(target:targetfile())))
+ local settings_file = io.open(android_deployment_settings, "w")
+ if settings_file then
+ settings_file:print('{')
+ settings_file:print(' "description": "This file is generated by qmake to be read by androiddeployqt and should not be modified by hand.",')
+ settings_file:print(' "qt": "%s",', _escape_path(qt.sdkdir))
+ settings_file:print(' "sdk": "%s",', _escape_path(android_sdkdir))
+ settings_file:print(' "ndk": "%s",', _escape_path(ndk))
+ settings_file:print(' "sdkBuildToolsRevision": "%s",', android_build_toolver)
+ settings_file:print(' "toolchain-prefix": "llvm",')
+ settings_file:print(' "tool-prefix": "llvm",')
+ settings_file:print(' "toolchain-version": "%s",', ndk_toolchains_ver)
+ settings_file:print(' "stdcpp-path": "%s",', _escape_path(stdcpp_path))
+ settings_file:print(' "ndk-host": "%s",', ndk_host)
+ settings_file:print(' "target-architecture": "%s",', target_arch)
+ settings_file:print(' "qml-root-path": "%s",', _escape_path(os.projectdir()))
+ settings_file:print(' "useLLVM": true,')
+ if qt_sdkver and qt_sdkver:ge("5.14") then
+ -- @see https://codereview.qt-project.org/c/qt-creator/qt-creator/+/287145
+ local triples =
+ {
+ ["armv5te"] = "arm-linux-androideabi" -- deprecated
+ , ["armv7-a"] = "arm-linux-androideabi" -- deprecated
+ , ["armeabi"] = "arm-linux-androideabi" -- removed in ndk r17
+ , ["armeabi-v7a"] = "arm-linux-androideabi"
+ , ["arm64-v8a"] = "aarch64-linux-android"
+ , i386 = "i686-linux-android" -- deprecated
+ , x86 = "i686-linux-android"
+ , x86_64 = "x86_64-linux-android"
+ , mips = "mips-linux-android" -- removed in ndk r17
+ , mips64 = "mips64-linux-android" -- removed in ndk r17
+ }
+ settings_file:print(' "architectures": {"%s":"%s"},', target_arch, triples[target_arch])
+ settings_file:print(' "application-binary": "%s"', target:basename())
+ else
+ settings_file:print(' "application-binary": "%s"', _escape_path(target:targetfile()))
+ end
+ settings_file:print('}')
+ settings_file:close()
+ end
+ if option.get("verbose") and option.get("diagnosis") then
+ io.cat(android_deployment_settings)
+ end
-- do deploy
local argv = {"--input", android_deployment_settings,
@@ -133,6 +172,9 @@ function main(target, opt)
"--android-platform", android_platform,
"--jdk", java_home,
"--gradle", "--no-gdbserver"}
+ if option.get("verbose") and option.get("diagnosis") then
+ table.insert(argv, "--verbose")
+ end
os.vrunv(androiddeployqt, argv)
-- output apk
diff --git a/xmake/rules/qt/load.lua b/xmake/rules/qt/load.lua
index 9944d2652..3323aea6f 100644
--- a/xmake/rules/qt/load.lua
+++ b/xmake/rules/qt/load.lua
@@ -21,9 +21,10 @@
-- imports
import("core.project.config")
import("core.project.target")
+import("lib.detect.find_library")
-- make link for framework
-function _link(framework, major)
+function _link(linkdirs, framework, major)
if major and framework:startswith("Qt") then
local debug_suffix = "_debug"
if is_plat("windows") then
@@ -34,6 +35,12 @@ function _link(framework, major)
debug_suffix = ""
end
framework = "Qt" .. major .. framework:sub(3) .. (is_mode("debug") and debug_suffix or "")
+ if is_plat("android") then --> -lQt5Core_armeabi/-lQt5CoreDebug_armeabi for 5.14.x
+ local libinfo = find_library(framework .. "_" .. config.arch(), linkdirs)
+ if libinfo and libinfo.link then
+ framework = libinfo.link
+ end
+ end
end
return framework
end
@@ -193,11 +200,11 @@ function main(target, opt)
target:add("includedirs", path.join(frameworkdir, "Headers"))
useframeworks = true
else
- target:add("syslinks", _link(framework, major))
+ target:add("syslinks", _link(qt.linkdirs, framework, major))
target:add("includedirs", path.join(qt.sdkdir, "include", framework))
end
else
- target:add("syslinks", _link(framework, major))
+ target:add("syslinks", _link(qt.linkdirs, framework, major))
target:add("includedirs", path.join(qt.sdkdir, "include", framework))
end
end