Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

INSTALL_DIRS not working as expected when using install

Suppose I have a package that has some public headers in a non-standard include folder (for example because foo here is some kind of external library in a submodule):

somepackage
├── CMakeLists.txt
├── foo
│   └── bar
│       └── somelib.h
└── package.xml

Which get included in other packages using

#include <bar/somelib.h>

I therefore specify the folder foo as an exported include dir in somepackage/CMakeLists.txt:

catkin_package(INSTALL_DIRS foo)

Which works fine with the normal devel workspace. Now I wan't to use the catkin config --install option instead. So I add an install() call to somepackage/CMakeLists.txt:

install(
    DIRECTORY foo
    DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
)

Note that without a trailing slash (foo/) this will install the header to $PREFIX/include/foo/bar/somelib.h, e.g. my_workspace/install/foo/bar/somelib.h. Users of somepackage now have to add $PREFIX/include/foo/ to their include path. Which should automatically happen because they wrote

include_directories(${catkin_INCLUDE_DIRS})

in their CMakeLists.txt and depend on somepackage.

Unfortunately, it doesn't work when using catkin config --install: Catkin only exports include in somepackageConfig.cmake in this case (the actual code that handles this is in https://github.com/ros/catkin/blob/0d245cb80fd62053ba6bcc33b888e97c1588188e/cmake/catkin_package.cmake#L421-L429)

Now, I could of course install it directly to $PREFIX/include/bar/somelib.h and be done with it. But I would like to know why the other option of having custom include paths isn't fully supported by catkin? It's not unusual for a normal (non-catkin) cmake library to provide a ${library_INCLUDE_DIRS} variable. Looking at the code of catkin_package() it seems there seems to be some rationale behind it.

INSTALL_DIRS not working as expected when using install

Suppose I have a package that has some public headers in a non-standard include folder (for example because foo here is some kind of external library in a submodule):

somepackage
├── CMakeLists.txt
├── foo
│   └── bar
│       └── somelib.h
└── package.xml

Which get included in other packages using

#include <bar/somelib.h>

I therefore specify the folder foo as an exported include dir in somepackage/CMakeLists.txt:

catkin_package(INSTALL_DIRS foo)

Which works fine with the normal devel workspace. Now I wan't to use the catkin config --install option instead. So I add an install() call to somepackage/CMakeLists.txt:

install(
    DIRECTORY foo
    DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
)

Note that without a trailing slash (foo/) this will install the header to $PREFIX/include/foo/bar/somelib.h, e.g. my_workspace/install/foo/bar/somelib.h. Users of somepackage now have to add $PREFIX/include/foo/ to their include path. Which should automatically happen because they wrote

include_directories(${catkin_INCLUDE_DIRS})

in their CMakeLists.txt and depend on somepackage.

Unfortunately, it doesn't work when using catkin config --install: Catkin only exports include in somepackageConfig.cmake in this case (the actual code that handles this is in https://github.com/ros/catkin/blob/0d245cb80fd62053ba6bcc33b888e97c1588188e/cmake/catkin_package.cmake#L421-L429)

Now, I could of course install it directly to $PREFIX/include/bar/somelib.h and be done with it. But I would like to know why the other option of having custom include paths isn't fully supported by catkin? It's not unusual for a normal (non-catkin) cmake library to provide a ${library_INCLUDE_DIRS} variable. Looking at the code of catkin_package() it seems there seems to be some rationale behind it. it.

(A very related question: https://stackoverflow.com/questions/50009126/catkin-ros-how-to-specify-include-path-correctly-when-using-submodules)