opencv/cmake
Samuel Martin 671a630f47 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 substitutions for these paths when the
aforementioned environment variables are set.
In such case, since the prefix is the target one, not the sysroot one,
these libraries' absolute 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<libdir> -l<libname>

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

This patch is a port of [6] on the master branch.

[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
[6] eceada586b

Signed-off-by: Samuel Martin <s.martin49@gmail.com>
2015-05-22 16:09:05 +03:00
..
checks Removing unused winrttest.cpp file 2015-03-23 16:56:50 +03:00
FindCUDA update FindCUDA CMake module to the latest version from upstream 2014-12-23 17:47:04 +03:00
templates VideoCapture with digital camera and gPhoto2 library 2015-05-21 00:41:39 +02:00
cl2cpp.cmake Build separate world-like iOS framework for contrib 2014-12-05 17:48:28 +03:00
copyAndroidLibs.cmake android: allow to build & run examples without Android OpenCV Manager 2014-06-06 18:01:04 +04:00
FindCUDA.cmake port of aarch64 cuda changes from 2.4 2015-04-23 17:57:29 +03:00
OpenCVCompilerOptions.cmake Merge pull request #3966 from Dikay900:master_diff_to_2_4_2 2015-04-28 11:00:57 +00:00
OpenCVConfig.cmake Add VS2015 compatibility to CMake scripts 2015-05-02 15:24:14 +01:00
OpenCVCRTLinkage.cmake Adding support for WinRT(WinPhone 8/8.1 and Win Store) via CMake 3.1 2015-03-02 22:26:43 +03:00
OpenCVDetectAndroidSDK.cmake world fix 2014-08-05 20:12:35 +04:00
OpenCVDetectApacheAnt.cmake Fix ant/Java detection in cmake scripts 2013-03-29 18:29:40 +04:00
OpenCVDetectCStripes.cmake fixed C= detection script 2012-10-10 16:15:27 +04:00
OpenCVDetectCUDA.cmake Merge pull request #3758 from ilya-lavrenov:aarch64 2015-03-02 10:50:31 +00:00
OpenCVDetectCXXCompiler.cmake Add VS2015 compatibility to CMake scripts 2015-05-02 15:24:14 +01:00
OpenCVDetectDirectX.cmake cmake: detect Direct 3D 11 2013-12-13 15:57:31 +04:00
OpenCVDetectOpenCL.cmake Fixing buildbot job: 2015-03-02 22:26:45 +03:00
OpenCVDetectPython.cmake Fix win32 search for same bitness executable 2015-04-10 14:57:31 +02:00
OpenCVDetectTBB.cmake Added suuport for finding Intel TBB for Visual Studio 2013 2014-04-28 07:23:49 -04:00
OpenCVDetectVTK.cmake More proper OpneCv+Qt+Vtk issues handling (http://code.opencv.org/issues/3492) 2014-02-10 15:45:44 +04:00
OpenCVExtraTargets.cmake Removed all use of the obsolete IMMEDIATE parameter to configure_file. 2014-01-29 19:34:02 +04:00
OpenCVFindIntelPerCSDK.cmake Fix notes about cmake files. Fix build warning. 2013-12-17 16:13:55 +04:00
OpenCVFindIPP.cmake explained reason why IPP is disabled on 32-bit Linux. disable IPP's minMaxLoc_32f on 32-bit OSes only 2015-03-06 15:02:22 +03:00
OpenCVFindIPPAsync.cmake Added SharedMatrix 2014-04-03 14:53:27 +04:00
OpenCVFindLATEX.cmake Started top-level CMakeLists.txt file reorganization: cmake scripts are moved to separate folder; refactored BUILD_*, INSTALL_*, ENABLE_*, USE_*, WITH_* options. 2012-01-03 13:48:12 +00:00
OpenCVFindLibsGrfmt.cmake Fixing the gdal include error that Macports seems to only mess up. 2015-05-11 20:27:50 -07:00
OpenCVFindLibsGUI.cmake Correction to enable compilation on platform with only GTK2 libs 2014-04-13 11:11:05 +01:00
OpenCVFindLibsPerf.cmake ipp: added support for updated ICV package 2014-04-09 18:20:49 +04:00
OpenCVFindLibsVideo.cmake VideoCapture with digital camera and gPhoto2 library 2015-05-21 00:41:39 +02:00
OpenCVFindMatlab.cmake Added TODO for the future of Matlab version sorting 2013-09-16 00:48:07 +10:00
OpenCVFindOpenEXR.cmake Normalize line endings and whitespace 2012-10-17 15:57:49 +04:00
OpenCVFindOpenNI2.cmake Added enviroment search paths for OpenNI2 for linux and fixed specific warning 2014-12-24 15:07:05 +03:00
OpenCVFindOpenNI.cmake Normalize line endings and whitespace 2012-10-17 15:57:49 +04:00
OpenCVFindWebP.cmake This code is based on https://github.com/prasannatsm/opencv code. 2013-03-11 11:51:38 +04:00
OpenCVFindXimea.cmake XIMEA cam support: allow on OS X too 2014-09-09 19:25:14 +04:00
OpenCVGenABI.cmake Do not compare extra modules in ABI check 2015-03-23 13:10:40 +03:00
OpenCVGenAndroidMK.cmake Fix generating of android.mk 2015-04-06 16:12:00 +03:00
OpenCVGenConfig.cmake Fixed mangled install layout on unix machines 2015-03-13 14:18:37 +03:00
OpenCVGenHeaders.cmake Install cvconfig.h file 2015-05-18 19:19:48 +03:00
OpenCVGenInfoPlist.cmake Build separate world-like iOS framework for contrib 2014-12-05 17:48:28 +03:00
OpenCVGenPkgconfig.cmake cmake/OpenCVGenPkgconfig.cmake: rework opencv.pc generation 2015-05-22 16:09:05 +03:00
OpenCVMinDepVersions.cmake Build both Python 2 and Python 3 bindings 2014-06-29 20:08:13 -04:00
OpenCVModule.cmake Basic HAL module 2015-04-07 18:16:22 +03:00
OpenCVPackaging.cmake Mark the libs component required 2015-03-10 16:24:23 +03:00
OpenCVPCHSupport.cmake world fix 2014-08-05 20:12:35 +04:00
OpenCVUtils.cmake Generators: updated the library gathering loop 2015-04-08 14:15:20 +03:00
OpenCVVersion.cmake Switched OpenCV to a 3-component version number. 2013-11-15 19:41:53 +04:00