From patchwork Sun May 17 13:03:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Martin X-Patchwork-Id: 473158 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ozlabs.org (Postfix) with ESMTP id 214C7140A98 for ; Sun, 17 May 2015 23:03:30 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=aIsZWiKz; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 333CF8BE19; Sun, 17 May 2015 13:03:29 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id P8FZZei9T41I; Sun, 17 May 2015 13:03:27 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 5EE9A8BDF2; Sun, 17 May 2015 13:03:27 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (silver.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id A301D1BFA9F for ; Sun, 17 May 2015 13:03:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id A31F730FA3 for ; Sun, 17 May 2015 13:03:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LL5dWkKOgFFb for ; Sun, 17 May 2015 13:03:23 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com [209.85.212.170]) by silver.osuosl.org (Postfix) with ESMTPS id 12DE7266BE for ; Sun, 17 May 2015 13:03:23 +0000 (UTC) Received: by wibt6 with SMTP id t6so41386372wib.0 for ; Sun, 17 May 2015 06:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=88oYOUnuchGbRfnDLucPxM6fRFaa4T3RtPv3Wel9jS0=; b=aIsZWiKzClNqisB6JwJjMtCRcl7qCnKMwtSl50rCrzqMxDSZt9E57R05OL8PDhIS1e m3H0iADzwU3p4F1zebIGQ+L5LCYMaebS4x8cIhuomjouOrTHY3KWGfoUi19kEpsKrElC OdcjJX7vQtMKN5I8jlN4nqd0thTZ2xyW/P9k6bYps5C0caPaf/6cTDOOzBHedX1dd/hV 4rifYoHxqw3MkLLpukmpbt86E8OC0ZJEIUaKIsdhG2B+2vd6UZ78wbCMTkutMq07UalV foo0Q7CzCiiye5yaw2x7RKD/lU8oHsUvqKQlDR2KcsUnRSbLT9tfOmF2ON8FMpGXO0y2 gPdQ== X-Received: by 10.194.161.138 with SMTP id xs10mr36177775wjb.37.1431867801505; Sun, 17 May 2015 06:03:21 -0700 (PDT) Received: from bobook.localdomain (ANantes-655-1-143-147.w2-0.abo.wanadoo.fr. [2.0.174.147]) by mx.google.com with ESMTPSA id h5sm11964075wjn.20.2015.05.17.06.03.19 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 17 May 2015 06:03:20 -0700 (PDT) From: Samuel Martin To: buildroot@buildroot.org Date: Sun, 17 May 2015 15:03:14 +0200 Message-Id: <1431867794-6291-1-git-send-email-s.martin49@gmail.com> X-Mailer: git-send-email 2.4.1 Cc: Thomas Petazzoni , "Yann E. MORIN" Subject: [Buildroot] [PATCH] package/opencv: fix opencv.pc generation X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" This change fixes build of packages depending on opencv and using pkg-config to get the opencv LDFLAGS, which were wrongly ordered for static build and included absolute path pointing to the host system libraries instead of the sysroot ones. This patch fixes build issues with gst1-plugins-bad and vlc. This change introduce and new patch to opencv, which is already merged upstream [1]. Fixes: http://autobuild.buildroot.net/results/c70/c70f793c7c3b380428d6e2e622a90805cffc4dd1/ ... and many others [1] https://github.com/Itseez/opencv/commit/eceada586bbf18fc267e437522ec4f1f23ddc656 Cc: "Yann E. MORIN" Cc: Thomas Petazzoni Signed-off-by: Samuel Martin Tested-by: "Yann E. MORIN" --- Note that this fix is for upcoming 2015.05 release, and I am already preparing a series bumping of the opencv package for the next release. :) --- ...VGenPkgconfig.cmake-rework-opencv.pc-gene.patch | 156 +++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 package/opencv/0003-cmake-OpenCVGenPkgconfig.cmake-rework-opencv.pc-gene.patch diff --git a/package/opencv/0003-cmake-OpenCVGenPkgconfig.cmake-rework-opencv.pc-gene.patch b/package/opencv/0003-cmake-OpenCVGenPkgconfig.cmake-rework-opencv.pc-gene.patch new file mode 100644 index 0000000..768f08d --- /dev/null +++ b/package/opencv/0003-cmake-OpenCVGenPkgconfig.cmake-rework-opencv.pc-gene.patch @@ -0,0 +1,156 @@ +From eceada586bbf18fc267e437522ec4f1f23ddc656 Mon Sep 17 00:00:00 2001 +From: Samuel Martin +Date: Fri, 3 Oct 2014 00:32:40 +0200 +Subject: [PATCH] cmake/OpenCVGenPkgconfig.cmake: rework opencv.pc generation + +Using absolute path to locate the components in the "Libs:" field of the +*.pc can badly break cross-compilation, especially when building +statically linked objects. + +Indeed, pkg-config automatically replaces the '-I...' and '-L...' paths +when the PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_LIBDIR environment +variables are set [1]. This feature is very helpful and common in +cross-compilation framework like Buildroot [2,3]. + +When there are absolute paths in the *.pc files, pkg-config won't be +able to do the path substitions for these paths when the afromentioned +environment variables are set. +In such case, since the prefix is the target one, not the sysroot one, +these libraries' abolute paths will point to: +- in the best case: a non-existing file (i.e. these files do not exists + on the host system; +- at worst: the host system's libraries. This will make the linking + failed because these host system's libraries will most likely not be + build for the target architecture [4]. + +So, this patch replace the components' absolute paths by the form: + -L -l + +This way, the linker will be able to resolve each dependency path, +whatever the kind of objects/build (shared object or static build) it +is dealing with. + +Note that for static link, the library order does matter [5]. The order +of the opencv components has been carefully chosen to comply with this +requirement. + +Fixes #3931 + +[1] http://linux.die.net/man/1/pkg-config +[2] http://buildroot.org/ +[3] http://git.buildroot.net/buildroot/tree/package/pkgconf/pkg-config.in +[4] http://autobuild.buildroot.net/results/e8a/e8a859276db34aff87ef181b0cce98916b0afc90/build-end.log +[5] http://stackoverflow.com/questions/45135/linker-order-gcc + +Signed-off-by: Samuel Martin + +--- +Note: this patch properly applies on top of the master branch, though it + has been written on top of the 2.4 branch. +--- + cmake/OpenCVGenPkgconfig.cmake | 64 +++++++++++++++++++++++++++--------------- + 1 file changed, 42 insertions(+), 22 deletions(-) + +diff --git a/cmake/OpenCVGenPkgconfig.cmake b/cmake/OpenCVGenPkgconfig.cmake +index fa57db9..183c56d 100644 +--- a/cmake/OpenCVGenPkgconfig.cmake ++++ b/cmake/OpenCVGenPkgconfig.cmake +@@ -8,10 +8,6 @@ + # + # ${BIN_DIR}/unix-install/opencv.pc -> For use *with* "make install" + # ------------------------------------------------------------------------------------------- +-set(prefix "${CMAKE_INSTALL_PREFIX}") +-set(exec_prefix "\${prefix}") +-set(libdir "") #TODO: need link paths for OpenCV_EXTRA_COMPONENTS +-set(includedir "\${prefix}/${OPENCV_INCLUDE_INSTALL_PATH}") + + if(CMAKE_BUILD_TYPE MATCHES "Release") + set(ocv_optkind OPT) +@@ -35,42 +31,66 @@ ocv_list_reverse(OpenCV_LIB_COMPONENTS) + ocv_list_reverse(OpenCV_EXTRA_COMPONENTS) + + #build the list of components +-set(OpenCV_LIB_COMPONENTS_ "") +-foreach(CVLib ${OpenCV_LIB_COMPONENTS}) +- get_target_property(libpath ${CVLib} LOCATION_${CMAKE_BUILD_TYPE}) +- get_filename_component(libname "${libpath}" NAME) + +- if(INSTALL_TO_MANGLED_PATHS) +- set(libname "${libname}.${OPENCV_VERSION}") +- endif() ++# Note: ++# when linking against static libraries, if libfoo depends on libbar, then ++# libfoo must come first in the linker flags. ++ ++# world is a special target whose library should come first, especially for ++# static link. ++if(OpenCV_LIB_COMPONENTS MATCHES "opencv_world") ++ list(REMOVE_ITEM OpenCV_LIB_COMPONENTS "opencv_world") ++ list(INSERT OpenCV_LIB_COMPONENTS 0 "opencv_world") ++endif() ++ ++set(OpenCV_LIB_COMPONENTS_) ++foreach(CVLib ${OpenCV_LIB_COMPONENTS}) + +- #need better solution.... +- if(libpath MATCHES "3rdparty") +- set(installDir "share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}") ++ get_target_property(libloc ${CVLib} LOCATION_${CMAKE_BUILD_TYPE}) ++ if(libloc MATCHES "3rdparty") ++ set(libpath "\${exec_prefix}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}") + else() +- set(installDir "${OPENCV_LIB_INSTALL_PATH}") ++ set(libpath "\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}") + endif() ++ list(APPEND OpenCV_LIB_COMPONENTS_ "-L${libpath}") ++ ++ get_filename_component(libname ${CVLib} NAME_WE) ++ string(REGEX REPLACE "^lib" "" libname "${libname}") ++ list(APPEND OpenCV_LIB_COMPONENTS_ "-l${libname}") + +- set(OpenCV_LIB_COMPONENTS_ "${OpenCV_LIB_COMPONENTS_} \${exec_prefix}/${installDir}/${libname}") + endforeach() + + # add extra dependencies required for OpenCV +-set(OpenCV_LIB_COMPONENTS ${OpenCV_LIB_COMPONENTS_}) + if(OpenCV_EXTRA_COMPONENTS) + foreach(extra_component ${OpenCV_EXTRA_COMPONENTS}) + +- if(extra_component MATCHES "^-[lL]" OR extra_component MATCHES "[\\/]") +- set(maybe_l_prefix "") ++ if(extra_component MATCHES "^-[lL]") ++ set(libprefix "") ++ set(libname "${extra_component}") ++ elseif(extra_component MATCHES "[\\/]") ++ get_filename_component(libdir "${extra_component}" PATH) ++ list(APPEND OpenCV_LIB_COMPONENTS_ "-L${libdir}") ++ get_filename_component(libname "${extra_component}" NAME_WE) ++ string(REGEX REPLACE "^lib" "" libname "${libname}") ++ set(libprefix "-l") + else() +- set(maybe_l_prefix "-l") ++ set(libprefix "-l") ++ set(libname "${extra_component}") + endif() +- +- set(OpenCV_LIB_COMPONENTS "${OpenCV_LIB_COMPONENTS} ${maybe_l_prefix}${extra_component}") ++ list(APPEND OpenCV_LIB_COMPONENTS_ "${libprefix}${libname}") + + endforeach() + endif() + ++list(REMOVE_DUPLICATES OpenCV_LIB_COMPONENTS_) ++string(REPLACE ";" " " OpenCV_LIB_COMPONENTS "${OpenCV_LIB_COMPONENTS_}") ++ + #generate the .pc file ++set(prefix "${CMAKE_INSTALL_PREFIX}") ++set(exec_prefix "\${prefix}") ++set(libdir "\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}") ++set(includedir "\${prefix}/${OPENCV_INCLUDE_INSTALL_PATH}") ++ + if(INSTALL_TO_MANGLED_PATHS) + set(OPENCV_PC_FILE_NAME "opencv-${OPENCV_VERSION}.pc") + else() +-- +2.4.1 +