diff options
| author | ruki <[email protected]> | 2019-09-08 22:11:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-09-08 22:11:59 +0800 |
| commit | 123c6b7c40e797fbe02d81673fbcc88800b1f4b6 (patch) | |
| tree | 203b65f21002483abf3be5cf0407147e94f072a4 | |
| parent | 311693f056cc268de9b811963a5677c7166a0a35 (diff) | |
add qt.quickapp and qt.widgetapp rules
| -rw-r--r-- | tests/projects/qt/quickapp/xmake.lua | 4 | ||||
| -rw-r--r-- | tests/projects/qt/quickapp_static/xmake.lua | 5 | ||||
| -rw-r--r-- | tests/projects/qt/widgetapp/xmake.lua | 4 | ||||
| -rw-r--r-- | tests/projects/qt/widgetapp_static/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/rules/qt/deploy/android.lua | 135 | ||||
| -rw-r--r-- | xmake/rules/qt/install/android.lua | 42 | ||||
| -rw-r--r-- | xmake/rules/qt/xmake.lua | 162 | ||||
| -rw-r--r-- | xmake/templates/c++/quickapp_qt/project/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/templates/c++/quickapp_qt_static/project/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/templates/c++/widgetapp_qt/project/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/templates/c++/widgetapp_qt_static/project/xmake.lua | 5 |
11 files changed, 218 insertions, 157 deletions
diff --git a/tests/projects/qt/quickapp/xmake.lua b/tests/projects/qt/quickapp/xmake.lua index 0eb3fc57a..f71402a14 100644 --- a/tests/projects/qt/quickapp/xmake.lua +++ b/tests/projects/qt/quickapp/xmake.lua @@ -6,7 +6,7 @@ add_rules("mode.debug", "mode.release") target("qt_demo") -- add rules - add_rules("qt.application") + add_rules("qt.quickapp") -- add headers add_headerfiles("src/*.h") @@ -15,6 +15,4 @@ target("qt_demo") add_files("src/*.cpp") add_files("src/qml.qrc") - -- add frameworks - add_frameworks("QtQuick") diff --git a/tests/projects/qt/quickapp_static/xmake.lua b/tests/projects/qt/quickapp_static/xmake.lua index a7e447bfb..d670aa92d 100644 --- a/tests/projects/qt/quickapp_static/xmake.lua +++ b/tests/projects/qt/quickapp_static/xmake.lua @@ -9,7 +9,7 @@ includes("qt_add_static_plugins.lua") target("qt_demo") -- add rules - add_rules("qt.application") + add_rules("qt.quickapp") -- add headers add_headerfiles("src/*.h") @@ -18,9 +18,6 @@ target("qt_demo") add_files("src/*.cpp") add_files("src/qml.qrc") - -- add frameworks - add_frameworks("QtQuick") - -- add plugin: QXXXIntegrationPlugin if is_plat("macosx") then qt_add_static_plugins("QCocoaIntegrationPlugin", {linkdirs = "plugins/platforms", links = {"qcocoa", "Qt5PrintSupport", "Qt5PlatformSupport", "Qt5Widgets", "cups"}}) diff --git a/tests/projects/qt/widgetapp/xmake.lua b/tests/projects/qt/widgetapp/xmake.lua index 2b0217835..1bee2e4b6 100644 --- a/tests/projects/qt/widgetapp/xmake.lua +++ b/tests/projects/qt/widgetapp/xmake.lua @@ -6,7 +6,7 @@ add_rules("mode.debug", "mode.release") target("qt_demo") -- add rules - add_rules("qt.application") + add_rules("qt.widgetapp") -- add headers add_headerfiles("src/*.h") @@ -18,6 +18,4 @@ target("qt_demo") -- add files with Q_OBJECT meta (only for qt.moc) add_files("src/mainwindow.h") - -- add frameworks - add_frameworks("QtWidgets") diff --git a/tests/projects/qt/widgetapp_static/xmake.lua b/tests/projects/qt/widgetapp_static/xmake.lua index 936b10e8e..d435cc8b6 100644 --- a/tests/projects/qt/widgetapp_static/xmake.lua +++ b/tests/projects/qt/widgetapp_static/xmake.lua @@ -9,7 +9,7 @@ includes("qt_add_static_plugins.lua") target("qt_demo") -- add rules - add_rules("qt.application") + add_rules("qt.widgetapp") -- add headers add_headerfiles("src/*.h") @@ -21,9 +21,6 @@ target("qt_demo") -- add files with Q_OBJECT meta (only for qt.moc) add_files("src/mainwindow.h") - -- add frameworks - add_frameworks("QtWidgets") - -- add plugin: QXXXIntegrationPlugin if is_plat("macosx") then qt_add_static_plugins("QCocoaIntegrationPlugin", {linkdirs = "plugins/platforms", links = {"qcocoa", "Qt5PrintSupport", "Qt5PlatformSupport", "cups"}}) diff --git a/xmake/rules/qt/deploy/android.lua b/xmake/rules/qt/deploy/android.lua new file mode 100644 index 000000000..8e5561e72 --- /dev/null +++ b/xmake/rules/qt/deploy/android.lua @@ -0,0 +1,135 @@ +--!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 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file android.lua +-- + +-- imports +import("core.theme.theme") +import("core.base.option") +import("core.project.config") + +-- deploy application package for android +function main(target, opt) + + -- get target apk path + local target_apk = path.join(path.directory(target:targetfile()), target:basename() .. ".apk") + + -- trace progress info + cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", opt.progress.stop) + if option.get("verbose") then + cprint("${dim color.build.target}generating.qt.app %s.apk", target:basename()) + else + cprint("${color.build.target}generating.qt.app %s.apk", target:basename()) + end + + -- get qt sdk + local qt = target:data("qt") + + -- get ndk + local ndk = path.translate(assert(config.get("ndk"), "cannot get NDK!")) + local ndk_sdkver = assert(config.get("ndk_sdkver"), "cannot get the sdk version of NDK!") + + -- get ndk host + local ndk_host = os.host() .. "-" .. os.arch() + if is_host("windows") then + ndk_host = os.arch() == "x64" and "windows-x86_64" or "windows-x86" + elseif is_host("macosx") then + ndk_host = "darwin-x86_64" + elseif is_host("linux") then + ndk_host = "linux-x86_64" + end + + -- get androiddeployqt + local androiddeployqt = path.join(qt.bindir, "androiddeployqt" .. (is_host("windows") and ".exe" or "")) + assert(os.isexec(androiddeployqt), "androiddeployqt not found!") + + -- get working directory + local workdir = path.join(config.buildir(), ".qt", "app", "android", target:name()) + + -- get android-build directory + local android_buildir = path.join(workdir, "android-build") + + -- get android platform + local android_platform = "android-" .. tostring(ndk_sdkver) + + -- get java home + local java_home = assert(os.getenv("JAVA_HOME"), "please set $JAVA_HOME environment variable first!") + + -- get android sdk directory + local android_sdkdir = path.translate(assert(config.get("android_sdk"), "please run `xmake f --android_sdk=xxx` to set the android sdk directory!")) + + -- 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 the target architecture + local target_archs = + { + ["armv5te"] = "armeabi" + , ["armv7-a"] = "armeabi-v7a" + , ["arm64-v8a"] = "arm64-v8a" + , i386 = "x86" + , x86_64 = "x86_64" + , mips = "mips" + , mips64 = "mips64" + } + 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()))) + + -- get stdcpp path + local stdcpp_path = path.join(ndk, "sources/cxx-stl/llvm-libc++/libs", target_arch, "libc++_shared.so") + + -- 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" + }]], qt.sdkdir, android_sdkdir, ndk, android_build_toolver, ndk_toolchains_ver, ndk_host, target_arch, os.projectdir(), stdcpp_path, target:targetfile())) + + -- do deploy + local argv = {"--input", android_deployment_settings, + "--output", android_buildir, + "--android-platform", android_platform, + "--jdk", java_home, + "--gradle", "--no-gdbserver"} + os.vrunv(androiddeployqt, argv) + + -- output apk + os.cp(path.join(android_buildir, "build", "outputs", "apk", "debug", "android-build-debug.apk"), target_apk) + + -- show apk output path + vprint("the apk output path: %s", target_apk) +end + diff --git a/xmake/rules/qt/install/android.lua b/xmake/rules/qt/install/android.lua new file mode 100644 index 000000000..fc0d27c95 --- /dev/null +++ b/xmake/rules/qt/install/android.lua @@ -0,0 +1,42 @@ +--!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 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file android.lua +-- + +-- install application package for android +function main(target, opt) + + -- get target apk path + local target_apk = path.join(path.directory(target:targetfile()), target:basename() .. ".apk") + assert(os.isfile(target_apk), "apk not found, please build %s first!", target:name()) + + -- show install info + print("installing %s ..", target_apk) + + -- get android sdk directory + local android_sdkdir = path.translate(assert(get_config("android_sdk"), "please run `xmake f --android_sdk=xxx` to set the android sdk directory!")) + + -- get adb + local adb = path.join(android_sdkdir, "platform-tools", "adb" .. (is_host("windows") and ".exe" or "")) + if not os.isexec(adb) then + adb = "adb" + end + + -- install apk to device + os.execv(adb, {"install", "-r", target_apk}) +end diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua index 8316fbdb3..48a1597b9 100644 --- a/xmake/rules/qt/xmake.lua +++ b/xmake/rules/qt/xmake.lua @@ -66,8 +66,8 @@ rule("qt.console") import("load")(target, {frameworks = {"QtCore"}}) end) --- define rule: qt application -rule("qt.application") +-- define rule: qt widgetapp +rule("qt.widgetapp") -- add rules add_deps("qt.qrc", "qt.ui", "qt.moc") @@ -81,7 +81,7 @@ rule("qt.application") after_load(function (target) -- load common flags to target - import("load")(target, {frameworks = {"QtGui", "QtQml", "QtNetwork", "QtCore"}}) + import("load")(target, {frameworks = {"QtGui", "QtWidgets", "QtCore"}}) -- add -subsystem:windows for windows platform if is_plat("windows") then @@ -92,140 +92,44 @@ rule("qt.application") end end) - -- after build for android - after_build("android", function (target, opt) - - -- imports - import("core.theme.theme") - import("core.base.option") - import("core.project.config") - - -- get target apk path - local target_apk = path.join(path.directory(target:targetfile()), target:basename() .. ".apk") - - -- trace progress info - cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", opt.progress) - if option.get("verbose") then - cprint("${dim color.build.target}generating.qt.app %s.apk", target:basename()) - else - cprint("${color.build.target}generating.qt.app %s.apk", target:basename()) - end - - -- get qt sdk - local qt = target:data("qt") - - -- get ndk - local ndk = path.translate(assert(config.get("ndk"), "cannot get NDK!")) - local ndk_sdkver = assert(config.get("ndk_sdkver"), "cannot get the sdk version of NDK!") - - -- get ndk host - local ndk_host = os.host() .. "-" .. os.arch() - if is_host("windows") then - ndk_host = os.arch() == "x64" and "windows-x86_64" or "windows-x86" - elseif is_host("macosx") then - ndk_host = "darwin-x86_64" - elseif is_host("linux") then - ndk_host = "linux-x86_64" - end - - -- get androiddeployqt - local androiddeployqt = path.join(qt.bindir, "androiddeployqt" .. (is_host("windows") and ".exe" or "")) - assert(os.isexec(androiddeployqt), "androiddeployqt not found!") - - -- get working directory - local workdir = path.join(config.buildir(), ".qt", "app", "android", target:name()) - - -- get android-build directory - local android_buildir = path.join(workdir, "android-build") - - -- get android platform - local android_platform = "android-" .. tostring(ndk_sdkver) - - -- get java home - local java_home = assert(os.getenv("JAVA_HOME"), "please set $JAVA_HOME environment variable first!") - - -- get android sdk directory - local android_sdkdir = path.translate(assert(config.get("android_sdk"), "please run `xmake f --android_sdk=xxx` to set the android sdk directory!")) - - -- 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 the target architecture - local target_archs = - { - ["armv5te"] = "armeabi" - , ["armv7-a"] = "armeabi-v7a" - , ["arm64-v8a"] = "arm64-v8a" - , i386 = "x86" - , x86_64 = "x86_64" - , mips = "mips" - , mips64 = "mips64" - } - 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()))) - - -- get stdcpp path - local stdcpp_path = path.join(ndk, "sources/cxx-stl/llvm-libc++/libs", target_arch, "libc++_shared.so") - - -- get toolchain version - local ndk_toolchains_ver = config.get("ndk_toolchains_ver") or "4.9" + -- deploy application for android after build + after_build("android", "deploy.android") - -- 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" - }]], qt.sdkdir, android_sdkdir, ndk, android_build_toolver, ndk_toolchains_ver, ndk_host, target_arch, os.projectdir(), stdcpp_path, target:targetfile())) + -- install application for android + on_install("android", "install.android") - -- do deploy - local argv = {"--input", android_deployment_settings, - "--output", android_buildir, - "--android-platform", android_platform, - "--jdk", java_home, - "--gradle", "--no-gdbserver"} - os.vrunv(androiddeployqt, argv) +-- define rule: qt quickapp +rule("qt.quickapp") - -- output apk - os.cp(path.join(android_buildir, "build", "outputs", "apk", "debug", "android-build-debug.apk"), target_apk) + -- add rules + add_deps("qt.qrc", "qt.ui", "qt.moc") - -- show apk output path - vprint("the apk output path: %s", target_apk) + -- we must set kind before target.on_load(), may we will use target in on_load() + before_load(function (target) + target:set("kind", is_plat("android") and "shared" or "binary") end) - -- on install for android - on_install("android", function (target, opt) + -- after load + after_load(function (target) - -- get target apk path - local target_apk = path.join(path.directory(target:targetfile()), target:basename() .. ".apk") - assert(os.isfile(target_apk), "apk not found, please build %s first!", target:name()) + -- load common flags to target + import("load")(target, {frameworks = {"QtGui", "QtQuick", "QtQml", "QtCore"}}) - -- show install info - print("installing %s ..", target_apk) + -- add -subsystem:windows for windows platform + if is_plat("windows") then + target:add("defines", "_WINDOWS") + target:add("ldflags", "-subsystem:windows", "-entry:mainCRTStartup", {force = true}) + elseif is_plat("mingw") then + target:add("ldflags", "-Wl,-subsystem:windows", {force = true}) + end + end) - -- get android sdk directory - local android_sdkdir = path.translate(assert(get_config("android_sdk"), "please run `xmake f --android_sdk=xxx` to set the android sdk directory!")) + -- deploy application for android after build + after_build("android", "deploy.android") - -- get adb - local adb = path.join(android_sdkdir, "platform-tools", "adb" .. (is_host("windows") and ".exe" or "")) - if not os.isexec(adb) then - adb = "adb" - end + -- install application for android + on_install("android", "install.android") - -- install apk to device - os.execv(adb, {"install", "-r", target_apk}) - end) +-- define rule: qt application +rule("qt.application") + add_deps("qt.quickapp") diff --git a/xmake/templates/c++/quickapp_qt/project/xmake.lua b/xmake/templates/c++/quickapp_qt/project/xmake.lua index bcfa506ef..ed756850c 100644 --- a/xmake/templates/c++/quickapp_qt/project/xmake.lua +++ b/xmake/templates/c++/quickapp_qt/project/xmake.lua @@ -6,7 +6,7 @@ add_rules("mode.debug", "mode.release") target("[targetname]") -- add rules - add_rules("qt.application") + add_rules("qt.quickapp") -- add headers add_headerfiles("src/*.h") @@ -15,6 +15,4 @@ target("[targetname]") add_files("src/*.cpp") add_files("src/qml.qrc") - -- add frameworks - add_frameworks("QtQuick") diff --git a/xmake/templates/c++/quickapp_qt_static/project/xmake.lua b/xmake/templates/c++/quickapp_qt_static/project/xmake.lua index 1978bf5bf..847cf6e76 100644 --- a/xmake/templates/c++/quickapp_qt_static/project/xmake.lua +++ b/xmake/templates/c++/quickapp_qt_static/project/xmake.lua @@ -9,7 +9,7 @@ includes("qt_add_static_plugins.lua") target("[targetname]") -- add rules - add_rules("qt.application") + add_rules("qt.quickapp") -- add headers add_headerfiles("src/*.h") @@ -18,9 +18,6 @@ target("[targetname]") add_files("src/*.cpp") add_files("src/qml.qrc") - -- add frameworks - add_frameworks("QtQuick") - -- add plugin: QXXXIntegrationPlugin if is_plat("macosx") then qt_add_static_plugins("QCocoaIntegrationPlugin", {linkdirs = "plugins/platforms", links = {"qcocoa", "Qt5PrintSupport", "Qt5PlatformSupport", "Qt5Widgets", "cups"}}) diff --git a/xmake/templates/c++/widgetapp_qt/project/xmake.lua b/xmake/templates/c++/widgetapp_qt/project/xmake.lua index ca522ec40..8b7bd5ec8 100644 --- a/xmake/templates/c++/widgetapp_qt/project/xmake.lua +++ b/xmake/templates/c++/widgetapp_qt/project/xmake.lua @@ -6,7 +6,7 @@ add_rules("mode.debug", "mode.release") target("[targetname]") -- add rules - add_rules("qt.application") + add_rules("qt.widgetapp") -- add headers add_headerfiles("src/*.h") @@ -18,6 +18,4 @@ target("[targetname]") -- add files with Q_OBJECT meta (only for qt.moc) add_files("src/mainwindow.h") - -- add frameworks - add_frameworks("QtWidgets") diff --git a/xmake/templates/c++/widgetapp_qt_static/project/xmake.lua b/xmake/templates/c++/widgetapp_qt_static/project/xmake.lua index 26ce15e15..b2dd629d5 100644 --- a/xmake/templates/c++/widgetapp_qt_static/project/xmake.lua +++ b/xmake/templates/c++/widgetapp_qt_static/project/xmake.lua @@ -9,7 +9,7 @@ includes("qt_add_static_plugins.lua") target("[targetname]") -- add rules - add_rules("qt.application") + add_rules("qt.widgetapp") -- add headers add_headerfiles("src/*.h") @@ -21,9 +21,6 @@ target("[targetname]") -- add files with Q_OBJECT meta (only for qt.moc) add_files("src/mainwindow.h") - -- add frameworks - add_frameworks("QtWidgets") - -- add plugin: QXXXIntegrationPlugin if is_plat("macosx") then qt_add_static_plugins("QCocoaIntegrationPlugin", {linkdirs = "plugins/platforms", links = {"qcocoa", "Qt5PrintSupport", "Qt5PlatformSupport", "cups"}}) |
