On Tuesday 04 November 2008, Hendrik Sattler wrote:
> Am Tuesday 04 November 2008 22:45:57 schrieb Alexander Neundorf:
> > So, if e.g. CMAKE_FIND_ROOT_PATH is /opt/eldk-4.1/ppc_4xxFP/ppc_4xxFP ,
> > then I would have to query pkg-config for the variable "prefix", then
> > prepend this prefix with the directory (the right one) from
> > CMAKE_FIND_ROOT_PATH, and then call pkg-config with
> > --define-variable=prefix=<the constructed prefix> ?
>
> Maybe you should ask the pkg-config people about this? The windows-only
> behaviour/options would be very handy for cross-compile support.
>
> > > BTW: <cross>-pkg-config as proposed here should indeed be used if
> > > present. However(!) and like the one above, it will also fail if you
> > > have more than one root prefix.
> >
> > I checked, my eldk doesn't come with an own pkg-config, so I don't have
> > some <cross>-pkg-config around.
> > How would this <cross>-pkg-config behave ?
> > How would it handle the PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH variables ?
> > Does it print the adjusted path for e.g. include dir etc. ?
>
> Don't know, never had one because the host's pkgconfig should be
> sufficient.
>
> > > The right fix would be to do the same as on Windows and automatically
> > > define prefix relative to the location of the .pc file that is
> > > currently in use (and remove the prefix variable from all those files).
> >
> > Is there a way to tell pkgconfig to print the full path of the pc file
> > which it found ?
> > I don't see this in the help.
>
> It is only hidden in the source code:
> $ pkg-config --variable=pcfiledir
>
> Maybe that can be used to solve the issue. Still, on Windows this is
> handled automatically by pkg-config itself.
Thanks for all the comments.
Please have a look at the attached patch and give it a try.
It does:
set the PKG_CONFIG_LIBDIR env.var
unset the PKG_CONFIG_PATH env.var
figure out "prefix" for the package from --variable=pcfiledir
More comments ?
It doesn't take a <prefix>-pkg-config into account yet.
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 3 Nov 2008 22:03:23 -0000
@@ -14,9 +14,25 @@
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.
+# 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})
+ LIST(APPEND pkgconfigLibDir ${currentFindRoot}/usr/lib/pkgconfig )
+ LIST(APPEND pkgconfigLibDir ${currentFindRoot}/usr/local/lib/pkgconfig )
+ ENDFOREACH(currentFindRoot)
+ FILE(TO_NATIVE_PATH "${pkgconfigLibDir}" pkgconfigLibDir)
+ SET(ENV{PKG_CONFIG_LIBDIR} "${pkgconfigLibDir}" )
+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})
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 3 Nov 2008 22:03:23 -0000
@@ -103,6 +103,20 @@ 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.
+# 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
+if(CMAKE_CROSSCOMPILING AND CMAKE_FIND_ROOT_PATH)
+ set(pkgconfigLibDir)
+ foreach(currentFindRoot ${CMAKE_FIND_ROOT_PATH})
+ list(APPEND pkgconfigLibDir ${currentFindRoot}/usr/lib/pkgconfig )
+ list(APPEND pkgconfigLibDir ${currentFindRoot}/usr/local/lib/pkgconfig )
+ endforeach(currentFindRoot)
+ file(TO_NATIVE_PATH "${pkgconfigLibDir}" pkgconfigLibDir)
+ set(ENV{PKG_CONFIG_LIBDIR} "${pkgconfigLibDir}" )
+endif(CMAKE_CROSSCOMPILING AND CMAKE_FIND_ROOT_PATH)
# Unsets the given variables
macro(_pkgconfig_unset var)
_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake