Failing to add optional dependencies!

asked 2016-11-23 04:13:33 -0500

beginner gravatar image

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??

edit retag flag offensive close merge delete

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?

mgruhler gravatar image mgruhler  ( 2016-11-23 04:20:54 -0500 )edit

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

gvdhoorn gravatar image gvdhoorn  ( 2016-11-23 04:33:05 -0500 )edit

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

gvdhoorn gravatar image gvdhoorn  ( 2016-11-23 04:34:24 -0500 )edit

@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?

beginner gravatar image beginner  ( 2016-11-23 06:17:32 -0500 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2016-11-23 06:37:12 -0500 )edit