ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

catkin_find functionality at build time

asked 2013-11-26 04:52:46 -0600

Currently, I have a package with a CMake invocation like so:

  execute_process(COMMAND catkin_find other_package file/in/package --first-only
    OUTPUT_VARIABLE LOCATION_OF_FILE)

This works, but with one important caveat: the catkin_find call fails if the workspace wasn't sourced prior to build. What this means is that setting up a workspace with this package can be an awkward dance of creating and building the empty workspace, sourcing it, and then re-building.

My hypothesis is that there's a better way involving find_package(), but none of the variables which are created by find_package point to the share path. Is there some other catkin macro which fills this niche, or another CMake technique which should be used?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-11-26 05:47:22 -0600

Dirk Thomas gravatar image

You can not rely in sourcing the generated setup file of the workspace you are going to build. Simply because it is not available on the first build.

You should turn around the way the discovery works. The other_package should expose a variable to a base path or the specific file in its CMake extra file. Then your package can find_package() the other package and use its variable.

One example where this is done would be gencpp (https://github.com/ros/gencpp/blob/groovy-devel/cmake/gencpp-extras.cmake.em). It exposes the path to a script in GENCPP_BIN as well as the template directory in GENCPP_TEMPLATE_DIR. Since the relative location are different when being build and after installation the CMake extra file sets them in two different ways.

edit flag offensive delete link more

Comments

Yes, I assumed I was doing it not-quite-right, for exactly that reason. Thanks for the pointers.

mikepurvis gravatar image mikepurvis  ( 2013-11-26 06:25:01 -0600 )edit

What is the step which transforms `gencpp-extras.cmake.em` to `gencpp-extras.cmake`? Does the catkin_package macro just handle that automagically when you specify CFG_EXTRAS gencpp-extras.cmake?

mikepurvis gravatar image mikepurvis  ( 2013-11-26 06:33:30 -0600 )edit

Yes, it looks for a couple of file extensions and optionally also for different variants for devel and install space. See http://docs.ros.org/api/catkin/html/dev_guide/generated_cmake_api.html#catkin-package

Dirk Thomas gravatar image Dirk Thomas  ( 2013-11-26 06:37:07 -0600 )edit

Very clever. Thanks again.

mikepurvis gravatar image mikepurvis  ( 2013-11-26 07:17:39 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-11-26 04:52:46 -0600

Seen: 660 times

Last updated: Nov 26 '13