So catkin makes the assumption that you install all of your headers into the root of the include folder, i.e. <prefix>/include
, when generating your CMake config file and pkg-config files. So your resulting pkg_name_INCLUDE_DIRS
will by default be <prefix>/include
. In this instance you want to have that also include <prefix>/include/pkg_name
as well.
There are two ways to accomplish this. The first is simple, but will break if you relocate the installed package.
Simply pass this to your catkin_package(...)
call:
catkin_package(
INCLUDE_DIRS include include/tinyxml ${CMAKE_INSTALL_PREFIX}/include/tinyxml
...
)
The second way uses the pkg_name_DIR
variable which allows you to make a relocatable addition to your _INCLUDE_DIRS
. The problem is that this variable is not available in your CMakeLists.txt
, but is available when your package is find_package
'ed, so you have to use a CMake extras file (which gets evaluated at find_package
time) in order to do this correctly.
Reference: http://docs.ros.org/api/catkin/html/dev_guide/generated_cmake_api.html#catkin_package (CFG_EXTRAS
)
In order to do this, what you will want to do is to is create a file in your project cmake/<pkg_name>-extras.cmake.in
where you replace <pkg_name>
with your package name. In that file you should do something like this:
list(APPEND @PROJECT_NAME@_INCLUDE_DIRS "${@PROJECT_NAME@_DIR}/../../../@CATKIN_GLOBAL_INCLUDE_DESTINATION@/tinyxml")
The elements inside of @..@
will get templated at build time of your package. You will need to tell catkin to do this templating for you:
catkin_package(
...
CFG_EXTRAS <pkg_name>-extras.cmake
)
Note that you do not include the .in
extension here.
Originally posted by William with karma: 17335 on 2013-10-22
This answer was ACCEPTED on the original site
Post score: 8
Original comments
Comment by William on 2013-10-22:
@Dirk Thomas please review this answer
Comment by Dirk Thomas on 2013-10-22:
Looks all good to me. Great answer.
Comment by hawesie on 2014-10-28:
When doing this for a package to be released, should the <pkg_name>-extras.cmake file be installed? I'm guessing yes.
Comment by Dirk Thomas on 2014-10-28:
When you use CFG_EXTRAS the file gets installed automatically.
Comment by hawesie on 2014-10-28:
Awesome, thanks.