ROS CMakeLists.txt 中的 catkin_package 与 find_package

在 ROS 功能包的 CMakeLists.txt 文件中有这样两个宏,catkin_package 与 find_package。例如它们具有以下内容:

find_package(catkin REQUIRED COMPONENTS
    roscpp
    actionlib
    std_msgs
    message_generation
    actionlib_msgs
)

catkin_package(CATKIN_DEPENDS std_msgs actionlib actionlib_msgs roscpp)

根据教程的解释,这两个宏似乎都在描述一种依赖关系,那么这两个宏的区别是什么?

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

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

find_package 是 cmake 中常见的宏,用于加载 catkin 宏和指定对其他 ROS 功能包的依赖关系。

catkin_package 宏是 catkin 的宏之一,声明要传递给依赖项目的内容,生成 cmake 配置文件。也就是说它对依赖于此功能包的其他功能包来说具有重要作用。

本文的例子中,构建此功能包需要依赖于

  • roscpp
  • actionlib
  • std_msgs
  • message_generation
  • actionlib_msgs

而依赖于此功能包的功能包同时需要具有以下依赖

  • std_msgs
  • actionlib
  • actionlib_msgs
  • roscpp

关于 catkin_package 宏的 DEPENDSCATKIN_DEPENDS 选项的详细理解可以参考这篇回答。

你可能感兴趣的:(ROS程序设计)