ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
21

What is the purpose of CATKIN_DEPENDS?

asked 2013-03-18 20:05:42 -0500

dejanpan gravatar image

updated 2021-12-29 23:08:44 -0500

lucasw gravatar image

While looking at this CMakeLists.txt:

https://kforge.ros.org/geometry/geome...https://github.com/ros/geometry/blob/...

I was wondering the exact meaning of the CATKIN_DEPENDS option of the catkin_package(...) macro was?

I would expect to see there the same packages as listed in the find_package(...) macro but this does not seem to be the case.

b) Do we still need to copy python msg and srv manually in the install target? Are there any other files or directories that require this special treatment?

Using ROS Groovy and Ubuntu 12.04.

Cheers, D.

edit retag flag offensive close merge delete

Comments

For part b, you should probably make a separate question. But while you are could you explain what you mean? Are you asking if you need to manually install the .msg and .srv files? or the resulting generated code?

William gravatar image William  ( 2013-03-19 09:01:57 -0500 )edit

@William: maybe not even worth a separate question. Looking at the last 4 lines of this: https://kforge.ros.org/geometry/geometry/file/2eee66fd724e/tf/CMakeLists.txt I was wondering if we still need to manually copy srv and msg dirs into PYTHON_INSTALL_DIR? It was a total random discover for me...

dejanpan gravatar image dejanpan  ( 2013-03-19 11:46:52 -0500 )edit

Looking at that issue it looks like that problem was fixed, and those last few lines are no longer needed.

William gravatar image William  ( 2013-03-19 11:49:47 -0500 )edit

That is how it looked to me too though I do not understand much of the code. But now I verified it and the dirs still do not get installed for my packages. How do I know if that patch was released?

dejanpan gravatar image dejanpan  ( 2013-03-19 11:57:16 -0500 )edit

The reference patch to genmsg has been released long time before groovy was release. I just checked out the geometry repository, removed the manual install lines and ran "catkin_make install" and the files are getting installed correctly.

Dirk Thomas gravatar image Dirk Thomas  ( 2013-03-19 12:07:01 -0500 )edit

1 Answer

Sort by » oldest newest most voted
44

answered 2013-03-19 08:37:29 -0500

William gravatar image

updated 2013-03-19 09:00:14 -0500

To answer part A of your question...

DEPENDS and CATKIN_DEPENDS are how you can tell catkin which of your package's dependencies should be passed along to packages which find_package(...) your package.

For example, lets say you find_package(Boost REQUIRED) and in one of your installed headers you #include <boost/function.hpp>. In order for a dependent package to build and link your header they need to have Boost's include directory in the their include path and they need to link against Boost's libraries. They should get that dependency from you since you expose it in your header, i.e. they should not have to find_package(Boost REQUIRED) just because they are building against your package, and do not otherwise use Boost.

The fact that your package depends on Boost is an implementation detail. Therefore when some find_package(...)'s your package they should get the dependency on Boost "for free". The way this works is that you put DEPENDS Boost in your catkin_package(...) call. Internally, catkin will find_package(Boost) and add ${Boost_LIBRARIES} to ${your_pkg_LIBRARIES} and add ${Boost_INCLUDE_DIRS} to ${your_pkg_INCLUDE_DIRS}.

I should note that catkin will take the exact thing you give it and try to find_package(...) it and then try to use the _LIBRARIES and _INCLUDE_DIRS variables for that package. This assumption about find_package(...) layout does not always hold, as CMake does not enforce this. For example, when find_package(...)ing Python: find_package(PythonLibs REQUIRED) results in variables like PYTHON_INCLUDE_PATH, and find_package(OpenGL REQUIRED) results in OPENGL_INCLUDE_DIR. Aside from case of the variable prefixes, the actual prefixes differ (PythonLibs -> PYTHON), and the suffixes are non-standard (PYTHON_INCLUDE_PATH and OPENGL_INCLUDE_DIR vs *_INCLUDE_DIRS). In this case you need to pass the include dirs variable to catkin_package(...) explicitly using the INCLUDE_DIRS option and the libraries using the LIBRARIES option.

The CATKIN_DEPENDS option is exactly like that DEPENDS option, but you must put catkin packages only in that list. The benefit for sorting your catkin depends into a separate option is that catkin can do additional checks and warn you of potentially incorrect practices.

Finally, a simple example CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(foo)

find_package(Boost REQUIRED
  COMPONENTS
  system
  thread
)

find_package(PythonLibs REQUIRED)
find_package(OpenGL REQUIRED)

find_package(catkin REQUIRED
  COMPONENTS
  rosconsole
  roscpp
)

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  ${OPENGL_INCLUDE_DIR}
  ${PYTHON_INCLUDE_PATH}
)

catkin_package(
  INCLUDE_DIRS include ${OPENGL_INCLUDE_DIR}
  LIBRARIES foo ${OPENGL_LIBRARIES}
  CATKIN_DEPENDS roscpp
  DEPENDS Boost
)

...

In this example you can see that I find_package(Boost...) and pass it along in the DEPENDS section because it generates compliant CMake variables. I find_package(PythonLibs...) and use it internally but do not pass it along as it is not in any of my exposed headers. I find_package(OpenGL...) but since it does not make compliant CMake variables I pass it along explicitly to INCLUDE_DIRS and LIBRARIES. Finally I find_package(catkin...rosconsole roscpp), I use both internally, but maybe I only use rosconsole in my .c* files and therefore I do not need to pass it along, so in the CATKIN_DEPENDS variable I just put roscpp.

One final example, if a package ... (more)

edit flag offensive delete link more

Comments

1

Great answer, thx a lot Will.

dejanpan gravatar image dejanpan  ( 2013-03-19 11:32:47 -0500 )edit
5

This seems to be a common misunderstanding surrounding catkin and chaining dependencies. I might post it in the wiki, or rework it as a tutorial.

William gravatar image William  ( 2013-03-19 11:46:00 -0500 )edit

This is very helpful. However, regarding your example,why INCLUDE_DIRS does not have ${PYTHON_INCLUDE_PATH}, CATKIN_DEPENDS does not have rosconsole? And why DEPENDS does not have OpenGL or PythonLibs?

Javier V. Gómez gravatar image Javier V. Gómez  ( 2016-01-26 10:25:31 -0500 )edit

Thank you so much for the in depth explanation! Just one quick question, the example assumes OpenGl is used in header files, right?

kotoko gravatar image kotoko  ( 2016-08-09 04:41:05 -0500 )edit

It definitely should be in the CMakeLists wiki. This answer is a wiki itself. Thanks a lot!

OMC gravatar image OMC  ( 2017-01-16 09:30:00 -0500 )edit

I'm still not convinced. You do find_package for Boost because your header refer to it. But the library foo will have a target_link_library for Boost later on, otherwise it would not compile. There should be no need to do the same for a package which links against foo.

mcamurri gravatar image mcamurri  ( 2019-01-10 05:57:22 -0500 )edit

Or are you just saying that CATKIN_DEPENDS and DEPENDS should contain the only libraries which appear in headers which are not included and compiled inside the package itself (e.g. a header only library)? Would I need to specify any dependency if there are no libraries declared?

mcamurri gravatar image mcamurri  ( 2019-01-10 05:59:47 -0500 )edit
1

If I have a Python-only package without generated messages, should I add something to CATKIN_DEPENDS? I know practically that I can leave it empty, but the question is if it is correct also "theoretically". Also, do Python-only packages only need <exec_depend> tags in package.xml? Overall, I'm missing some good documentation for Python-only packages on the Wiki. E.g. here the wiki suggests to add <build_depend>python-numpy, but is it really needed?

peci1 gravatar image peci1  ( 2019-03-08 13:33:55 -0500 )edit

Question Tools

6 followers

Stats

Asked: 2013-03-18 20:05:42 -0500

Seen: 16,917 times

Last updated: Dec 29 '21