INSTALL_DIRS not working as expected when using install

asked 2019-10-21 13:10:47 -0600

iliis gravatar image

updated 2019-10-21 13:14:14 -0600

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.cmakein this case (the actual code that handles this is in https://github.com/ros/catkin/blob/0d...)

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.

(A very related question: https://stackoverflow.com/questions/5...)

edit retag flag offensive close merge delete

Comments

I believe this is a duplicate of #q93266.

If it is, I would recommend implementing the "second way" @William suggests.

But I would like to know why the other option of having custom include paths isn't fully supported by catkin?

I believe it is, and #q93266 should show you how.

gvdhoorn gravatar imagegvdhoorn ( 2019-10-21 14:32:25 -0600 )edit

Thanks for the quick answer! The "first way" fails in catkin_package.cmake:299, because at the time catkin_package() is executed, the files haven't been install()ed to the CMAKE_INSTALL_PREFIX yet and thus don't exist when catkin_package() check if the path is valid. The "second way" should work but is a bit complicated for something that catkin_package() already supports directlyfor devel and even has code to handle it for install. But instead of adding the additional paths it just discards them and replaces everything with "include". See https://github.com/ros/catkin/blob/0d... When I read that code it looks like support for just writing catkin_package(INSTALL_DIRS foo) and have it work both in devel and in install space was intentionally removed/not put in.

iliis gravatar imageiliis ( 2019-10-23 08:38:36 -0600 )edit