0
$\begingroup$

Rosanswers logo

Hi there,

In a few packages, especially when porting third-party software to catkin, I encounter the problem of auto-generated headers. In a single-package scenario, it is pretty easy to handle, as I just have to play with include_directories() and the matter is settled. As for the install space, an appropriate install() rule easily takes care of it. Things get more complicated when dealing with devel space. For example, I would like my fooConfig.cmake to contain a link to the devel space include folder, that would contain the header generated from a template with configure_file(), for example. The same goes with pkg-config files.

I looked around and could not find any documentation or best practices on the matter. So far, I have tested adding a cmake/foo-extras.cmake.in file like the following:

if(@DEVELSPACE@)
  list(APPEND @PROJECT_NAME@_INCLUDE_DIRS @CATKIN_DEVEL_PREFIX@/include)
endif()

and then in my CMakeLists.txt I have something akin to this:

catkin_package(
  CFG_EXTRAS foo-extras.cmake
)

set(devel_pkg_inc ${CATKIN_DEVEL_PREFIX}/include/${PROJECT_NAME})

configure_file(foo.h.in ${devel_pkg_inc}/foo.h)
install(FILES ${devel_pkg_inc}/foo.h DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})

It does the job for me, but it looks a bit clunky. Is there any catkin-ish way of doing this? Am I missing anything obvious?


Originally posted by po1 on ROS Answers with karma: 411 on 2014-04-17

Post score: 4


Original comments

Comment by demmeln on 2014-04-18:
cc @Dirk Thomas

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

The proposed way is ok. Generating the header into the devel space is exactly what should be done. Also the install rule is necessary - as is.

But you can achieve the same functionality without an extra file. First to make it work for code compiler in your package you need to add the include folders:

# also assuming that you also have static headers in the include folder of your package
include_directories(include ${CATKIN_DEVEL_PREFIX}/include)

You should always only add the include folder (rather then the package specific subfolder in it) and then include your code with the package name as a namespace (e.g. #include <pkgname/myheader.h).

Second to make packages work which depend on yours you have to export both include locations:

catkin_package(INCLUDE_DIRS include ${CATKIN_DEVEL_PREFIX}/include)

For the install case it will work correctly since the include folder in install space will contain your static headers form the package include folder (if you have also installed them) as well as the header installed from the devel space. Again keep in mind that all your headers should be in a subfolder of include and should also be referenced like this in code.


Originally posted by Dirk Thomas with karma: 16276 on 2014-04-18

This answer was ACCEPTED on the original site

Post score: 6


Original comments

Comment by po1 on 2014-04-19:
Thanks! This is exactly what I wanted to know. To be honest, I was looking at INCLUDE_DIRS but was thinking that introducing a devel space path in it might not play nicely with the install space rules. Now I know that it's fine, and getting rid of this -extras.cmake file is a relief.

Comment by po1 on 2014-04-28:
Unfortunately, it did not work: CMake Error at /opt/ros/hydro/share/catkin/cmake/catkin_package.cmake:336 (message): catkin_package() include dir '/Users/paul/test_ws/devel/include' is neither an absolute directory nor exists relative to '/Users/paul/test_ws/src/foo'

Comment by po1 on 2014-05-05:
I had to add this before catkin_package: file(MAKE_DIRECTORY ${CATKIN_DEVEL_PREFIX}/include)

$\endgroup$

Your Answer

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