0
$\begingroup$

Rosanswers logo

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?


Originally posted by mikepurvis on ROS Answers with karma: 1153 on 2013-11-26

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Dirk Thomas with karma: 16276 on 2013-11-26

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by mikepurvis on 2013-11-26:
Yes, I assumed I was doing it not-quite-right, for exactly that reason. Thanks for the pointers.

Comment by mikepurvis on 2013-11-26:
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?

Comment by Dirk Thomas on 2013-11-26:
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

Comment by mikepurvis on 2013-11-26:
Very clever. Thanks again.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.