getting CMake to find (the right) KDL when cross compiling

I'm attempting to build software for VxWorks 6.7. My software has KDL dependencies (and will eventually have Orocos dependencies) and is built with CMake. I've written a toolchain file for CMake to allow easy cross-compiling of CMake-enabled projects. However, the trouble I'm running into is getting my call to find_package(Orocos-KDL REQUIRED) to work.

Here's what I've done so far...

1) Created a toolchain file that enables cross compiling for VxWorks 6.7 on a PPC604 board using the GNU compiler. This sets CMAKE_FIND_ROOT_PATH equal to the target VxWorks directory (as well as the soon to be mentioned environment variable CROSSCOMPILE_DIR).
2) Created a directory ~/cc-dir to store third-party target dependencies (like Eigen and KDL), along with an associated environment variable $CROSSCOMPILE_DIR
3) Cross compiled (ccmake, make and make install) Eigen2 into ~/cc-dir. Cross compilation was accomplished by using the -DCMAKE_TOOLCHAIN_FILE="toolchain.cmake" option for ccmake.
4) Cross compiled KDL into ~/cc-dir. I set the "EIGEN2_INCLUDE_DIR" to point to the target version in ~/cc-dir.
5) Ran ccmake on my project that has a call to find_package(Orocos-KDL REQUIRED), setting the "Orocos-KDL_DIR" option to equal /home/dgooding/cc-dir/share/orocos-kdl and here's the output of hitting configure:
/**
Looking for KDL in: /home/dgooding/cc-dir
Includes in: /usr/local/include;/usr/local/include/eigen2
Compiler flags: -I/usr/local/include;-I/usr/local/include/eigen2
Libraries: orocos-kdl
Libraries in: /usr/local/lib
Linker flags :
Defines:
**/

So, what's happening is the find_package call, even though it's using the orocos-kdl-config.cmake and orocos-kdl.pc in ~/cc-dir (as evidenced by the "Looking for KDL in:" line) which points to stuff in my ~/cc-dir directory, it's finding the host-side versions of Eigen and KDL in /usr/local. I read somewhere that this is because pkgconfig isn't great for cross compiling... but KDL uses pkgconfig...

So, any advice? Has anyone else had success cross compiling KDL, and then using the resulting libraries in a CMake project? Are there any CMake-friendly ways of more-strongly-encouraging the finding of the target versions of Eigen and KDL, instead of the host versions? Is it feasible for KDL to stop using pkgconfig for ease of cross compilation? Any help is appreciated.

--
Dustin Gooding

getting CMake to find (the right) KDL when cross compiling

On Jul 19, 2011, at 5:06 PM, Gooding, Dustin R. (JSC-ER411) wrote:

I'm attempting to build software for VxWorks 6.7. My software has KDL dependencies (and will eventually have Orocos dependencies) and is built with CMake. I've written a toolchain file for CMake to allow easy cross-compiling of CMake-enabled projects. However, the trouble I'm running into is getting my call to find_package(Orocos-KDL REQUIRED) to work.

Here's what I've done so far...

1) Created a toolchain file that enables cross compiling for VxWorks 6.7 on a PPC604 board using the GNU compiler. This sets CMAKE_FIND_ROOT_PATH equal to the target VxWorks directory (as well as the soon to be mentioned environment variable CROSSCOMPILE_DIR).
2) Created a directory ~/cc-dir to store third-party target dependencies (like Eigen and KDL), along with an associated environment variable $CROSSCOMPILE_DIR
3) Cross compiled (ccmake, make and make install) Eigen2 into ~/cc-dir. Cross compilation was accomplished by using the -DCMAKE_TOOLCHAIN_FILE="toolchain.cmake" option for ccmake.
4) Cross compiled KDL into ~/cc-dir. I set the "EIGEN2_INCLUDE_DIR" to point to the target version in ~/cc-dir.
5) Ran ccmake on my project that has a call to find_package(Orocos-KDL REQUIRED), setting the "Orocos-KDL_DIR" option to equal /home/dgooding/cc-dir/share/orocos-kdl and here's the output of hitting configure:
/**
Looking for KDL in: /home/dgooding/cc-dir
Includes in: /usr/local/include;/usr/local/include/eigen2
Compiler flags: -I/usr/local/include;-I/usr/local/include/eigen2
Libraries: orocos-kdl
Libraries in: /usr/local/lib
Linker flags :
Defines:
**/

So, what's happening is the find_package call, even though it's using the orocos-kdl-config.cmake and orocos-kdl.pc in ~/cc-dir (as evidenced by the "Looking for KDL in:" line) which points to stuff in my ~/cc-dir directory, it's finding the host-side versions of Eigen and KDL in /usr/local. I read somewhere that this is because pkgconfig isn't great for cross compiling... but KDL uses pkgconfig...

So, any advice? Has anyone else had success cross compiling KDL, and then using the resulting libraries in a CMake project? Are there any CMake-friendly ways of more-strongly-encouraging the finding of the target versions of Eigen and KDL, instead of the host versions? Is it feasible for KDL to stop using pkgconfig for ease of cross compilation? Any help is appreciated.

--
Dustin Gooding

For what it's worth, I've tried setting ENV{PKG_CONFIG_PATH} to "${ENV{CROSSCOMPILE_DIR}/lib/pkgconfig:$ENV{CROSSCOMPILE_DIR}/share/pkgconfig" in my toolchain file without any luck. Pkgconfig still finds the host orocos-kdl package.

But, on the command line, setting that environment variable works:

/**
dgooding@loki:~$ pkg-config --cflags eigen2
-I/usr/local/include/eigen2
dgooding@loki:~$ PKG_CONFIG_PATH=$CROSSCOMPILE_DIR/lib/pkgconfig:$CROSSCOMPILE_DIR/share/pkgconfig pkg-config --cflags eigen2
-I/home/dgooding/cc-dir/include/eigen2
dgooding@loki:~$ pkg-config --cflags orocos-kdl
-I/usr/local/include -I/usr/local/include/eigen2
dgooding@loki:~$ PKG_CONFIG_PATH=$CROSSCOMPILE_DIR/lib/pkgconfig:$CROSSCOMPILE_DIR/share/pkgconfig pkg-config --cflags orocos-kdl
-I/home/dgooding/cc-dir/include -I/home/dgooding/cc-dir/include/eigen2
**/

I worry that pkg-config is finding the host libraries before I have a chance to change the Orocos-KDL_DIR option, and after I change it to point to the cc-dir location, pkgconfig doesn't bother finding the target version of orocos-kdl.

In fact, that's exactly what was happening... I just modified my main CMakeLists.txt file to find the Orocos-KDL package in the following way and pkg-config works correctly now.

/**
if (CMAKE_CROSSCOMPILING)
set(Orocos-KDL_DIR $ENV{CROSSCOMPILE_DIR}/share/orocos-kdl)
endif (CMAKE_CROSSCOMPILING)
find_package(Orocos-KDL REQUIRED)
**/

So now all I ask is, should this be the way things are?

-dustin

getting CMake to find (the right) KDL when cross compiling

On Wednesday 20 July 2011 16:48:24 Gooding, Dustin R. (JSC-ER411) wrote:
> On Jul 19, 2011, at 5:06 PM, Gooding, Dustin R. (JSC-ER411) wrote:
>
> I'm attempting to build software for VxWorks 6.7. My software has KDL
> dependencies (and will eventually have Orocos dependencies) and is built
> with CMake. I've written a toolchain file for CMake to allow easy
> cross-compiling of CMake-enabled projects. However, the trouble I'm
> running into is getting my call to find_package(Orocos-KDL REQUIRED) to
> work.
>
> Here's what I've done so far...
>
> 1) Created a toolchain file that enables cross compiling for VxWorks 6.7 on
> a PPC604 board using the GNU compiler. This sets CMAKE_FIND_ROOT_PATH
> equal to the target VxWorks directory (as well as the soon to be mentioned
> environment variable CROSSCOMPILE_DIR). 2) Created a directory ~/cc-dir to
> store third-party target dependencies (like Eigen and KDL), along with an
> associated environment variable $CROSSCOMPILE_DIR 3) Cross compiled
> (ccmake, make and make install) Eigen2 into ~/cc-dir. Cross compilation
> was accomplished by using the -DCMAKE_TOOLCHAIN_FILE="toolchain.cmake"
> option for ccmake. 4) Cross compiled KDL into ~/cc-dir. I set the
> "EIGEN2_INCLUDE_DIR" to point to the target version in ~/cc-dir. 5) Ran
> ccmake on my project that has a call to find_package(Orocos-KDL REQUIRED),
> setting the "Orocos-KDL_DIR" option to equal
> /home/dgooding/cc-dir/share/orocos-kdl and here's the output of hitting
> configure: /**
> Looking for KDL in: /home/dgooding/cc-dir
> Includes in: /usr/local/include;/usr/local/include/eigen2
> Compiler flags: -I/usr/local/include;-I/usr/local/include/eigen2
> Libraries: orocos-kdl
> Libraries in: /usr/local/lib
> Linker flags :
> Defines:
> **/
>
> So, what's happening is the find_package call, even though it's using the
> orocos-kdl-config.cmake and orocos-kdl.pc in ~/cc-dir (as evidenced by the
> "Looking for KDL in:" line) which points to stuff in my ~/cc-dir
> directory, it's finding the host-side versions of Eigen and KDL in
> /usr/local. I read somewhere that this is because pkgconfig isn't great
> for cross compiling... but KDL uses pkgconfig...
>
> So, any advice? Has anyone else had success cross compiling KDL, and then
> using the resulting libraries in a CMake project? Are there any
> CMake-friendly ways of more-strongly-encouraging the finding of the target
> versions of Eigen and KDL, instead of the host versions? Is it feasible
> for KDL to stop using pkgconfig for ease of cross compilation? Any help
> is appreciated.
>
> --
> Dustin Gooding
>
>
> For what it's worth, I've tried setting ENV{PKG_CONFIG_PATH} to
> "${ENV{CROSSCOMPILE_DIR}/lib/pkgconfig:$ENV{CROSSCOMPILE_DIR}/share/pkgcon
> fig" in my toolchain file without any luck. Pkgconfig still finds the host
> orocos-kdl package.

There is a typo above: it's $ENV{...} and not ${ENV{...}

>
> But, on the command line, setting that environment variable works:
>
> /**
> dgooding@loki:~$ pkg-config --cflags eigen2
> -I/usr/local/include/eigen2
> dgooding@loki:~$
> PKG_CONFIG_PATH=$CROSSCOMPILE_DIR/lib/pkgconfig:$CROSSCOMPILE_DIR/share/pk
> gconfig pkg-config --cflags eigen2 -I/home/dgooding/cc-dir/include/eigen2
> dgooding@loki:~$ pkg-config --cflags orocos-kdl
> -I/usr/local/include -I/usr/local/include/eigen2
> dgooding@loki:~$
> PKG_CONFIG_PATH=$CROSSCOMPILE_DIR/lib/pkgconfig:$CROSSCOMPILE_DIR/share/pk
> gconfig pkg-config --cflags orocos-kdl -I/home/dgooding/cc-dir/include
> -I/home/dgooding/cc-dir/include/eigen2 **/
>
> I worry that pkg-config is finding the host libraries before I have a
> chance to change the Orocos-KDL_DIR option, and after I change it to point
> to the cc-dir location, pkgconfig doesn't bother finding the target
> version of orocos-kdl.

The Orocos-KDL_DIR is not used by pkg-config afaik, only for finding the .cmake
file.

>
> In fact, that's exactly what was happening... I just modified my main
> CMakeLists.txt file to find the Orocos-KDL package in the following way
> and pkg-config works correctly now.
>
> /**
> if (CMAKE_CROSSCOMPILING)
> set(Orocos-KDL_DIR $ENV{CROSSCOMPILE_DIR}/share/orocos-kdl)
> endif (CMAKE_CROSSCOMPILING)
> find_package(Orocos-KDL REQUIRED)
> **/
>
> So now all I ask is, should this be the way things are?

*normally* setting the PKG_CONFIG_PATH correctly should fix your issues,
although it will always look in the default paths too if it's not found, which
you would like to avoid as much as possible.

That your last fix fixes the issue surprises me a bit, what you set is the
location of the .cmake file, and not the location of the .pc files.

I wonder if the trailing slash in the pkg_config_path in the orocos-kdl-
config.cmake file would be the culprit... you could also modify that file to
instrument it with debug code, printing the PKG_CONFIG_PATH env variable.

Peter