aboutsummaryrefslogtreecommitdiff
path: root/toolchain
diff options
context:
space:
mode:
authorGabriel Souza Franco <gabrielfrancosouza@gmail.com>2020-11-25 12:09:06 -0300
committerGabriel Souza Franco <gabrielfrancosouza@gmail.com>2020-12-19 13:38:10 +0000
commitf493041ad039867bb24a4259657acf3f3d522dfe (patch)
tree368425cb3f27cce3df21a5a79155aecbc90037f1 /toolchain
parent34af7272582ba4c8e62811fe470fc56661f17421 (diff)
downloadextra-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')
-rw-r--r--toolchain/ECMAndroidDeployQt.cmake32
-rw-r--r--toolchain/specifydependencies.cmake68
2 files changed, 71 insertions, 29 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)
diff --git a/toolchain/specifydependencies.cmake b/toolchain/specifydependencies.cmake
index 905b62c3..69a7f534 100644
--- a/toolchain/specifydependencies.cmake
+++ b/toolchain/specifydependencies.cmake
@@ -1,25 +1,31 @@
-execute_process(COMMAND readelf --wide --dynamic ${TARGET} ERROR_VARIABLE readelf_errors OUTPUT_VARIABLE out RESULT_VARIABLE result)
-if (NOT result EQUAL 0)
- message(FATAL_ERROR "readelf failed on ${TARGET} exit(${result}): ${readelf_errors}")
-endif()
+function(list_dependencies target libs)
+ execute_process(COMMAND readelf --wide --dynamic ${target} ERROR_VARIABLE readelf_errors OUTPUT_VARIABLE out RESULT_VARIABLE result)
-string(REPLACE "\n" ";" lines "${out}")
-set(extralibs)
-foreach(line ${lines})
- string(REGEX MATCH ".*\\(NEEDED\\) +Shared library: +\\[(.+)\\]$" matched ${line})
- set(currentLib ${CMAKE_MATCH_1})
+ if (NOT result EQUAL 0)
+ message(FATAL_ERROR "readelf failed on ${target} exit(${result}): ${readelf_errors}")
+ endif()
- if(NOT ${currentLib} MATCHES "libQt5.*" AND matched)
- find_file(ourlib-${currentLib} ${currentLib} HINTS ${OUTPUT_DIR} ${EXPORT_DIR} ${ECM_ADDITIONAL_FIND_ROOT_PATH} NO_DEFAULT_PATH PATH_SUFFIXES lib)
+ string(REPLACE "\n" ";" lines "${out}")
+ set(extralibs ${${libs}})
+ foreach(line ${lines})
+ string(REGEX MATCH ".*\\(NEEDED\\) +Shared library: +\\[(.+)\\]$" matched ${line})
+ set(currentLib ${CMAKE_MATCH_1})
- if(ourlib-${currentLib})
- list(APPEND extralibs "${ourlib-${currentLib}}")
- else()
- message(STATUS "could not find ${currentLib} in ${OUTPUT_DIR} ${EXPORT_DIR}/lib/ ${ECM_ADDITIONAL_FIND_ROOT_PATH}")
+ if(NOT ${currentLib} MATCHES "libQt5.*" AND matched)
+ find_file(ourlib-${currentLib} ${currentLib} HINTS ${OUTPUT_DIR} ${EXPORT_DIR} ${ECM_ADDITIONAL_FIND_ROOT_PATH} NO_DEFAULT_PATH PATH_SUFFIXES lib)
+
+ if(ourlib-${currentLib})
+ list(APPEND extralibs "${ourlib-${currentLib}}")
+ else()
+ message(STATUS "could not find ${currentLib} in ${OUTPUT_DIR} ${EXPORT_DIR}/lib/ " ${ECM_ADDITIONAL_FIND_ROOT_PATH})
+ endif()
endif()
- endif()
-endforeach()
+ endforeach()
+ set(${libs} ${extralibs} PARENT_SCOPE)
+endfunction()
+
+list_dependencies(${TARGET} extralibs)
function(contains_library libpath IS_EQUAL)
get_filename_component (name ${libpath} NAME)
@@ -47,23 +53,29 @@ if (ANDROID_EXTRA_LIBS)
endforeach()
endif()
-if(extralibs)
- string(REPLACE ";" "," libs "${extralibs}")
- set(extralibs "\"android-extra-libs\": \"${libs}\",")
-endif()
-
set(extraplugins)
-foreach(folder "share" "lib/qml") #now we check for folders with extra stuff
+foreach(folder "plugins" "share" "lib/qml") #now we check for folders with extra stuff
set(plugin "${EXPORT_DIR}/${folder}")
if(EXISTS "${plugin}")
- if(extraplugins)
- set(extraplugins "${extraplugins},${plugin}")
- else()
- set(extraplugins "${plugin}")
- endif()
+ list(APPEND extraplugins "${plugin}")
endif()
endforeach()
+
+if(EXISTS "module-plugins")
+ file(READ "module-plugins" moduleplugins)
+ foreach(module ${moduleplugins})
+ list_dependencies(${module} extralibs)
+ endforeach()
+ list(REMOVE_DUPLICATES extralibs)
+endif()
+
+if(extralibs)
+ string(REPLACE ";" "," extralibs "${extralibs}")
+ set(extralibs "\"android-extra-libs\": \"${extralibs}\",")
+endif()
+
if(extraplugins)
+ string(REPLACE ";" "," extraplugins "${extraplugins}")
set(extraplugins "\"android-extra-plugins\": \"${extraplugins}\",")
endif()