diff options
author | Gabriel Souza Franco <gabrielfrancosouza@gmail.com> | 2020-11-25 12:09:06 -0300 |
---|---|---|
committer | Gabriel Souza Franco <gabrielfrancosouza@gmail.com> | 2020-12-19 13:38:10 +0000 |
commit | f493041ad039867bb24a4259657acf3f3d522dfe (patch) | |
tree | 368425cb3f27cce3df21a5a79155aecbc90037f1 /toolchain/ECMAndroidDeployQt.cmake | |
parent | 34af7272582ba4c8e62811fe470fc56661f17421 (diff) | |
download | extra-cmake-modules-f493041ad039867bb24a4259657acf3f3d522dfe.tar.gz extra-cmake-modules-f493041ad039867bb24a4259657acf3f3d522dfe.tar.bz2 |
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.
Diffstat (limited to 'toolchain/ECMAndroidDeployQt.cmake')
-rw-r--r-- | toolchain/ECMAndroidDeployQt.cmake | 32 |
1 files changed, 31 insertions, 1 deletions
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 "$<TARGET_FILE:${tgt}>") + 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) |