ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Optional ROS package (and catkin) dependencies

asked 2015-09-15 16:37:12 -0500

peci1 gravatar image

Is there (going to be) support for specifying optional dependencies for ROS packages in both package.xml and CMakeLists.txt?

Rationale: I do some optional resource generation during the build process (optional robot parts), and then I want to merge all these generated resources in a common resource. So this common resource needs to be built only after the resource generation for the parts has finished. But I still need to preserve the optionality of the various parts.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-09-15 17:31:43 -0500

William gravatar image

updated 2015-09-15 19:55:57 -0500

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.


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 ...)


    list(APPEND MY_SRCS src/optional_dep1_code.cpp)
    list(APPEND MY_LINK_LIBRARIES ${optional_dep1_LIBRARIES})
    # Anything else you need to do to enable use of the optional dep, like add definitions

include_directories(include ${MY_LINK_INCLUDE_DIRS})


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.

edit flag offensive delete link more


That's a pity. Imagine the combinatorial explosion of "workaround" packages which should model all combinations of optional equipement on our robot (at least 5 pieces -> 32 packages)

peci1 gravatar image peci1  ( 2015-09-15 18:04:35 -0500 )edit

There is nothing to stop you from writing your CMakeLists.txt such that it tries to find additional deps which are not listed in the package.xml and use them if found. They just won't be installed before building on the build farm. But at least from source you can install them and use them.

William gravatar image William  ( 2015-09-15 18:45:48 -0500 )edit

If you want to include the "optional" deps on the build farm but make them optional when built from source, you can put everything in the package.xml and write your CMakeLists.txt such that it doesn't fail if a dependency is not found. The build tools will not have a problem, but others might.

William gravatar image William  ( 2015-09-15 18:47:39 -0500 )edit

For instance, rosinstall_generator and rosdep will try to fulfill all dependencies in the package.xml and it would be up to the user to narrow down that list when building from source.

William gravatar image William  ( 2015-09-15 18:48:14 -0500 )edit

If you want to use the "recommended" pattern that .deb files allow for, you can do what I suggest here: and patch the release repository.

William gravatar image William  ( 2015-09-15 18:49:47 -0500 )edit

The solution with custom CMakeLists.txt rules seems to be clean and I like it. However, I'm no CMake geek, so could you please point me to the right set of commands? Something like find_package(catkin QUIET COMPONENTS optional_dep); if (optional_dep_FOUND) add_dependencies(...); endif() ?

peci1 gravatar image peci1  ( 2015-09-15 19:17:52 -0500 )edit

You'd need to find_package(...) each optional item independently, I'll update my answer with an example.

William gravatar image William  ( 2015-09-15 19:41:56 -0500 )edit

Thanks, I tested this solution and it works well. The only thing is I use find_package(optional_dep QUIET) so that CMake doesn't issue a warning when the package is not found.

peci1 gravatar image peci1  ( 2015-09-21 06:10:46 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-09-15 16:37:12 -0500

Seen: 1,846 times

Last updated: Sep 15 '15