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>
This commit is contained in:
Leander Beernaert 2019-10-22 16:19:13 +02:00
parent d5dc755c65
commit 790d380f8b
4 changed files with 35 additions and 4 deletions

View File

@ -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}")

View File

@ -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()

View File

@ -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()

View File

@ -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
)