qt5base-lts/tests/manual/permissions/CMakeLists.txt

62 lines
2.2 KiB
CMake
Raw Normal View History

# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
qt_internal_add_test(tst_manual_qpermissions
SOURCES
tst_qpermissions.cpp
LIBRARIES
Qt::CorePrivate
)
Add permission API backend for macOS and iOS When submitting applications to the iOS and macOS AppStore the application goes through static analysis, which will trigger on uses of various privacy protected APIs, unless the application has a corresponding usage description for the permission in the Info.plist file. This applies even if the application never requests the given permission, but just links to a Qt library that has the offending symbols or library dependencies. To ensure that the application does not have to add usage descriptions to their Info.plist for permissions they never plan to use we split up the various permission implementations into small static libraries that register with the Qt plugin mechanism as permission backends. We can then inspect the application's Info.plist at configure time and only add the relevant static permission libraries. Furthermore, since some permissions can be checked without any usage description, we allow the implementation to be split up into two separate translation units. By putting the request in its own translation unit we can selectively include it during linking by telling the linker to look for a special symbol. This is useful for libraries such as Qt Multimedia who would like to check the current permission status, but without needing to request any permission of its own. Done-with: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Change-Id: Ic2a43e1a0c45a91df6101020639f473ffd9454cc Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-05-10 13:02:43 +00:00
if(ANDROID)
set_property(TARGET tst_manual_qpermissions
PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
elseif(APPLE)
Add permission API backend for macOS and iOS When submitting applications to the iOS and macOS AppStore the application goes through static analysis, which will trigger on uses of various privacy protected APIs, unless the application has a corresponding usage description for the permission in the Info.plist file. This applies even if the application never requests the given permission, but just links to a Qt library that has the offending symbols or library dependencies. To ensure that the application does not have to add usage descriptions to their Info.plist for permissions they never plan to use we split up the various permission implementations into small static libraries that register with the Qt plugin mechanism as permission backends. We can then inspect the application's Info.plist at configure time and only add the relevant static permission libraries. Furthermore, since some permissions can be checked without any usage description, we allow the implementation to be split up into two separate translation units. By putting the request in its own translation unit we can selectively include it during linking by telling the linker to look for a special symbol. This is useful for libraries such as Qt Multimedia who would like to check the current permission status, but without needing to request any permission of its own. Done-with: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Change-Id: Ic2a43e1a0c45a91df6101020639f473ffd9454cc Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-05-10 13:02:43 +00:00
# Test an app bundle, but without any usage descriptions
qt_internal_add_test(tst_qpermissions_app
SOURCES
tst_qpermissions.cpp
DEFINES
tst_QPermissions=tst_QPermissionsApp
LIBRARIES
Qt::CorePrivate
)
set_property(TARGET tst_qpermissions_app
PROPERTY MACOSX_BUNDLE TRUE)
set_property(TARGET tst_qpermissions_app
PROPERTY MACOSX_BUNDLE_GUI_IDENTIFIER "io.qt.dev.tst_permissions_app")
# Test an app bundle with all the required usage descriptions
qt_internal_add_test(tst_qpermissions_app_with_usage_descriptions
SOURCES
tst_qpermissions.cpp
DEFINES
tst_QPermissions=tst_QPermissionsAppWithUsageDescriptions
HAVE_USAGE_DESCRIPTION=1
LIBRARIES
Qt::CorePrivate
Qt::Gui
)
set_property(TARGET tst_qpermissions_app_with_usage_descriptions
PROPERTY MACOSX_BUNDLE TRUE)
set_property(TARGET tst_qpermissions_app_with_usage_descriptions
PROPERTY MACOSX_BUNDLE_GUI_IDENTIFIER "io.qt.dev.tst_qpermissions_app_with_usage_descriptions")
set_property(TARGET tst_qpermissions_app_with_usage_descriptions
PROPERTY MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist")
foreach(permission_plugin IN LISTS QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_permissions)
set(permission_plugin "${QT_CMAKE_EXPORT_NAMESPACE}::${permission_plugin}")
qt6_import_plugins(tst_qpermissions_app INCLUDE ${permission_plugin})
qt6_import_plugins(tst_qpermissions_app_with_usage_descriptions INCLUDE ${permission_plugin})
endforeach()
if(NOT CMAKE_GENERATOR STREQUAL "Xcode")
add_custom_command(TARGET tst_qpermissions_app_with_usage_descriptions
POST_BUILD COMMAND codesign -s - tst_qpermissions_app_with_usage_descriptions.app)
endif()
endif()