ROS功能包中CMakeLists.txt的说明(ROS入门学习笔记三)

         ROS的构建系统默认使用CMake(Cross Platform Make),其构建环境在功能包目录中的CMakeLists.txt文件中描述。在ROS中,CMake被修改为适合于ROS的“catkin” 构建系统。

结合一个CMakeLists.txt实例进行如下介绍:

cmake _ minimum _ required ( VERSION 2 . 8 . 3 ) ///操作系统中安装cmake的最低版本
project ( my _ first _ ros _ pkg )                      ///指定功能包的名称
## 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     ///find_package项是进行构建所需的组件包。

///目前,roscpp和std_msgs被添加为依赖包。如果此处没有输入功能包名称,则在构建时会向用户报错。换句话说,这是让用户先创建依赖包的选项。

roscpp

std _ msgs

)
## System dependencies are found with CMake's conventions

# find _ package ( Boost REQUIRED COMPONENTS system )   ///使用ROS以外的功能包时使用的方法。

///例如,使用Boost时,必须安装system功能包。功能如前面的说明,是让用户先创建依赖功能包的选项。

## Uncomment this if the package has a setup . py . This macro ensures
## modules and global scripts declared therein get installed
## See http :// ros . org / doc / api / catkin / html / user _ guide / setup _ dot _ py . html
# catkin _ python _ setup ()

///catkin_python_setup( )选项是在使用Python,也就是使用rospy时的配置选项。其功能是调用Python安装过程setup.py。
################################################
## Declare ROS messages , services and actions ##
################################################
## To declare and build messages , services or actions from within this
## package , follow these steps :
## * Let MSG _ DEP _ SET be the set of packages whose message types you use in
## your messages / services / actions ( e . g . std _ msgs , actionlib _ msgs , ...).
## * In the file package . xml :
## * add a build _ depend tag for "message _ generation"
## * add a build _ depend and a run _ depend tag for each package in MSG _ DEP _ SET
## * If MSG _ DEP _ SET isn't empty the following dependency has been pulled in
##
##
but can be declared for certainty nonetheless :
* add a run _ depend tag for "message _ runtime"
## * In this file ( CMakeLists . txt ):
## * add "message _ generation" and every package in MSG _ DEP _ SET to
##
find _ package ( catkin REQUIRED COMPONENTS ...)
## * add "message _ runtime" and every package in MSG _ DEP _ SET to
## catkin _ package ( CATKIN _ DEPENDS ...)
## and list every . msg /. srv /. action file to be processed
## * uncomment the add _*_ files sections below as needed
## * uncomment the generate _ messages entry below
## * add every package in MSG _ DEP _ SET to generate _ messages ( DEPENDENCIES ...)
## Generate messages in the 'msg' folder
# add _ message _ files ( ///add_message_files是添加消息文件的选项。FILES将引用当前功能包目录的msg目录中的*.msg文件,自动生成一个头文件(*.h)。
# FILES
# Message1 . msg
# Message2 . msg
# )
## Generate services in the 'srv' folder

# add _ service _ files (

///add_service_files是添加要使用的服务文件的选项。使用FILES会引用功能包目录中的srv目录中的*.srv文件。在这个例子中,用户可以选择使用服务文件Service1.srv和Service2.srv。

# FILES
# Service1 . srv
# Service2 . srv
# )
## Generate actions in the 'action' folder
# add _ action _ files (
# FILES
# Action1 . action
# Action2 . action
# )
## Generate added messages and services with any dependencies listed here
# generate _ messages ( ///generate_messages是设置依赖的消息的选项。此示例是将DEPENDENCIES选项设置为使用std_msgs消息包。
# DEPENDENCIES
# std _ msgs
# )
################################################
## Declare ROS dynamic reconfigure parameters ##
################################################
## To declare and build dynamic reconfigure parameters within this

## package , follow these steps :

## * In the file package . xml :
## * add a build _ depend and a run _ depend tag for "dynamic _ reconfigure"
## * In this file ( CMakeLists . txt ):
## * add "dynamic _ reconfigure" to
## find _ package ( catkin REQUIRED COMPONENTS ...)
## and list every . cfg file to be processed
## * uncomment the "generate _ dynamic _ reconfigure _ options" section below
## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate _ dynamic _ reconfigure _ options ( ///generate_dynamic_reconfigure_options是使用dynamic_reconfigure时加载要引用的配置文件的设置。
# cfg / DynReconf1 . cfg
# cfg / DynReconf2 . cfg
# )
###################################
## catkin specific configuration ##
###################################
## 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 ( ///catkin 构建选项
# INCLUDE _ DIRS include ///INCLUDE_DIRS表示将使用INCLUDE_DIRS后面的内部目录include的头文件。
# LIBRARIES my _ first _ ros _ pkg ///LIBRARIES表示将使用随后而来的功能包的库。
# CATKIN _ DEPENDS roscpp std _ msgs ///CATKIN_DEPENDS后面指定如roscpp或std_msgs等依赖包。
# DEPENDS system _ lib ///DEPENDS是一个描述系统依赖包的设置。
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
# include _ directories ( include )

include _ directories ( ///include_directories是可以指定包含目录的选项。目前设定为${catkin_INCLUDE_DIRS},这意味着将引用每个功能包中的include目录中的头文件。

///当用户想指定一个额外的include目录时,写在${catkin_INCLUDE_DIRS}的下一行即可。

${ catkin _ INCLUDE _ DIRS }

)

## Declare a C ++ library

# add _ library ( my _ first _ ros _ pkg ///add_library声明构建之后需要创建的库。

///以下是引用位于my_first_ros_pkg功能包的src目录中的my_first_ros_pkg.cpp文件来创建my_first_ros_pkg库的命令。

# src /${ PROJECT _ NAME }/ my _ first _ ros _ pkg . cpp
# )
## Add cmake target dependencies of the library
## as an example , code may need to be generated before libraries

## either from message generation or dynamic reconfigure

 

///add_dependencies是在构建该库和可执行文件之前,如果有需要预先生成的有依赖性的消息或dynamic_reconfigure,则要先执行。

///以下内容是优先生成my_first_ros_pkg库依赖的消息及dynamic reconfigure的设置。
# add _ dependencies ( my _ first _ ros _ pkg ${${ PROJECT _ NAME }_ EXPORTED _ TARGETS } ${ catkin _ EXPORTED _ TARGETS })

## Declare a C ++ executable

 

///add_executable是对于构建之后要创建的可执行文件的选项。以下内容是引用src/my_first_ros_pkg_node.cpp文件生成my_first_ros_pkg_node可执行文件。

///如果有多个要引用的*.cpp文件,将其写入my_first_ros_pkg_node.cpp之后。如果要创建两个以上的可执行文件,需追加add_executable项目。

# add _ executable ( my _ first _ ros _ pkg _ node src / my _ first _ ros _ pkg _ node . cpp )
## Add cmake target dependencies of the executable

## same as for the library above

 

///如前面描述的add_dependencies一样,add_dependencies是一个首选项,是在构建库和可执行文件之前创建依赖消息和dynamic reconfigure的设置。

///下面介绍名为my_first_ros_pkg_node的可执行文件的依赖关系,而不是上面提到的库。在建立可执行文件之前,先创建消息文件的情况下会经常用到。

# add _ dependencies ( my _ first _ ros _ pkg _ node ${${ PROJECT _ NAME }_ EXPORTED _ TARGETS }

${ catkin _ EXPORTED _ TARGETS })

///target_link_libraries是在创建特定的可执行文件之前将库和可执行文件进行链接的选项。

## Specify libraries to link a library or executable target against
# target _ link _ libraries ( my _ first _ ros _ pkg _ node
# ${ catkin _ LIBRARIES }

# )

 

///以下时提供了创建官方发行版ROS功能包时使用的Install项目

#############
## Install ##
#############
# all install targets should use catkin DESTINATION variables
# See http :// ros . org / doc / api / catkin / html / adv _ user _ guide / variables . html
## Mark executable scripts ( Python etc .) for installation
## in contrast to setup . py , you can choose the destination
# install ( PROGRAMS
# scripts / my _ python _ script
# DESTINATION ${ CATKIN _ PACKAGE _ BIN _ DESTINATION }
# )
## Mark executables and / or libraries for installation

# install ( TARGETS my _ first _ ros _ pkg my _ first _ ros _ pkg _ node

# ARCHIVE DESTINATION ${ CATKIN _ PACKAGE _ LIB _ DESTINATION }
# LIBRARY DESTINATION ${ CATKIN _ PACKAGE _ LIB _ DESTINATION }
# RUNTIME DESTINATION ${ CATKIN _ PACKAGE _ BIN _ DESTINATION }
# )
## Mark cpp header files for installation
# install ( DIRECTORY include /${ PROJECT _ NAME }/
# DESTINATION ${ CATKIN _ PACKAGE _ INCLUDE _ DESTINATION }
# FILES _ MATCHING PATTERN " *. h"
# PATTERN " . svn" EXCLUDE
# )
## Mark other files for installation ( e . g . launch and bag files , etc .)
# install ( FILES
# # myfile1
# # myfile2
# DESTINATION ${ CATKIN _ PACKAGE _ SHARE _ DESTINATION }

# )

///以下时用于单元测试的项目
Testing项目。

#############
## Testing ##
#############
## Add gtest based cpp test target and link libraries
# catkin _ add _ gtest (${ PROJECT _ NAME }- test test / test _ my _ first _ ros _ pkg . cpp )
# if ( TARGET ${ PROJECT _ NAME }- test )
# target _ link _ libraries (${ PROJECT _ NAME }- test ${ PROJECT _ NAME })
# endif ()
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)

 

  • 1
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值