Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Just to clarify in the beginning that I have no idea about Swift - so all of the following is just me extrapolating from how CMake works for C / C++.

The exported target will use the property INTERFACE_INCLUDE_DIRECTORIES when downstream packages try to find headers (in C / C++). Since the build directory can potentially be deleted after package rclswift_common has been built and installed the property shouldn't point to a build directory.

For C++ projects you commonly need some include directories to build a packages and other include directories for downstream packages to use the installed headers, e.g. https://github.com/ros2/rcl/blob/2a4d2f40fe8c5d6d0f33655d4c4f077ce8793825/rcl/CMakeLists.txt#L68-L70 (you will find the same pattern in almost all ROS core packages in Foxy and newer):

target_include_directories( your_library_target PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" "$<INSTALL_INTERFACE:include>")

The $<BUILD_INTERFACE:...`` could also or additionally point to something underCMAKE_CURRENT_BINARY_DIR`.

If you need to declare include directories for downstream packages you also need to install some files which you expect to be used by downstream packages.

For C++ that would be the header files. Maybe for Swift you have to install swift/Interfaces.swift? Assuming you would install that file to include you need to declare the INSTALL_INTERFACE on the target like this:

target_include_directories( RclSwiftCommon PUBLIC "$<INSTALL_INTERFACE:include>")

Just to clarify in the beginning that I have no idea about Swift - so all of the following is just me extrapolating from how CMake works for C / C++.

The exported target will use the property INTERFACE_INCLUDE_DIRECTORIES when downstream packages try to find headers (in C / C++). Since the build directory can potentially be deleted after package rclswift_common has been built and installed the property shouldn't point to a build directory.

For C++ projects you commonly need some include directories to build a packages and other include directories for downstream packages to use the installed headers, e.g. https://github.com/ros2/rcl/blob/2a4d2f40fe8c5d6d0f33655d4c4f077ce8793825/rcl/CMakeLists.txt#L68-L70 (you will find the same pattern in almost all ROS core packages in Foxy and newer):

target_include_directories(
  your_library_target PUBLIC
  "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
  "$<INSTALL_INTERFACE:include>")

The $<BUILD_INTERFACE:...`` $<BUILD_INTERFACE:... could also or additionally point to something underCMAKE_CURRENT_BINARY_DIR`.under CMAKE_CURRENT_BINARY_DIR.

If you need to declare include directories for downstream packages you also need to install some files which you expect to be used by downstream packages.

For C++ that would be the header files. Maybe for Swift you have to install swift/Interfaces.swift? Assuming you would install that file to include you need to declare the INSTALL_INTERFACE on the target like this:

target_include_directories(
  RclSwiftCommon PUBLIC
  "$<INSTALL_INTERFACE:include>")