summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2019-10-22 16:19:13 +0200
committerLeander Beernaert <leander.beernaert@qt.io>2019-10-23 09:08:10 +0000
commit790d380f8b5b46d135e5c9c25bdfe13b7e5c4b05 (patch)
tree2759ee2d802bf3f0222465b55c85057543395a3e
parentd5dc755c653b56d8c09d8331e3a56e0382cf5ac5 (diff)
Add custom targets to generate Android APK
This patch adds two custom targets to generate android apks. The targets are named ${TARGET}_prepare_apk_dir and ${TARGET}_make_apk. The first one insures the binary is copied to the right location and the latter invokes androiddeployqt on the apk directory. Change-Id: I8152cef387b50ec03ee2bfd92b56910a6f22754c Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--cmake/QtBuild.cmake4
-rw-r--r--cmake/QtPlatformAndroid.cmake28
-rw-r--r--src/corelib/Qt6CoreMacros.cmake1
-rw-r--r--src/plugins/platforms/android/CMakeLists.txt6
4 files changed, 35 insertions, 4 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index 75a35507d7..5df171850f 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -1823,6 +1823,10 @@ function(add_qt_plugin target)
if (ANDROID)
qt_android_apply_arch_suffix("${target}")
+ set_target_properties(${target}
+ PROPERTIES
+ LIBRARY_OUTPUT_NAME "plugins_${arg_TYPE}_${target}"
+ )
endif()
qt_internal_add_target_aliases("${target}")
diff --git a/cmake/QtPlatformAndroid.cmake b/cmake/QtPlatformAndroid.cmake
index 3532217722..0a91e14591 100644
--- a/cmake/QtPlatformAndroid.cmake
+++ b/cmake/QtPlatformAndroid.cmake
@@ -317,9 +317,35 @@ endfunction()
function(qt_android_apply_arch_suffix target)
get_target_property(target_type ${target} TYPE)
- if (target_type STREQUAL "SHARED_LIBRARY")
+ if (target_type STREQUAL "SHARED_LIBRARY" OR target_type STREQUAL "MODULE_LIBRARY")
set_property(TARGET "${target}" PROPERTY SUFFIX "_${CMAKE_ANDROID_ARCH_ABI}.so")
elseif (target_type STREQUAL "STATIC_LIBRARY")
set_property(TARGET "${target}" PROPERTY SUFFIX "_${CMAKE_ANDROID_ARCH_ABI}.a")
endif()
endfunction()
+
+# Add custom target to package the APK
+function(qt_android_add_apk_target target)
+ get_target_property(deployment_file ${target} QT_ANDROID_DEPLOYMENT_SETTINGS_FILE)
+ if (NOT deployment_file)
+ message(FATAL_ERROR "Target ${target} is not a valid android executable target\n")
+ endif()
+
+ set(deployment_tool "${QT_HOST_PATH}/bin/androiddeployqt")
+ set(apk_dir "$<TARGET_PROPERTY:${target},BINARY_DIR>/apk")
+ add_custom_target(${target}_prepare_apk_dir
+ DEPENDS ${target}
+ COMMAND ${CMAKE_COMMAND}
+ -E copy $<TARGET_FILE:${target}>
+ "${apk_dir}/libs/${CMAKE_ANDROID_ARCH_ABI}/$<TARGET_FILE_NAME:${target}>"
+ COMMENT "Copying ${target} binarty to apk folder"
+ )
+
+ add_custom_target(${target}_make_apk
+ DEPENDS ${target}_prepare_apk_dir
+ COMMAND ${deployment_tool}
+ --input ${deployment_file}
+ --output ${apk_dir}
+ COMMENT "Creating APK for ${target}"
+ )
+endfunction()
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake
index d1001ad2af..dbc9cdb163 100644
--- a/src/corelib/Qt6CoreMacros.cmake
+++ b/src/corelib/Qt6CoreMacros.cmake
@@ -423,6 +423,7 @@ function(add_qt_gui_executable target)
if(ANDROID)
qt_android_generate_deployment_settings("${target}")
+ qt_android_add_apk_target("${target}")
endif()
endfunction()
diff --git a/src/plugins/platforms/android/CMakeLists.txt b/src/plugins/platforms/android/CMakeLists.txt
index b6a92fa6ed..bcc3538bcc 100644
--- a/src/plugins/platforms/android/CMakeLists.txt
+++ b/src/plugins/platforms/android/CMakeLists.txt
@@ -61,11 +61,11 @@ add_qt_plugin(qtforandroid
jnigraphics
# special case begin
INSTALL_DIRECTORY
- plugins/platforms/android
+ plugins/platforms
OUTPUT_DIRECTORY
- plugins/platforms/android
+ plugins/platforms
ARCHIVE_INSTALL_DIRECTORY
- plugins/platforms/android
+ plugins/platforms
# special case end
)