Ask Your Question
0

How to export CMake settings (CMAKE_MODULE_PATH) to other packages?

asked 2019-11-02 18:02:50 -0600

tyler-picknik gravatar image

updated 2019-11-02 18:59:19 -0600

gvdhoorn gravatar image

I want to add a .cmake file to my project which contains many multiple catkin projects. Normally with cmake the way I would do this is set the CMAKE_MODULE_PATH variable to point to a cmake directory and then I could use the cmake command include to include a script from that directory. Is there a good way to go about doing that in a catkin project so that other catkin projects that depend on my project could also use this cmake script?

The context is I am trying to find the right way to go about adding a .cmake file to a project like moveit which contains many different catkin projects and I'd like to only add my file in one place and ideally have it affect all the dependent catkin projects.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-11-02 18:55:46 -0600

gvdhoorn gravatar image

updated 2019-11-02 18:58:17 -0600

You can do this with a CFG_EXTRAS file (which is essentially a snippet of CMake) and exporting the location to it in your catkin_package(.. CFG_EXTRAS ..) call in the CMakeLists.txt of the package from which you'd like to export this.

See #q173947 for a Q&A where this is done for exporting compiler flags from a package, and #q93266 for an example where this is used to export a non-standard include path.

You should be able to append to CMAKE_MODULE_PATH in the same way, as the extras-file contains just regular CMake. Be sure to specify the correct path to CMAKE_MODULE_PATH: it would need to be a path relative to the package that you're calling catkin_package(.. CFG_EXTRAS ..) in and also make sure to install(..) the extras-file as otherwise consumers of your package will not be able to find it when using an install space.

As the paths to your package may be different in the devel and install space, you may have to use some templating to get the correct paths generated for you. gencpp does something similar (from here):

@[if DEVELSPACE]@
  ...
@[else]@
  ...
@[end if]@

See also the catkin documentation: Extracted CMake API reference for more information on this.

edit flag offensive delete link more

Comments

And a final comment: while this can certainly be a valid approach to export certain information from CMake packages (it's essentially just CMake), be aware that it's easy to "overdo" this. That could result in creating tightly-coupled packages, which would be undesirable.

gvdhoorn gravatar imagegvdhoorn ( 2019-11-02 18:57:46 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-11-02 18:02:50 -0600

Seen: 31 times

Last updated: Nov 02