[CMake] pkg-config and Cross_compiling

Wookey wookey at wookware.org
Wed Jul 2 12:59:37 EDT 2008


OK. I have a cmake project and now 2.6 is out I am able to try
cross-compiling. Initially I found that setting CMAKE_FIND_ROOT_PATH
in my toolchina file didn't make any difference - eventually I worked
out that that was becuase the project CMakeLists.txt file didn;t use
any of the FIND_FILE FIND_PACKAGE etc functionality.

I found that FIND_PACKAGE only covers some libs and pkg-config covered
some others - neither covered all the libs needed. Is one or other
mechanism preferred? I also found that some FINDPackage modules are
quite out-of-date - e.g. FINDGTK only coveres v1.2, not 2.0, I
wondered if this was because pckconfig was deemed amore generic
soultion and they were now deprecated?

A few days of fiddling later the CMake file now uses both FIND_PACKAGE
and pkg-config. The FIND_PACKAGE stuff automagically works with
CMAKE_FIND_ROOT_PATH as described in the docs, however the pkg_config
stuff does not.

pkg_check_modules looks in /usr/lib/pkgconfig rather thanin
/usr/arm-linux-gnu/lib/pkgconfig for .pc files, when CROSS_COMPILING
is true and CMAKE_FIND_ROOT_PATH is set. This results in it finding
the native versions of libraries and headers not the target versions.

pkg-config can be made to look in the right place (first, it still
looks in the wrong place too, but there's not much cmake can do about
that) by setting the PKG_CONFIG_PATH environment variable.

I tried to fix the FindPkgConfig.cmake file to automaticaly do this,
but found that it uses execute_process to call pkg-config and there
seems to be no way to set an environment variable with this call. Am I
missing something? Fixing this module to look in
CMAKE_FIND_ROOT_PATH when cross-compiling seems like the best fix to
me, but there may be a better way?

I couldn't see any other way to inject an appropriate path in cmake
either, but hopefully there is one?

I have made things work by running cmake with the env var set:
PKG_CONFIG_PATH=/usr/arm-linux-gnu/lib/pkgconfig/  cmake
-DCMAKE_TOOLCHAIN_FILE=./CMakeCross.txt
but this seems a clunky solution.

Suggestions welcome as to how to fix this, as it seems a pretty
important omission for cross-compiling.

Thanx for cmake, it seems to be significantly less painful than
autofoo. Once we've got the cross-building stuff software I'll put
support for cmake into dpkg-cross so things should 'just work' on
Debian (for properly-written cmake files).

Wookey
-- 
Principal hats:  Balloonz - Toby Churchill - Aleph One - Debian
http://wookware.org/


More information about the CMake mailing list