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/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...)
I believe this is a duplicate of #q93266.
If it is, I would recommend implementing the "second way" @William suggests.
I believe it is, and #q93266 should show you how.
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 beeninstall()
ed to theCMAKE_INSTALL_PREFIX
yet and thus don't exist whencatkin_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 writingcatkin_package(INSTALL_DIRS foo)
and have it work both in devel and in install space was intentionally removed/not put in.