diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 3a1dbb5bb4..6699e9844c 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -1225,6 +1225,10 @@ function(add_qt_module target) else() add_library("${target}" STATIC) endif() + + if (android) + qt_android_apply_arch_suffix("${target}") + endif() qt_internal_add_target_aliases("${target}") # Add _private target to link against the private headers: @@ -1683,6 +1687,10 @@ function(add_qt_plugin target) set_property(TARGET "${target}" PROPERTY SUFFIX ".dylib") endif() endif() + + if (ANDROID) + qt_android_apply_arch_suffix("${target}") + endif() qt_internal_add_target_aliases("${target}") set_target_properties("${target}" PROPERTIES diff --git a/cmake/QtBuildInternals/QtBuildInternalsAndroid.cmake b/cmake/QtBuildInternals/QtBuildInternalsAndroid.cmake index ecba1dd08f..7f8b6df232 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsAndroid.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsAndroid.cmake @@ -112,10 +112,10 @@ function(qt_android_dependencies target) endmacro() get_target_property(target_bin_dir ${target} BINARY_DIR) - set(dependency_file "${target_bin_dir}/${target_name}-android-dependencies.xml") + set(dependency_file "${target_bin_dir}/${target_name}_${CMAKE_ANDROID_ARCH_ABI}-android-dependencies.xml") - file(WRITE ${dependency_file} "\n") - file(APPEND ${dependency_file} "\n") + set(file_contents "\n") + string(APPEND file_contents "\n") # Jar Dependencies if(arg_JAR_DEPENDENCIES) @@ -125,7 +125,7 @@ function(qt_android_dependencies target) set(init_class "initClass=\"${init_class}\"") endif() file(TO_NATIVE_PATH ${jar_file} jar_file_native) - file(APPEND ${dependency_file} "\n") + string(APPEND file_contents "\n") endforeach() endif() @@ -137,32 +137,34 @@ function(qt_android_dependencies target) set(init_class "initClass=\"${init_class}\"") endif() file(TO_NATIVE_PATH ${jar_bundle} jar_bundle_native) - file(APPEND ${dependency_file} "\n") + string(APPEND file_contents "\n") endforeach() endif() # Lib Dependencies if(arg_LIB_DEPENDENCIES) foreach(lib IN LISTS arg_LIB_DEPENDENCIES) + string(REPLACE ".so" "_${CMAKE_ANDROID_ARCH_ABI}.so" lib ${lib}) section(${lib} ":" lib_file lib_extends) if (lib_extends) set(lib_extends "extends=\"${lib_extends}\"") endif() file(TO_NATIVE_PATH ${lib_file} lib_file_native) - file(APPEND ${dependency_file} "\n") + string(APPEND file_contents "\n") endforeach() endif() # Lib Dependencies Replacements if(arg_LIB_DEPENDENCY_REPLACEMENTS) foreach(lib IN LISTS arg_LIB_DEPENDENCY_REPLACEMENTS) + string(REPLACE ".so" "_${CMAKE_ANDROID_ARCH_ABI}.so" lib ${lib}) section(${lib} ":" lib_file lib_replacement) if (lib_replacement) file(TO_NATIVE_PATH ${lib_replacement} lib_replacement_native) set(lib_replacement "replaces=\"${lib_replacement_native}\"") endif() file(TO_NATIVE_PATH ${lib_file} lib_file_native) - file(APPEND ${dependency_file} "\n") + string(APPEND file_contents "\n") endforeach() endif() @@ -171,26 +173,27 @@ function(qt_android_dependencies target) if(arg_BUNDLED_FILES) foreach(file IN LISTS arg_BUNDLED_FILES) file(TO_NATIVE_PATH ${lib_file} file_native) - file(APPEND ${dependency_file} "\n") + string(APPEND file_contents "\n") endforeach() endif() # Module plugins if(module_plugins) foreach(plugin IN LISTS module_plugins) - file(APPEND ${dependency_file} "\n") + string(APPEND file_contents "\n") endforeach() endif() # Android Permissions if(arg_PERMISSIONS) foreach(permission IN LISTS arg_PERMISSIONS) - file(APPEND ${dependency_file} "\n") + string(APPEND file_contents "\n") endforeach() endif() - file(APPEND ${dependency_file} "") - file(APPEND ${dependency_file} "\n") + string(APPEND file_contents "") + string(APPEND file_contents "\n") + file(WRITE ${dependency_file} ${file_contents}) get_target_property(target_install_dir ${target} QT_ANDROID_MODULE_INSTALL_DIR) if (NOT target_install_dir) @@ -206,3 +209,5 @@ function(qt_android_dependencies target) COMPONENT Devel) endfunction() + + 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() diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 79adaaf2d4..060c69e8de 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -408,6 +408,7 @@ function(add_qt_gui_executable target) # through dlopen() set_property(TARGET "${target}" PROPERTY C_VISIBILITY_PRESET default) set_property(TARGET "${target}" PROPERTY CXX_VISIBILITY_PRESET default) + qt_android_apply_arch_suffix("${target}") else() add_executable("${target}" WIN32 MACOSX_BUNDLE ${ARGN}) endif()