summaryrefslogtreecommitdiffstats
path: root/cmake/QtAndroidHelpers.cmake
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@qt.io>2024-09-02 10:21:04 +0300
committerJuha Vuolle <juha.vuolle@qt.io>2024-09-16 11:59:49 +0300
commitc76c888556d21f93fc087b52e96a1b7f06465a2a (patch)
treeaee53c1c1daa73cf87a74939b93d6e0cac6dddf2 /cmake/QtAndroidHelpers.cmake
parent3af20bd8eb8c75017c5d6d138d7c42914ee5bee3 (diff)
Introduce qt_add_android_permission CMake function
qt_add_android_permission function can be used to set Android permissions on target executable. This allows setting new permissions, or overriding permissions set by Qt modules, without needing to supply a manual application AndroidManifest.xml. The change consists of: - New public CMake function for setting the permissions on the target + documentation - Writing these application permissions into the deployment settings json file - Reading and handling these permissions at androiddeployqt side - Moving some pre-existing permission functionality from QtAndroidHelpers.cmake to Qt6AndroidMacros.cmake so that they can be reused also in the context of application CMakeLists.txt processing - Documentation update for Android permission handling In future this same mechanism can be extended for Android features. [ChangeLog][CMake] Added qt_add_android_permission function for setting Android permissions from application CMake Fixes: QTBUG-128280 Change-Id: Ia22951fb435598be00b5da5eae11b9f35f704795 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Diffstat (limited to 'cmake/QtAndroidHelpers.cmake')
-rw-r--r--cmake/QtAndroidHelpers.cmake39
1 files changed, 3 insertions, 36 deletions
diff --git a/cmake/QtAndroidHelpers.cmake b/cmake/QtAndroidHelpers.cmake
index 9e81e862058..81b5817967c 100644
--- a/cmake/QtAndroidHelpers.cmake
+++ b/cmake/QtAndroidHelpers.cmake
@@ -89,40 +89,7 @@ macro(qt_internal_setup_android_target_properties)
endmacro()
function(qt_internal_add_android_permission target)
- cmake_parse_arguments(arg "" "NAME" "ATTRIBUTES" ${ARGN})
-
- if(NOT target)
- message(FATAL_ERROR "Target for adding Android permission cannot be empty (${arg_NAME})")
- endif()
-
- if(NOT arg_NAME)
- message(FATAL_ERROR "NAME for adding Android permission cannot be empty (${target})")
- endif()
-
- set(permission_entry "${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 attributes must be name-value pairs (${arg_NAME})")
- endif()
- # Combine name-value pairs
- set(index 0)
- set(attributes "")
- while(index LESS attributes_len)
- list(GET arg_ATTRIBUTES ${index} name)
- math(EXPR index "${index} + 1")
- list(GET arg_ATTRIBUTES ${index} value)
- string(APPEND attributes " android:${name}=\"${value}\"")
- math(EXPR index "${index} + 1")
- endwhile()
- set(permission_entry "${permission_entry}\;${attributes}")
- endif()
-
- # Append the permission to the target's property
- set_property(TARGET ${target} APPEND PROPERTY QT_ANDROID_PERMISSIONS "${permission_entry}")
+ _qt_internal_add_android_permission(${ARGV})
endfunction()
@@ -233,9 +200,9 @@ function(qt_internal_android_dependencies_content target file_content_out)
elseif(permission_len EQUAL 2)
list(GET permission 0 name)
list(GET permission 1 extras)
- string(APPEND file_contents "<permission name=\"${name}\" extras=\'${extras}\'/>\n")
+ string(APPEND file_contents "<permission name=\"${name}\" extras=\"${extras}\"/>\n")
else()
- message(FATAL_ERROR "Unexpected permission: " "${permission}" "${permission_len}")
+ message(FATAL_ERROR "Invalid permission format: ${permission} ${permission_len}")
endif()
endforeach()
endif()