diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2019-08-30 11:34:23 +0200 |
---|---|---|
committer | Leander Beernaert <leander.beernaert@qt.io> | 2019-08-30 12:10:26 +0000 |
commit | eeffac526ead99175125421f4f83356113460eaa (patch) | |
tree | fcce9e4c3221cb103e35a826e8039952e69f101a /cmake/QtPlatformAndroid.cmake | |
parent | 6c15ad79788b6ccbba0fde73fb09cfcd15cce608 (diff) |
Update Android build configuration
Update Android build configuration to be compatible with the multi-arch
android build patch to qmake. We can now build and generate the apk
correctly. Executing on the device/simulator will only work once the
latest changes from 5.14 have been merged in.
We now replace target suffix with ${CMAKE_ANDROID_ARCH_ABI}.[so|a] so
we don't have to deal with handling targets which might have any of the
OUTPUT_NAME properties set.
The dependency and deploy settings generation has also been updated to
append the file contents to a string and then do a single file write
at the end.
Change-Id: Id3c5bd0428141ecaf962124a100390e3a4e41feb
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake/QtPlatformAndroid.cmake')
-rw-r--r-- | cmake/QtPlatformAndroid.cmake | 82 |
1 files changed, 50 insertions, 32 deletions
diff --git a/cmake/QtPlatformAndroid.cmake b/cmake/QtPlatformAndroid.cmake index 6c27088765..c9deae49e3 100644 --- a/cmake/QtPlatformAndroid.cmake +++ b/cmake/QtPlatformAndroid.cmake @@ -12,8 +12,6 @@ # Android API version # QT_ANDROID_SDK_BUILD_TOOLS_VERSION # Detected Android sdk build tools version -# QT_ANDROID_NDK_STDLIB_PATH -# Detected path to the c++ stl lib shared library # # Public functions: # @@ -82,10 +80,6 @@ if(NOT ANDROID_STL STREQUAL c++_shared) message(FATAL_ERROR "The Qt libraries on Android only supports the shared library configuration of stl. Please use -DANDROID_STL=\"c++_shared\" as configuration argument.") endif() - -# Location of stdlibc++ -set(QT_ANDROID_NDK_STDLIB_PATH "${ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${ANDROID_ABI}/libc++_shared.so") - # Target properties required for android deploy tool define_property(TARGET PROPERTY @@ -155,14 +149,14 @@ function(qt_android_generate_deployment_settings target) endif() set(deploy_file "${target_binary_dir}/android-lib${target_output_name}.so-deployment-settings.json") - file(WRITE ${deploy_file} "{\n") + set(file_contents "{\n") # content begin - file(APPEND ${deploy_file} + string(APPEND file_contents " \"description\": \"This file is generated by cmake to be read by androiddeployqt and should not be modified by hand.\",\n") # Host Qt Android install path if (NOT QT_BUILDING_QT) - set(file_check "${Qt6_DIR}/plugins/platforms/android/libqtforandroid.so") + set(file_check "${Qt6_DIR}/plugins/platforms/android/libqtforandroid_${CMAKE_ANDROID_ARCH_ABI}.so") if (NOT EXISTS ${file_check}) message(SEND_ERROR "Detected Qt installation does not contain libqtforandroid.so. This is most likely due to the installation not being a build of Qt for Android. Please update your settings.") return() @@ -174,49 +168,59 @@ function(qt_android_generate_deployment_settings target) endif() file(TO_NATIVE_PATH "${qt_android_install_dir}" qt_android_install_dir_native) - file(APPEND ${deploy_file} + string(APPEND file_contents " \"qt\": \"${qt_android_install_dir_native}\",\n") # Android SDK path file(TO_NATIVE_PATH "${ANDROID_SDK_ROOT}" android_sdk_root_native) - file(APPEND ${deploy_file} + string(APPEND file_contents " \"sdk\": \"${android_sdk_root_native}\",\n") # Android SDK Build Tools Revision - file(APPEND ${deploy_file} + string(APPEND file_contents " \"sdkBuildToolsRevision\": \"${QT_ANDROID_SDK_BUILD_TOOLS_VERSION}\",\n") # Android NDK file(TO_NATIVE_PATH "${ANDROID_NDK}" android_ndk_root_native) - file(APPEND ${deploy_file} + string(APPEND file_contents " \"ndk\": \"${android_ndk_root_native}\",\n") # Setup LLVM toolchain - file(APPEND ${deploy_file} + string(APPEND file_contents " \"toolchain-prefix\": \"llvm\",\n") - file(APPEND ${deploy_file} + string(APPEND file_contents " \"tool-prefix\": \"llvm\",\n") - file(APPEND ${deploy_file} + string(APPEND file_contents " \"useLLVM\": true,\n") # NDK Toolchain Version - file(APPEND ${deploy_file} + string(APPEND file_contents " \"toolchain-version\": \"${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}\",\n") # NDK Host - file(APPEND ${deploy_file} + string(APPEND file_contents " \"ndk-host\": \"${ANDROID_NDK_HOST_SYSTEM_NAME}\",\n") + if (CMAKE_ANDROID_ARCH_ABI STREQUAL "x86") + set(arch_value "i686-linux-android") + elseif (CMAKE_ANDROID_ARCH_ABI STREQUAL "x86_64") + set(arch_value "x86_64-linux-android") + elseif (CMAKE_ANDROID_ARCH_ABI STREQUAL "armv64-v8a") + set(arch_value "aarch64-linux-android") + else() + set(arch_value "arm-linux-androideabi") + endif() + # Architecture - file(APPEND ${deploy_file} - " \"target-architecture\": \"${CMAKE_ANDROID_ARCH_ABI}\",\n") + string(APPEND file_contents + " \"architectures\": { \"${CMAKE_ANDROID_ARCH_ABI}\" : \"${arch_value}\" },\n") # deployment dependencies get_target_property(android_deployment_dependencies ${target} QT_ANDROID_DEPLOYMENT_DEPENDENCIES) if (android_deployment_dependencies) list(JOIN android_deployment_dependencies "," android_deployment_dependencies) - file(APPEND ${deploy_file} + string(APPEND file_contents " \"deployment-dependencies\": \"${android_deployment_dependencies}\",\n") endif() @@ -225,7 +229,7 @@ function(qt_android_generate_deployment_settings target) ${target} QT_ANDROID_EXTRA_PLUGINS) if (android_extra_plugins) list(JOIN android_extra_plugins "," android_extra_plugins) - file(APPEND ${deploy_file} + string(APPEND file_contents " \"android-extra-plugins\": \"${android_extra_plugins}\",\n") endif() @@ -234,7 +238,7 @@ function(qt_android_generate_deployment_settings target) ${target} QT_ANDROID_EXTRA_LIBS) if (android_extra_libs) list(JOIN android_extra_libs "," android_extra_libs) - file(APPEND ${deploy_file} + string(APPEND file_contents " \"android-extra-libs\": \"${android_extra_libs}\",\n") endif() @@ -243,7 +247,7 @@ function(qt_android_generate_deployment_settings target) ${target} QT_ANDROID_PACKAGE_SOURCE_DIR) if (android_package_source_dir) file(TO_NATIVE_PATH "${android_package_source_dir}" android_package_source_dir_native) - file(APPEND ${deploy_file} + string(APPEND file_contents " \"android-package-source-directory\": \"${android_package_source_dir_native}\",\n") endif() @@ -254,7 +258,7 @@ endif() get_target_property(qml_import_path ${target} QT_QML_IMPORT_PATH) if (qml_import_path) file(TO_NATIVE_PATH "${qml_import_path}" qml_import_path_native) - file(APPEND ${deploy_file} + string(APPEND file_contents " \"qml-import-path\": \"${qml_import_path_native}\",\n") endif() @@ -263,24 +267,38 @@ endif() set(qml_root_path "${target_source_dir}") endif() file(TO_NATIVE_PATH "${qml_root_path}" qml_root_path_native) - file(APPEND ${deploy_file} + string(APPEND file_contents " \"qml-root-path\": \"${qml_root_path_native}\",\n") # App binary - file(TO_NATIVE_PATH "${target_binary_dir}/lib${target_output_name}.so" target_binary_dir_native) - file(APPEND ${deploy_file} - " \"application-binary\": \"${target_binary_dir_native}\",\n") + string(APPEND file_contents + " \"application-binary\": \"${target_output_name}\",\n") # Lats item in json file - file(APPEND ${deploy_file} - " \"stdcpp-path\": \"${QT_ANDROID_NDK_STDLIB_PATH}\"\n") + # base location of stdlibc++, will be suffixed by androiddeploy qt + set(android_ndk_stdlib_base_path + "${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/" + ) + string(APPEND file_contents + " \"stdcpp-path\": \"${android_ndk_stdlib_base_path}\"\n") # content end - file(APPEND ${deploy_file} "}\n") + string(APPEND file_contents "}\n") + + file(WRITE ${deploy_file} ${file_contents}) set_target_properties(${target} PROPERTIES QT_ANDROID_DEPLOYMENT_SETTINGS_FILE ${deploy_file} ) endfunction() + +function(qt_android_apply_arch_suffix target) + get_target_property(target_type ${target} TYPE) + if (target_type STREQUAL "SHARED_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() |