Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You must install the header file.h from the package called my_package. You can do that by using this CMake snippet in the CMakeLists.txt file in the my_package package:

## Install project namespaced headers
install(DIRECTORY include/${PROJECT_NAME}/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
  PATTERN ".svn" EXCLUDE)

Note that this assumes your headers, in this case file.h, are in your package under the include/<project name> folder, which for my_package would be include/my_package/file.h. This is a good practice, since all header files for all packages can be installed to the same place and you wouldn't want your file.h and another package's to collide. This also means that the main.cpp in the_package should do #include <my_package/file.h> instead of what you listed above.

Then the the_package package must:

  • have a build_depend on my_package in its package.xml
  • have called find_package(my_package REQUIRED) in its CMakeLists.txt
  • add my_package's exported include directories by doing include_directories(${my_package_INCLUDE_DIRS})

The include_directories(...) CMake call needs to come after the find_package(...) call.

Each of those points above ensures that: - my_package is built before the_package - my_package exists and can be found through CMake - the location of the headers exported by my_package is passed to the compiler for the libraries and executables in the_package

Note that you can also do find_package(catkin REQUIRED COMPONENTS my_package ...) instead of find_package(my_package REQUIRED), where the ... maybe other packages that the_package depends on. Doing this would allow you to use the catkin_ prefixed CMake variables, so you would do include_directories(${catkin_INCLUDE_DIRS}) rather than include_directories(${my_package_INCLUDE_DIRS}).

You must install the header file.h from the package called my_package. You can do that by using this CMake snippet in the CMakeLists.txt file in the my_package package:

## Install project namespaced headers
install(DIRECTORY include/${PROJECT_NAME}/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
  PATTERN ".svn" EXCLUDE)

Note that this assumes your headers, in this case file.h, are in your package under the include/<project name> folder, which for my_package would be include/my_package/file.h. This is a good practice, since all header files for all packages can be installed to the same place and you wouldn't want your file.h and another package's to collide. This also means that the main.cpp in the_package should do #include <my_package/file.h> instead of what you listed above.

Then the the_package package must:

  • have a build_depend on my_package in its package.xml
  • have called find_package(my_package REQUIRED) in its CMakeLists.txt
  • add my_package's exported include directories by doing include_directories(${my_package_INCLUDE_DIRS})

The include_directories(...) CMake call needs to come after the find_package(...) call.

Each of those points above ensures that: - that:

  • my_package is built before the_package -
  • my_package exists and can be found through CMake - CMake
  • the location of the headers exported by my_package is passed to the compiler for the libraries and executables in the_package

Note that you can also do find_package(catkin REQUIRED COMPONENTS my_package ...) instead of find_package(my_package REQUIRED), where the ... maybe other packages that the_package depends on. Doing this would allow you to use the catkin_ prefixed CMake variables, so you would do include_directories(${catkin_INCLUDE_DIRS}) rather than include_directories(${my_package_INCLUDE_DIRS}).