On Wednesday 05 November 2008, Hendrik Sattler wrote:
...
> Maybe it was an old patch?

Yes, wrong file.
Next try.

Alex


Index: UsePkgConfig.cmake
===================================================================
RCS file: /cvsroot/CMake/CMake/Modules/UsePkgConfig.cmake,v
retrieving revision 1.7
diff -b -u -p -r1.7 UsePkgConfig.cmake
--- UsePkgConfig.cmake	16 Aug 2008 11:01:49 -0000	1.7
+++ UsePkgConfig.cmake	4 Nov 2008 23:48:26 -0000
@@ -11,12 +11,28 @@
 #
 
 
-
 FIND_PROGRAM(PKGCONFIG_EXECUTABLE NAMES pkg-config )
 
+# When crosscompiling, pkg_config should not search for packages of the host system,
+# but for the target system. To do this, there is the environment variable 
+# PKG_CONFIG_LIBDIR, which was added to pkg_config explicitely for crosscompiling.
+# Additionally PKG_CONFIG_PATH is set empty, otherwise these directories are searched 
+# before PKG_CONFIG_LIBDIR (at least here with version 0.21).
+# So set this here to point inside the CMAKE_FIND_ROOT_PATH so it can find
+# only packages for the target system when crosscompiling. Alex
+SET(pkgconfigLibDir)
+IF(CMAKE_CROSSCOMPILING  AND  CMAKE_FIND_ROOT_PATH)
+   FOREACH(currentFindRoot ${CMAKE_FIND_ROOT_PATH})
+      SET(pkgconfigLibDir "${pkgconfigLibDir}:${currentFindRoot}/usr/lib/pkgconfig:${currentFindRoot}/usr/local/lib/pkgconfig" )
+   ENDFOREACH(currentFindRoot)
+   SET(ENV{PKG_CONFIG_LIBDIR} "${pkgconfigLibDir}" )
+   SET(ENV{PKG_CONFIG_PATH} "" )
+ENDIF(CMAKE_CROSSCOMPILING  AND  CMAKE_FIND_ROOT_PATH)
+
+
 MACRO(PKGCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
   MESSAGE(STATUS
-    "WARNING: you are using the obsolete 'PKGCONFIG' macro use FindPkgConfig")
+    "WARNING: you are using the obsolete 'PKGCONFIG' macro, use FindPkgConfig instead")
 # reset the variables at the beginning
   SET(${_include_DIR})
   SET(${_link_DIR})
@@ -31,20 +47,31 @@ MACRO(PKGCONFIG _package _include_DIR _l
     # and if the package of interest also exists for pkg-config, then get the information
     IF(NOT _return_VALUE)
 
-      EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=includedir 
+      # if cross compiling, determine the location of the pc file and use that to adjust
+      # the "prefix" variable for the pc file accordingly, so it returns the actual path
+      # where the includes and libs are on the host system instead of the location on the target system
+      SET(_pkgconfigDefinePrefixVariable)
+      IF(CMAKE_CROSSCOMPILING  AND  CMAKE_FIND_ROOT_PATH)
+        EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=pcfiledir 
+          OUTPUT_VARIABLE _pkgconfigPcFileDir )
+        STRING(REGEX REPLACE  "^(/.+)/lib/pkgconfig$" "\\1" _pkgconfigPrefix "${_pkgconfigPcFileDir}")
+        SET(_pkgconfigDefinePrefixVariable "--define-variable=prefix=${_pkgconfigPrefix}")
+      ENDIF(CMAKE_CROSSCOMPILING  AND  CMAKE_FIND_ROOT_PATH)
+
+      EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=includedir ${_pkgconfigDefinePrefixVariable} 
         OUTPUT_VARIABLE ${_include_DIR} )
       STRING(REGEX REPLACE "[\r\n]" " " ${_include_DIR} "${${_include_DIR}}")
     
 
-      EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=libdir 
+      EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=libdir ${_pkgconfigDefinePrefixVariable} 
         OUTPUT_VARIABLE ${_link_DIR} )
       STRING(REGEX REPLACE "[\r\n]" " " ${_link_DIR} "${${_link_DIR}}")
 
-      EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --libs 
+      EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --libs ${_pkgconfigDefinePrefixVariable} 
         OUTPUT_VARIABLE ${_link_FLAGS} )
       STRING(REGEX REPLACE "[\r\n]" " " ${_link_FLAGS} "${${_link_FLAGS}}")
 
-      EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --cflags 
+      EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --cflags ${_pkgconfigDefinePrefixVariable} 
         OUTPUT_VARIABLE ${_cflags} )
       STRING(REGEX REPLACE "[\r\n]" " " ${_cflags} "${${_cflags}}")
 
Index: FindPkgConfig.cmake
===================================================================
RCS file: /cvsroot/CMake/CMake/Modules/FindPkgConfig.cmake,v
retrieving revision 1.7
diff -b -u -p -r1.7 FindPkgConfig.cmake
--- FindPkgConfig.cmake	7 Feb 2008 18:19:38 -0000	1.7
+++ FindPkgConfig.cmake	4 Nov 2008 23:48:26 -0000
@@ -103,6 +103,21 @@ if(PKG_CONFIG_EXECUTABLE)
   set(PKG_CONFIG_FOUND 1)
 endif(PKG_CONFIG_EXECUTABLE)
 
+# When crosscompiling, pkg_config should not search for packages of the host system,
+# but for the target system. To do this, there is the environment variable 
+# PKG_CONFIG_LIBDIR, which was added to pkg_config explicitely for crosscompiling.
+# Additionally PKG_CONFIG_PATH is set empty, otherwise these directories are searched 
+# before PKG_CONFIG_LIBDIR (at least here with version 0.21).
+# So set this here to point inside the CMAKE_FIND_ROOT_PATH so it can find
+# only packages for the target system when crosscompiling. Alex
+set(pkgconfigLibDir)
+if(CMAKE_CROSSCOMPILING  AND  CMAKE_FIND_ROOT_PATH)
+   foreach(currentFindRoot ${CMAKE_FIND_ROOT_PATH})
+      set(pkgconfigLibDir "${pkgconfigLibDir}:${currentFindRoot}/usr/lib/pkgconfig:${currentFindRoot}/usr/local/lib/pkgconfig" )
+   endforeach(currentFindRoot)
+   set(ENV{PKG_CONFIG_LIBDIR} "${pkgconfigLibDir}" )
+   set(ENV{PKG_CONFIG_PATH} "" )
+endif(CMAKE_CROSSCOMPILING  AND  CMAKE_FIND_ROOT_PATH)
 
 # Unsets the given variables
 macro(_pkgconfig_unset var)
@@ -273,6 +288,17 @@ macro(_pkg_check_modules_internal _is_re
       # when we are here, we checked whether requested modules
       # exist. Now, go through them and set variables
       
+      # if cross compiling, determine the location of the pc file and use that to adjust
+      # the "prefix" variable for the pc file accordingly, so it returns the actual path
+      # where the includes and libs are on the host system instead of the location on the target system
+      set(_pkgconfigDefinePrefixVariable)
+      if(CMAKE_CROSSCOMPILING  AND  CMAKE_FIND_ROOT_PATH)
+        exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=pcfiledir 
+          OUTPUT_VARIABLE _pkgconfigPcFileDir )
+        string(REGEX REPLACE  "^(/.+)/lib/pkgconfig$" "\\1" _pkgconfigPrefix "${_pkgconfigPcFileDir}")
+        set(_pkgconfigDefinePrefixVariable "--define-variable=prefix=${_pkgconfigPrefix}")
+      endif(CMAKE_CROSSCOMPILING  AND  CMAKE_FIND_ROOT_PATH)
+
       _pkgconfig_set(${_prefix}_FOUND 1)
       list(LENGTH _pkg_check_modules_packages pkg_count)
 
@@ -285,23 +311,23 @@ macro(_pkg_check_modules_internal _is_re
           set(_pkg_check_prefix "${_prefix}_${_pkg_check_modules_pkg}")
         endif(pkg_count EQUAL 1)
         
-        _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" VERSION    ""   --modversion )
-        _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" PREFIX     ""   --variable=prefix )
-        _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" INCLUDEDIR ""   --variable=includedir )
-        _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" LIBDIR     ""   --variable=libdir )
+        _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" VERSION    ""   --modversion ${_pkgconfigDefinePrefixVariable} )
+        _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" PREFIX     ""   --variable=prefix ${_pkgconfigDefinePrefixVariable} )
+        _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" INCLUDEDIR ""   --variable=includedir ${_pkgconfigDefinePrefixVariable} )
+        _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" LIBDIR     ""   --variable=libdir ${_pkgconfigDefinePrefixVariable} )
 
         message(STATUS "  found ${_pkg_check_modules_pkg}, version ${_pkgconfig_VERSION}")
       endforeach(_pkg_check_modules_pkg)
 
       # set variables which are combined for multiple modules
-      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARIES           "(^| )-l" --libs-only-l )
-      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARY_DIRS        "(^| )-L" --libs-only-L )
-      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS             ""        --libs )
-      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS_OTHER       ""        --libs-only-other )
-
-      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" INCLUDE_DIRS        "(^| )-I" --cflags-only-I )
-      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS              ""        --cflags )
-      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS_OTHER        ""        --cflags-only-other )
+      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARIES           "(^| )-l" --libs-only-l ${_pkgconfigDefinePrefixVariable} )
+      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARY_DIRS        "(^| )-L" --libs-only-L ${_pkgconfigDefinePrefixVariable} )
+      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS             ""        --libs ${_pkgconfigDefinePrefixVariable} )
+      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS_OTHER       ""        --libs-only-other ${_pkgconfigDefinePrefixVariable} )
+
+      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" INCLUDE_DIRS        "(^| )-I" --cflags-only-I ${_pkgconfigDefinePrefixVariable} )
+      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS              ""        --cflags ${_pkgconfigDefinePrefixVariable} )
+      _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS_OTHER        ""        --cflags-only-other ${_pkgconfigDefinePrefixVariable} )
     endif(_pkg_check_modules_failed)
   else(PKG_CONFIG_EXECUTABLE)
     if (${_is_required})
_______________________________________________
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to