Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The way to export include directories in catkin is with catkin_package(INCLUDE_DIRS ...) (not as mentioned in the question with INCLUDE).

These paths can be absolute (https://github.com/ros/catkin/blob/1b2e47643d782e147c17ecb8134a534a3f3630ef/cmake/catkin_package.cmake#L414) (which is usually not recommended) as well as relative (https://github.com/ros/catkin/blob/1b2e47643d782e147c17ecb8134a534a3f3630ef/cmake/catkin_package.cmake#L417) to the installation prefix path. And it is possible to pass any custom value there, e.g. catkin_package(INCLUDE_DIRS foo)if you want <CMAKE_INSTALL_PREFIX>/foo to end up in the include dirs list. There is no need to use a custom CMake extras file for this.

Regarding your three options I would say none is the way to go:

  1. As you already stated is undesirable for possible clashes with other packages.

  2. As you already stated a CMake config file should not directly manipulate the build configuration. Also this would implicitly clash with other packages if multiple packages add paths which contain the same relative headers.

  3. Setting the package specific subfolder as an include directory defeats the separation (same as 2.). Header files of multiple packages with the same relative paths still collide.

Therefore you should:

  • install header files to a package specific subfolder (commonly the name of the subfolder has the same name as the package).

  • only export the include folder as the include directory which requires all headers to be included with the package specific subfolder: package_name/my_header.h

The way to export include directories in catkin is with catkin_package(INCLUDE_DIRS ...) (not as mentioned in the question with INCLUDE).

These paths can be absolute (https://github.com/ros/catkin/blob/1b2e47643d782e147c17ecb8134a534a3f3630ef/cmake/catkin_package.cmake#L414) (which is usually not recommended) as well as relative (https://github.com/ros/catkin/blob/1b2e47643d782e147c17ecb8134a534a3f3630ef/cmake/catkin_package.cmake#L417) to the (https://github.com/ros/catkin/blob/1b2e47643d782e147c17ecb8134a534a3f3630ef/cmake/catkin_package.cmake#L417).


Updated block: For every relative include directory it is being assumed that the headers will be installed into the FHS compliant location <CMAKE_INSTALL_PREFIX>/include. A value other then include will only affect the devel space but not the install space. After installation prefix path. And it is possible to pass any custom value there, e.g. catkin_package(INCLUDE_DIRS foo)if you the header files need to be in the path under include to use this. For your use case where you don't want <CMAKE_INSTALL_PREFIX>/foo to end up in the include dirs list. There is no need to update the include directives you actually have to use a custom CMake extras file for this.

config file.


Regarding your three options I would say none is the way to go:

  1. As you already stated is undesirable for possible clashes with other packages.

  2. As you already stated a CMake config file should not directly manipulate the build configuration. Also this would implicitly clash with other packages if multiple packages add paths which contain the same relative headers.

  3. Setting the package specific subfolder as an include directory defeats the separation (same as 2.). Header files of multiple packages with the same relative paths still collide.

Therefore you should:

  • install header files to a package specific subfolder (commonly the name of the subfolder has the same name as the package).

  • only export the include folder as the include directory which requires all headers to be included with the package specific subfolder: package_name/my_header.h