From c91c3650968d828d52291f97f835a5a04024c2e0 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Wed, 20 Dec 2017 20:42:59 +0100 Subject: Use readelf to find project dependencies Summary: We were using a link.txt file that cmake used to generate, on newer cmake versions it doesn't anymore. Instead use readelf, much like androiddeployqt does, to extract the depenencies. Catch: It relies on having all the binaries being at the same subdirectory, which is the default in ECM since not long ago. Test Plan: Build kirigamigallery with it Reviewers: #frameworks, #build_system, aacid Reviewed By: aacid Subscribers: mart Tags: #frameworks, #build_system Differential Revision: https://phabricator.kde.org/D8173 --- toolchain/specifydependencies.cmake | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'toolchain/specifydependencies.cmake') diff --git a/toolchain/specifydependencies.cmake b/toolchain/specifydependencies.cmake index 65e875bf..8965d6da 100644 --- a/toolchain/specifydependencies.cmake +++ b/toolchain/specifydependencies.cmake @@ -1,27 +1,29 @@ -file(READ "${TARGET_DIR}/CMakeFiles/${TARGET_NAME}.dir/link.txt" out) +execute_process(COMMAND readelf --wide --dynamic ${TARGET} ERROR_VARIABLE readelf_errors OUTPUT_VARIABLE out RESULT_VARIABLE result) -string(FIND "${out}" "-o ${TARGET_NAME}" POS) #we trim the initial arguments, we want the ones in the end. we find the target -string(SUBSTRING "${out}" ${POS} -1 out) #we -string(REGEX MATCHALL "(/|\\.\\./|\\./)[^ ]+\\.so" outout "${out}") -string(STRIP "${outout}" outout) -string(REPLACE " /" ";/" outout "${outout}") +if (NOT result EQUAL 0) + message(FATAL_ERROR "readelf failed on ${TARGET} exit(${result}): ${readelf_errors}") +endif() +string(REPLACE "\n" ";" lines "${out}") set(extralibs) -foreach(lib IN LISTS outout) #now we filter Qt5 libraries, because Qt wants to take care about these itself - if(NOT ${lib} MATCHES ".*/libQt5.*") - # resolve relative paths - if(${lib} MATCHES "^(\\.\\./|\\./)") - set(lib "${TARGET_DIR}/${lib}") - endif() - if(extralibs) - set(extralibs "${extralibs},${lib}") +foreach(line ${lines}) + string(REGEX MATCH ".*\\(NEEDED\\) +Shared library: +\\[(.+)\\]$" matched ${line}) + set(currentLib ${CMAKE_MATCH_1}) + + 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() - set(extralibs "${lib}") + message(STATUS "could not find ${currentLib} in ${OUTPUT_DIR} ${EXPORT_DIR}/lib/ ${ECM_ADDITIONAL_FIND_ROOT_PATH}") endif() endif() endforeach() + if(extralibs) - set(extralibs "\"android-extra-libs\": \"${extralibs}\",") + string(REPLACE ";" "," libs "${extralibs}") + set(extralibs "\"android-extra-libs\": \"${libs}\",") endif() set(extraplugins) -- cgit v1.2.1