If you have a line like this in your cmake:
find_package(Boost REQUIRED thread)
and later on you are creating and exporting a library:
add_library(my_library ...)
...
install(TARGETS my_library ...)
ament_export_dependencies(Boost ...)
And you've noticed that you get cmake errors complaining about missing libraries when you try to depend on your my_library
in another package (or perhaps a user submits a bug about this).
Create a file named ConfigExtras.cmake
and copy the find_package
line into it for boost:
find_package(Boost REQUIRED thread)
In your CMakeLists.txt
file where the find_package
line was for Boost replace it with this to include the code from your new file:
include(ConfigExtras.cmake)
Then at the bottom of your CMakeLists.txt
file add an argument to your call to ament_package
like this:
ament_package(CONFIG_EXTRAS ConfigExtras.cmake)
Here is the ros-answers post that directed me towards this solution: https://answers.ros.org/question/331089/ament_export_dependenciesboost-not-working/?answer=332460#post-id-332460
Here is the documentation on the ament_package argument: https://github.com/ament/ament_cmake/blob/95cab1de1cd6bd7caad34d0122e11b2e86310ee2/ament_cmake_core/cmake/core/ament_package.cmake#L24-L32
Here is the PR where I did this in MoveIt2: moveit/moveit2#372
The current implementation of ament_export_dependencies
can't handle this nicely for you.
In the future it would be nice if this was handled by whatever ament_cmake
function sets up the exporting of dependencies of your package.
If you feel equiped to solve this, here is where you might submit a PR.
If you do please let me know so I can test it and stop telling people to do it this way.
Link to Robotics Stack Exchange version of the ros-answers question: https://robotics.stackexchange.com/questions/93010/ament-export-dependenciesboost-not-working
Link to open issue regarding this problem: ament/ament_cmake#456