ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
There is no planned support for optional dependencies. Here is some related reading:
2 | No.2 Revision |
There is no planned support for optional dependencies. Here is some related reading:
Edit: Adding example of looking for dependencies conditionally in CMake
First let me explain the find_package(catkin REQUIRED COMPONENTS ...)
mechanism.
This:
find_package(catkin REQUIRED COMPONENTS foo bar baz)
message("Libraries: ${catkin_LIBRARIES}")
Is the same as:
find_package(foo REQUIRED)
find_package(bar REQUIRED)
find_package(baz REQUIRED)
message("Libraries: ${foo_LIBRARIES};${bar_LIBRARIES};${baz_LIBRARIES}")
So any variable which starts with catkin_
will be the aggregate of the items you passed as COMPONENTS
.
Therefore, you can find package things one at a time and act accordingly:
find_package(catkin REQUIRED COMPONENTS required_dep1 required_dep2)
set(MY_SRCS src/main.cpp ...)
set(MY_LINK_INCLUDE_DIRS ${catkin_INCLUDE_DIRS})
set(MY_LINK_LIBRARIES ${catkin_LIBRARIES})
find_package(optional_dep1)
if(optional_dep1_FOUND)
list(APPEND MY_SRCS src/optional_dep1_code.cpp)
list(APPEND MY_LINK_INCLUDE_DIRS ${optional_dep1_INCLUDE_DIRS})
list(APPEND MY_LINK_LIBRARIES ${optional_dep1_LIBRARIES})
# Anything else you need to do to enable use of the optional dep, like add definitions
add_definitions("-DUSE_OPTIONAL_DEP1=1")
endif()
include_directories(include ${MY_LINK_INCLUDE_DIRS})
catkin_package()
add_executable(my_exec ${MY_SRCS})
target_link_libraries(my_exec ${MY_LINK_LIBRARIES})
You can imagine how you could conditionally do just about anything based on the result of optional_dep1_FOUND
.