Warning, /frameworks/extra-cmake-modules/toolchain/ECMAndroidDeployQt.cmake is written in an unsupported language. File is not indexed.

0001 cmake_minimum_required (VERSION 3.19 FATAL_ERROR)
0002 find_package(Qt5Core REQUIRED)
0003 find_package(Python3 COMPONENTS Interpreter REQUIRED)
0004 
0005 # Taken from https://stackoverflow.com/a/62311397
0006 function(_ecm_get_all_targets var)
0007     set(targets)
0008     _ecm_get_all_targets_recursive(targets ${CMAKE_CURRENT_SOURCE_DIR})
0009     set(${var} ${targets} PARENT_SCOPE)
0010 endfunction()
0011 
0012 macro(_ecm_get_all_targets_recursive targets dir)
0013     get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
0014     foreach(subdir ${subdirectories})
0015         _ecm_get_all_targets_recursive(${targets} ${subdir})
0016     endforeach()
0017 
0018     get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
0019     list(APPEND ${targets} ${current_targets})
0020 endmacro()
0021 
0022 function(_ecm_deferred_androiddeployqt)
0023     _ecm_get_all_targets(all_targets)
0024     set(module_targets)
0025     foreach(tgt ${all_targets})
0026         get_target_property(tgt_type ${tgt} TYPE)
0027         if(tgt_type STREQUAL "MODULE_LIBRARY")
0028             list(APPEND module_targets "$<TARGET_FILE:${tgt}>")
0029         endif()
0030     endforeach()
0031     file(GENERATE OUTPUT "module-plugins" CONTENT "${module_targets}")
0032 endfunction()
0033 cmake_language(DEFER DIRECTORY "${CMAKE_SOURCE_DIR}" CALL _ecm_deferred_androiddeployqt)
0034 
0035 function(ecm_androiddeployqt QTANDROID_EXPORTED_TARGET ECM_ADDITIONAL_FIND_ROOT_PATH)
0036     set(EXPORT_DIR "${CMAKE_BINARY_DIR}/${QTANDROID_EXPORTED_TARGET}_build_apk/")
0037     if (Qt5Core_VERSION VERSION_LESS 5.14.0)
0038         set(EXECUTABLE_DESTINATION_PATH "${EXPORT_DIR}/libs/${CMAKE_ANDROID_ARCH_ABI}/lib${QTANDROID_EXPORTED_TARGET}.so")
0039     else()
0040         set(EXECUTABLE_DESTINATION_PATH "${EXPORT_DIR}/libs/${CMAKE_ANDROID_ARCH_ABI}/lib${QTANDROID_EXPORTED_TARGET}_${CMAKE_ANDROID_ARCH_ABI}.so")
0041     endif()
0042     set(QML_IMPORT_PATHS "")
0043     # add build directory to the search path as well, so this works without installation
0044     if (EXISTS ${CMAKE_BINARY_DIR}/lib)
0045         set(QML_IMPORT_PATHS ${CMAKE_BINARY_DIR}/lib)
0046     endif()
0047     foreach(prefix ${ECM_ADDITIONAL_FIND_ROOT_PATH})
0048         # qmlimportscanner chokes on symlinks, so we need to resolve those first
0049         get_filename_component(qml_path "${prefix}/lib/qml" REALPATH)
0050         if(EXISTS ${qml_path})
0051             if (QML_IMPORT_PATHS)
0052                 set(QML_IMPORT_PATHS "${QML_IMPORT_PATHS},${qml_path}")
0053             else()
0054                 set(QML_IMPORT_PATHS "${qml_path}")
0055             endif()
0056         endif()
0057     endforeach()
0058     if (QML_IMPORT_PATHS)
0059         set(DEFINE_QML_IMPORT_PATHS "\"qml-import-paths\": \"${QML_IMPORT_PATHS}\",")
0060     endif()
0061 
0062     set(EXTRA_PREFIX_DIRS "\"${CMAKE_BINARY_DIR}\"")
0063     foreach(prefix ${ECM_ADDITIONAL_FIND_ROOT_PATH})
0064         set(EXTRA_PREFIX_DIRS "${EXTRA_PREFIX_DIRS}, \"${prefix}\"")
0065     endforeach()
0066 
0067     if (Qt5Core_VERSION VERSION_LESS 5.14.0)
0068         set(_deployment_file_template "${_CMAKE_ANDROID_DIR}/deployment-file.json.in")
0069     else()
0070         set(_deployment_file_template "${_CMAKE_ANDROID_DIR}/deployment-file-qt514.json.in")
0071     endif()
0072     string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" _LOWER_CMAKE_HOST_SYSTEM_NAME)
0073     configure_file("${_deployment_file_template}" "${CMAKE_BINARY_DIR}/${QTANDROID_EXPORTED_TARGET}-deployment.json.in1")
0074     file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/${QTANDROID_EXPORTED_TARGET}-deployment.json.in2"
0075                   INPUT  "${CMAKE_BINARY_DIR}/${QTANDROID_EXPORTED_TARGET}-deployment.json.in1")
0076 
0077     if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
0078         set(arguments "\\$(ARGS)")
0079     endif()
0080 
0081     function(havestl var access VALUE)
0082         if (NOT VALUE STREQUAL "")
0083             # look for ++ and .so as in libc++.so
0084             string (REGEX MATCH "\"[^ ]+\\+\\+[^ ]*\.so\"" OUT ${VALUE})
0085             file(WRITE ${CMAKE_BINARY_DIR}/stl "${OUT}")
0086         endif()
0087     endfunction()
0088     function(haveranlib var access VALUE)
0089         if (NOT VALUE STREQUAL "")
0090             file(WRITE ${CMAKE_BINARY_DIR}/ranlib "${VALUE}")
0091         endif()
0092     endfunction()
0093     variable_watch(CMAKE_CXX_STANDARD_LIBRARIES havestl)
0094     variable_watch(CMAKE_RANLIB haveranlib)
0095 
0096     if (NOT TARGET create-apk)
0097         add_custom_target(create-apk)
0098         if (NOT DEFINED ANDROID_FASTLANE_METADATA_OUTPUT_DIR)
0099             set(ANDROID_FASTLANE_METADATA_OUTPUT_DIR ${CMAKE_BINARY_DIR}/fastlane)
0100         endif()
0101         add_custom_target(create-fastlane
0102             COMMAND Python3::Interpreter ${CMAKE_CURRENT_LIST_DIR}/generate-fastlane-metadata.py --output ${ANDROID_FASTLANE_METADATA_OUTPUT_DIR} --source ${CMAKE_SOURCE_DIR}
0103         )
0104     endif()
0105 
0106     if (NOT DEFINED ANDROID_APK_OUTPUT_DIR)
0107         set(ANDROID_APK_OUTPUT_DIR ${EXPORT_DIR})
0108     endif()
0109 
0110     set(CREATEAPK_TARGET_NAME "create-apk-${QTANDROID_EXPORTED_TARGET}")
0111     add_custom_target(${CREATEAPK_TARGET_NAME}
0112         COMMAND ${CMAKE_COMMAND} -E echo "Generating $<TARGET_NAME:${QTANDROID_EXPORTED_TARGET}> with $<TARGET_FILE_DIR:Qt5::qmake>/androiddeployqt"
0113         COMMAND ${CMAKE_COMMAND} -E remove_directory "${EXPORT_DIR}"
0114         COMMAND ${CMAKE_COMMAND} -E copy_directory "$<TARGET_PROPERTY:create-apk-${QTANDROID_EXPORTED_TARGET},ANDROID_APK_DIR>" "${EXPORT_DIR}"
0115         COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:${QTANDROID_EXPORTED_TARGET}>" "${EXECUTABLE_DESTINATION_PATH}"
0116         COMMAND LANG=C ${CMAKE_COMMAND} "-DTARGET=$<TARGET_FILE:${QTANDROID_EXPORTED_TARGET}>" -P ${_CMAKE_ANDROID_DIR}/hasMainSymbol.cmake
0117         COMMAND LANG=C ${CMAKE_COMMAND} -DINPUT_FILE="${QTANDROID_EXPORTED_TARGET}-deployment.json.in2" -DOUTPUT_FILE="${QTANDROID_EXPORTED_TARGET}-deployment.json" "-DTARGET=$<TARGET_FILE:${QTANDROID_EXPORTED_TARGET}>" "-DOUTPUT_DIR=$<TARGET_FILE_DIR:${QTANDROID_EXPORTED_TARGET}>" "-DEXPORT_DIR=${CMAKE_INSTALL_PREFIX}" "-DECM_ADDITIONAL_FIND_ROOT_PATH=\"${ECM_ADDITIONAL_FIND_ROOT_PATH}\"" "-DANDROID_EXTRA_LIBS=\"${ANDROID_EXTRA_LIBS}\"" "-DUSE_LLVM=\"${USE_LLVM}\"" -P ${_CMAKE_ANDROID_DIR}/specifydependencies.cmake
0118         COMMAND $<TARGET_FILE_DIR:Qt5::qmake>/androiddeployqt ${ANDROIDDEPLOYQT_EXTRA_ARGS} --gradle --input "${QTANDROID_EXPORTED_TARGET}-deployment.json" --apk "${ANDROID_APK_OUTPUT_DIR}/${QTANDROID_EXPORTED_TARGET}-${CMAKE_ANDROID_ARCH_ABI}.apk" --output "${EXPORT_DIR}" --android-platform android-${ANDROID_SDK_COMPILE_API} --deployment bundled ${arguments}
0119     )
0120     # --android-platform above is only available as a command line option
0121     # This specifies the actual version of the SDK files to use, and
0122     # can be different from both the NDK target and the Java API target.
0123 
0124     add_custom_target(install-apk-${QTANDROID_EXPORTED_TARGET}
0125         COMMAND adb install -r "${ANDROID_APK_OUTPUT_DIR}/${QTANDROID_EXPORTED_TARGET}-${CMAKE_ANDROID_ARCH_ABI}.apk"
0126     )
0127     add_dependencies(create-apk ${CREATEAPK_TARGET_NAME})
0128     add_dependencies(${CREATEAPK_TARGET_NAME} create-fastlane)
0129 endfunction()