# Copyright (C) 2025 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause # Generates the generator expression that converts the 'target' # QT_ANDROID_PERMISSIONS property to the specific 'type'. # # It's expected that each element in QT_ANDROID_PERMISSIONS list has specific # format: # \;\\\;\;\\\;\; # # Synopsis # _qt_internal_android_convert_permissions(out_var target ) # # Arguments # # `out_var` # The name of the variable where the resulting generator expression is # stored. # # `target` # The name of the target. # # `JSON` # Generate JSON array known by androiddeployqt. # # `XML` # Generate XML content compatible with AndroidManifest.xml. function(_qt_internal_android_convert_permissions out_var target type) set(permissions_property "$") set(permissions_genex "$<$:") if(type STREQUAL "JSON") set(pref "{ \"") set(post "\" }") set(indent "\n ") string(APPEND permissions_genex "[${indent}$${indent}${pref}" ">${post}," "\": \"" ">," "\"$ \"" ">\n ]" ) elseif(type STREQUAL "XML") set(pref "\n") string(APPEND permissions_genex "$${post}\n," "='" ">," "' android:" ">" ) else() message(FATAL_ERROR "Invalid type ${type}. Supported types: JSON, XML") endif() string(APPEND permissions_genex ">") set(${out_var} "${permissions_genex}" PARENT_SCOPE) endfunction() # Add the specific Android permission to the target. The permission is stored # in the QT_ANDROID_PERMISSIONS property(the property is not a public API) # and has the following format: # \;\\\;\;\\\;\; # # Synopsis # _qt_internal_add_android_permission(target NAME # ATTRIBUTES # [ ]... # ) # # Arguments # # `target` # The Android target. # # `NAME` # The permission name. E.g. 'android.permission.CAMERA'. # # `ATTRIBUTES` # Extra permission attribute key-value pairs. # See https://developer.android.com/guide/topics/manifest/uses-permission-element # for details. function(_qt_internal_add_android_permission target) if(NOT TARGET ${target}) message(FATAL_ERROR "Empty or invalid target for adding Android permission: (${target})") endif() cmake_parse_arguments(arg "" "NAME" "ATTRIBUTES" ${ARGN}) if(NOT arg_NAME) message(FATAL_ERROR "NAME for adding Android permission cannot be empty (${target})") endif() set(permission_entry "name\;${arg_NAME}") if(arg_ATTRIBUTES) # Permission with additional attributes list(LENGTH arg_ATTRIBUTES attributes_len) math(EXPR attributes_modulus "${attributes_len} % 2") if(NOT (attributes_len GREATER 1 AND attributes_modulus EQUAL 0)) message(FATAL_ERROR "Android permission: ${arg_NAME} attributes: ${arg_ATTRIBUTES}" " must be name-value pairs (for example: minSdkVersion 30)") endif() # Combine name-value pairs set(index 0) while(index LESS attributes_len) list(GET arg_ATTRIBUTES ${index} name) math(EXPR index "${index} + 1") list(GET arg_ATTRIBUTES ${index} value) string(APPEND permission_entry "\\\;${name}\;${value}") math(EXPR index "${index} + 1") endwhile() endif() # Append the permission to the target's property set_property(TARGET ${target} APPEND PROPERTY QT_ANDROID_PERMISSIONS "${permission_entry}") endfunction()