opencv/cmake
Samuel Martin eceada586b 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<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

[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 <s.martin49@gmail.com>

---
Note: this patch properly applies on top of the master branch, though it
      has been written on top of the 2.4 branch.
2014-11-05 11:32:11 +01:00
..
checks ocl: workaround for msvc11 bug 2013-10-18 20:52:36 +04:00
FindCUDA added own version of FindCUDA.cmake 2013-10-28 10:09:16 +04:00
templates Exclude OpenCL tests from default test list for Android as they are experimental. 2014-09-29 20:45:12 +04:00
cl2cpp.cmake ocl: fix compilation warnings, update openCLExecuteKernelInterop 2013-10-10 00:15:02 +04:00
CMakeParseArguments.cmake minor fix in FindTBB 2012-08-23 13:37:27 +04:00
FindCUDA.cmake fixed CUDA_TOOLKIT_TARGET_DIR for android: 2013-11-28 13:35:23 +04:00
OpenCVCompilerOptions.cmake Fixes for QNX 6.6 Neitrino support. 2014-10-23 17:17:35 +04:00
OpenCVConfig.cmake Added Visual Studio 2013 detection. 2013-11-18 19:39:39 +04:00
OpenCVCRTLinkage.cmake Add VS2013 support 2014-09-10 17:18:41 +08:00
OpenCVDetectAndroidSDK.cmake Cut path to CUDA libraries to prevent generation of OpenCVModules.cmake with abs path. 2014-03-19 18:47:32 +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 Cut path to CUDA libraries to prevent generation of OpenCVModules.cmake with abs path. 2014-03-19 18:47:32 +04:00
OpenCVDetectCXXCompiler.cmake Added Visual Studio 2013 detection. 2013-11-18 19:39:39 +04:00
OpenCVDetectOpenCL.cmake ocl: force to use Khronos OpenCL headers 2013-10-18 15:47:11 +04:00
OpenCVDetectPython.cmake Changed cmake python library search startegy for crosscompiling 2014-09-12 13:44:16 +04:00
OpenCVDetectTBB.cmake TBB download and build option enabled for non Android platfroms. 2013-02-06 14:43:57 +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 Fixed compilation with IPP on Linux. Added linking with Intel compiler runtime libraries. 2014-02-17 16:56:02 +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 fixed problems with building iOS version 2013-08-23 13:41:19 +04:00
OpenCVFindLibsGUI.cmake Fix errors in usages of try_compile 2013-08-22 15:56:35 +04:00
OpenCVFindLibsPerf.cmake Add better OpenMP detection and make an option to enable it. 2013-10-22 18:47:37 +04:00
OpenCVFindLibsVideo.cmake GStreamer 1.0 backport from master branch. 2014-09-30 12:30:09 +04:00
OpenCVFindOpenEXR.cmake Normalize line endings and whitespace 2012-10-17 15:32:23 +04:00
OpenCVFindOpenNI.cmake Normalize line endings and whitespace 2012-10-17 15:32:23 +04:00
OpenCVFindPkgConfig.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
OpenCVFindXimea.cmake XIMEA cam support: allow on OS X too 2014-09-09 19:17:13 +04:00
OpenCVGenAndroidMK.cmake Libraries filter update after abs path cut. 2014-03-21 12:48:38 +04:00
OpenCVGenConfig.cmake Removed all use of the obsolete IMMEDIATE parameter to configure_file. 2014-01-29 19:34:02 +04:00
OpenCVGenHeaders.cmake All installed files marked with component names for install customization. 2014-01-21 20:34:36 +04:00
OpenCVGenInfoPlist.cmake Fix building the iOS framework after I dropped the VERSION macro. 2013-08-06 18:56:36 +04:00
OpenCVGenPkgconfig.cmake cmake/OpenCVGenPkgconfig.cmake: rework opencv.pc generation 2014-11-05 11:32:11 +01:00
OpenCVLegacyOptions.cmake Normalized file endings. 2013-08-21 18:59:25 +04:00
OpenCVModule.cmake determine test category (Public vs Extra) based on module location 2014-10-21 18:51:02 +04:00
OpenCVPackaging.cmake Added implicit dependency from python and python-py to debian packages. 2014-09-29 17:43:54 +04:00
OpenCVPCHSupport.cmake cmake: PCH: use DEFINE_SYMBOL target property 2013-09-25 12:27:08 +04:00
OpenCVUtils.cmake Multiple improvements in OpenCV examples build. 2014-02-06 15:32:57 +04:00
OpenCVVersion.cmake Consistently use 4-digit library version 2013-01-18 14:57:55 +04:00