9

in the file CMakelists.txt I see find_packages and catkin_package:

find_package(catkin REQUIRED COMPONENTS roscpp rospy
image_transport std_msgs message_generation sensor_msgs
geometry_msgs )

catkin_package( CATKIN_DEPENDS message_runtime std_msgs sensor_msgs geometry_msgs )

What is the difference between those two things?

I tried to read about each thing in the tutorial, but it is not clear enough.

nbro
  • 15,395
  • 32
  • 113
  • 196
user5547561
  • 157
  • 1
  • 2
  • 8
  • Also check out https://answers.ros.org/question/261002/catkin_packagecatkin_depends-vs-find_packagecatkin-required-components/ – MorganStark47 Jul 19 '21 at 13:29

2 Answers2

6

The answer is basically given by the auto-generated comments in the CMakeLists.txt:

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS ...

and

## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(...

The find_package command is common cmake and is needed to load the catkin macros and specify dependencies to other ROS packages.

The catkin_package command is one of these catkin macros. It is responsible for the ROS-specific configuration of the package. So this is the essential part that differentiates a ROS package from a common cmake project. I don't know details but I guess that it is, for example, responsible for setting the correct build paths of the catkin workspace.
The parameters given here (i.e. dependencies) are important when other ROS packages depend on this one.

luator
  • 4,769
  • 3
  • 30
  • 51
  • 1
    How are these parameters important when other ROS packages depend on this one? Why do the same packages need to be in both `find_package(...)` and `catkin_package(...)`? – Jin Sep 03 '18 at 21:47
  • @Jin My understanding is the following: The packages listed in `find_package` are listing dependencies that are needed to build the package A itself (i.e. all nodes and libraries it provides). Packages listed in `catkin_package` are dependencies needed to build another package B which uses a library of A. It is not the same as not all build dependencies of A are necessarily required by the library it provides (there could also be nodes in the package, for which no dependencies need to be listed in `catkin_package`). I hope that make it clear? – luator Sep 04 '18 at 07:11
  • So as a short summary: Dependencies only need to be listed in `catkin_package` if they are dependencies of a library that is used by other packages. – luator Sep 04 '18 at 07:14
0

Found another answer here:

find_package() finds dependencies for this package.

catkin_package(CATKIN_DEPENDS) declares dependencies for packages that depend on this package.

So in your example, any package depending on your package needs the following dependencies:

  • message_runtime
  • std_msgs
  • sensor_msgs
  • geometry_msgs
Community
  • 1
  • 1
Jin
  • 778
  • 1
  • 8
  • 23