From f493041ad039867bb24a4259657acf3f3d522dfe Mon Sep 17 00:00:00 2001 From: Gabriel Souza Franco Date: Wed, 25 Nov 2020 12:09:06 -0300 Subject: Automatically detect plugin lib deps on Android This makes use of the CMake 3.19 DEFER command to list all MODULE targets after processing the toplevel CMakeLists. This allows us to collect required dependencies of all plugins without changes to the application. For example, this will fix Okular not including Poppler because it is only linked from the plugin, thus not being able to actually read PDFs. --- toolchain/ECMAndroidDeployQt.cmake | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'toolchain/ECMAndroidDeployQt.cmake') diff --git a/toolchain/ECMAndroidDeployQt.cmake b/toolchain/ECMAndroidDeployQt.cmake index 544f5a8d..65b68c67 100644 --- a/toolchain/ECMAndroidDeployQt.cmake +++ b/toolchain/ECMAndroidDeployQt.cmake @@ -1,7 +1,37 @@ -cmake_minimum_required (VERSION 3.7 FATAL_ERROR) +cmake_minimum_required (VERSION 3.19 FATAL_ERROR) find_package(Qt5Core REQUIRED) find_package(Python3 COMPONENTS Interpreter REQUIRED) +# Taken from https://stackoverflow.com/a/62311397 +function(_ecm_get_all_targets var) + set(targets) + _ecm_get_all_targets_recursive(targets ${CMAKE_CURRENT_SOURCE_DIR}) + set(${var} ${targets} PARENT_SCOPE) +endfunction() + +macro(_ecm_get_all_targets_recursive targets dir) + get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES) + foreach(subdir ${subdirectories}) + _ecm_get_all_targets_recursive(${targets} ${subdir}) + endforeach() + + get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS) + list(APPEND ${targets} ${current_targets}) +endmacro() + +function(_ecm_deferred_androiddeployqt) + _ecm_get_all_targets(all_targets) + set(module_targets) + foreach(tgt ${all_targets}) + get_target_property(tgt_type ${tgt} TYPE) + if(tgt_type STREQUAL "MODULE_LIBRARY") + list(APPEND module_targets "$") + endif() + endforeach() + file(GENERATE OUTPUT "module-plugins" CONTENT "${module_targets}") +endfunction() +cmake_language(DEFER DIRECTORY "${CMAKE_SOURCE_DIR}" CALL _ecm_deferred_androiddeployqt) + function(ecm_androiddeployqt QTANDROID_EXPORTED_TARGET ECM_ADDITIONAL_FIND_ROOT_PATH) set(EXPORT_DIR "${CMAKE_BINARY_DIR}/${QTANDROID_EXPORTED_TARGET}_build_apk/") if (Qt5Core_VERSION VERSION_LESS 5.14.0) -- cgit v1.2.1