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/specifydependencies.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/specifydependencies.cmake')
-rw-r--r-- | toolchain/specifydependencies.cmake | 68 |
1 files changed, 40 insertions, 28 deletions
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() |