ROS-CmakeList.txt详解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_23348963/article/details/79770074

代码中包名:test-packagle-name,文件名:test-file-name

cmake_minimum_required(VERSION 2.8.3) # CMake最低版本要求,低于2.8.3构建过程会被终止。 
project(test-package-name)#定义工程名称

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
#找到catkin编译的宏命令和库文件,如果像find_package(catkin REQUIRED COMPONENTS xyz)一样的清单被使用的话,也能找到其他catkin编译的功能包
find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
)

## System dependencies are found with CMake's conventions 
#系统依赖项也能随着CMake的规定被找到
# find_package(Boost REQUIRED COMPONENTS 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
#如果功能包里有一个setup.py,取消这些注释。这个宏可以确保模块和全局脚本声明在其中得到安装,参考http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################
#声明 ROS 的 messages, services 和 actions
#ervice 是同步的通信机制,a 和 b 间通过 sevice 机制通信,假设 a 是客户端访问 b 服务器端,a 远程调用 b 上的某个函数,
#a 程序得等 b 服务器响应后才能作其他的事情(运行其他程序),如果 b 服务器长期无响应,那么 a 啥也别做了,一直等下去吧,无法取消。
#显然效率低下,原因在于 service 时同步通信机制。ros 提供了另外一种通信机制 action,可以在远程调用服务器上某程序后,转而执行其他的程序,
#周期性的获得服务器上的信息,或者取消发送到服务器上的某远程调用,机制灵活,异步通信。

## To declare and build messages, services or actions from within this package, follow these steps:
##想要在功能包中声明和建立习messages, services和actions,就遵循以下步骤:

## * 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, ...).
## *用MSG_DEP_SET对功能包进行相应设置,且功能包的消息类型就是你的messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).

## * In the file package.xml:	在package.xml文件中:
##   * add a build_depend tag for "message_generation"	给"message_generation"增加一个build_depend标签
##   * add a build_depend and a run_depend tag for each package in MSG_DEP_SET	在MSG_DEP_SET里给功能包增加一个build_depend和一个run_depend标签
##   * 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"
##	   如果MSG_DEP_SET不是空的,接下来的依赖就已经被设置了,但是仍然可以做确定性说明: 给"message_runtime"增加一个run_depend标签
## * In this file (CMakeLists.txt):	   在CMakeLists.txt文件中:
##   * add "message_generation" and every package in MSG_DEP_SET to find_package(catkin REQUIRED COMPONENTS ...)	
##     增加"message_generation",而且在每一个功能包里,对MSG_DEP_SET要find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to catkin_package(CATKIN_DEPENDS ...)
##     增加"message_runtime",而且在每一个功能包里,对MSG_DEP_SET要catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed and list every .msg/.srv/.action file to be processed
##     以下add_*_files部分,和下列.msg/.srv/.action文件,每一个都根据需要可以取消注释
##   * uncomment the generate_messages entry below	在generate_messages的入口取消注释
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)	在MSG_DEP_SET的功能包增加generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )

## Generate services in the 'srv' folder
# add_service_files(
#   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	在这里列出的依赖项下,收集增加的messages和services
# generate_messages(
#   DEPENDENCIES
#   std_msgs  # Or other packages containing msgs	或者其他功能包包含的msgs
# )

################################################
## Declare ROS dynamic reconfigure parameters ##
################################################
##声明ROS动态配置参数

## 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"	给"dynamic_reconfigure"增加一个build_depend和一个run_depend标签
## * In this file (CMakeLists.txt):
##   * add "dynamic_reconfigure" to find_package(catkin REQUIRED COMPONENTS ...)	在"dynamic_reconfigure" 增加find_package(catkin REQUIRED COMPONENTS ...)
##   * uncomment the "generate_dynamic_reconfigure_options" section below and list every .cfg file to be processed
##     *取消下面"generate_dynamic_reconfigure_options"部分的注释,而且下面每一个.cfg文件都会被处理,在'cfg'路径收集动态配置参数

## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
#   cfg/DynReconf1.cfg
#   cfg/DynReconf2.cfg
# )

###################################
## catkin specific configuration ##
###################################
## catkin特殊配置

## The catkin_package macro generates cmake config files for your package	 catkin_package宏为你的功能包生成cmake配置文件
## Declare things to be passed to dependent projects	声明的参数要给依赖工程文件
## INCLUDE_DIRS: uncomment this if your package contains header files	INCLUDE_DIRS:如果你的功能包有头文件,就取消它的注释
## LIBRARIES: libraries you create in this project that dependent projects also need	 LIBRARIES: 在这个项目中生成库,还需要依赖项目
## CATKIN_DEPENDS: catkin_packages dependent projects also need		CATKIN_DEPENDS: catkin_packages依赖工程也需要
## DEPENDS: system dependencies of this project that dependent projects also need	DEPENDS: 系统依赖关系的这个项目也需要依赖项目

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES test-package-name
#  CATKIN_DEPENDS roscpp rospy
#  DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files. Your package locations should be listed before other locations
## 指定额外的头文件的位置,你的包的位置应该是其他地方之前列出
include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/test-package-name.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
## 给库增加cmake目标依赖,作为一个例子,在库之前生成代码或者从message生成,动态配置中生成
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Declare a C++ executable		声明一个C++可执行
## With catkin_make all packages are built within a single CMake context	通过catkin_make,所有的软件包都在一个CMake上下文中构建
## The recommended prefix ensures that target names across packages don't collide  	推荐的前缀可确保跨包的目标名称不会相互冲突
add_executable(test-file-name 
  src/test-file-name.cpp
)

## Rename C++ executable without prefix  重命名 更简洁的rosrun指令
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")

## Add cmake target dependencies of the executable same as for the library above	给可执行增加cmake目标依赖,对上述提到的库也是一样的操作
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Specify libraries to link a library or executable target against
target_link_libraries(test-file-name
  ${catkin_LIBRARIES}
)

#############
## Install ##
#############
##安装

# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
# 所有安装目标有应该使用catkin DESTINATION变量 参考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
## 为安装标记可执行脚本Python etc.对比于setup.py,你能选择下面的
# install(PROGRAMS
#   scripts/my_python_script
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark executables and/or libraries for installation   为安装标记可执行文件和/或库文件
# install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_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	为安装标记cpp头文件
# 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.)	为安装标记其他文件(e.g. launch and bag files, etc.)
# install(FILES
#   # myfile1
#   # myfile2
#   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )

#############
## Testing ##
#############

## Add gtest based cpp test target and link libraries	给cpp测试目标和链接库增加gtest
# catkin_add_gtest(${PROJECT_NAME}-test test/test-package-name.cpp)
# if(TARGET ${PROJECT_NAME}-test)
#   target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()

## Add folders to be run by python nosetests	在Python节点测试上增加文件
# catkin_add_nosetests(test)

猜你喜欢

转载自blog.csdn.net/qq_23348963/article/details/79770074