ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
The strategy proposed by William works well with catkin_make_isolated
and catkin build
, where multiple CMake projects exist, and the dependency is built before it is required. It however breaks under catkin_make
, where there is a single CMake project and the dependency has not yet been built when it is required (hence find_library
fails). For completeness, I have put together a a slightly modified version that is compatible with both single- and multi-CMake projects:
CMakeLists.txt
catkin_package(
...
LIBRARIES # NOTE: Not specified here, but in extras file
CFG_EXTRAS foo-extras.cmake
)
foo-extras.cmake.in
find_library(@PROJECT_NAME@_LIBRARY
NAMES @PROJECT_NAME@
PATHS "${@PROJECT_NAME@_DIR}/../../../@CATKIN_GLOBAL_LIB_DESTINATION@/funky/path/to/foo"
NO_DEFAULT_PATH)
if(@PROJECT_NAME@_LIBRARY)
# Multiple CMake projects case (i.e. 'catkin build'):
# - The target has already been built when its dependencies require it
# - Specify full path to found library
list(APPEND @PROJECT_NAME@_LIBRARIES ${@PROJECT_NAME@_LIBRARY})
else()
# Single CMake project case (i.e. 'catkin_make'):
# - The target has not been built when its dependencies require it
# - Specify target name only
list(APPEND @PROJECT_NAME@_LIBRARIES @PROJECT_NAME@)
endif()