Robotics StackExchange | Archived questions

Failing to add optional dependencies!

Hello,

I have 3 ros packages: A, B and C

B depends on A (as a required dependency) and C depends on A & B (but both as optional dependencies)

I want to make the building of C always work, whether A or B both exist, both do not exist, or one of them exists without the other.

In package C, I have written the CMakeLists.txt to first search for A, and if found also search for B:

find_package(catkin COMPONENTS
  A
)
if (${A_FOUND})
  find_package(catkin COMPONENTS
    B
  )
  if (${B_FOUND})
    add_definitions(-DFLAG)
  endif(${B_FOUND})
endif(${A_FOUND})

In package.xml, I had to add B as a dependency for it to look for A and B at all

What I get is that C is building in all cases except when B exists but A doesn't

Please any explanation or help??

Asked by beginner on 2016-11-23 05:13:33 UTC

Comments

I am not sure why you want to do this, but: If B depends on A, B requires A and thus B should not work/exist if A is not there. Is this the problem?

Asked by mgruhler on 2016-11-23 05:20:54 UTC

Note that -- in CMake, not just Catkin -- multiple find_package(..)s for the same package will not work as you expect: depending on how the find script is written, they might return early (if they don't consider the COMPONENTS arg), or overwrite each other. I would not use ..

Asked by gvdhoorn on 2016-11-23 05:33:05 UTC

.. find_package(catkin COMPONENTS ..), but just do a find_package(A), find_package(B), etc. The only thing the find_package(catkin COMPONENTS ..) does for you is gather all include/lib flags for you and let you do ${catkin_LIBRARIES} instead of having to list everything individually.

Asked by gvdhoorn on 2016-11-23 05:34:24 UTC

@mig: If A is not there, B should not build. That's fine... My issue is that C is not building too!

@gvdhoorn: even with find_package(A) and find_package(B), it also fails... If calling find_package(...) several times is not the way to do this, do you suggest something else?

Asked by beginner on 2016-11-23 07:17:32 UTC

it also fails

what fails?

find_package(..) is fine, you just don't want to call the same find/config script multiple times, or be very careful about it.

Asked by gvdhoorn on 2016-11-23 07:37:12 UTC

Answers