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)
————————————————
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章