参考
前言
CMakeLists
综述
总体结构(严格按照顺序)
find_package()思想
catkin_package()思想
消息,服务和动作
一系列注意事项(懒得翻译了)
单元测试
安装(略)
Package.xml
使用XML语言设置依赖(略)
专题:消息,服务,重配置的构造描述文件
实例:解决zsDoor模块缺失问题
查看stereo_wall_detection的CMakeLists.txt
TOC
参考
Catkin Documentation
ROS Wiki
**推荐一本书:《深入理解软件构建系统》
前言
- 是基于CMake,使用一系列CMake 宏制作而成的ROS构造系统
CMakeLists
综述
- 此文件是CMake 构造系统的输入文件,构造描述文件记录了代码如何构建以及如何安装,catkin 构建系统基于CMakeLists,但是也添加了额外的不多的约束
总体结构(严格按照顺序)
- Required CMake Version (cmake_minimum_required)
- Package Name (project())
- Find other CMake/Catkin packages needed for build (find_package())
- Message/Service/Action Generators(add_message_files(),add_service_files(),add_action_files())
- Invoke message/service/action generation (generate_messages())
- Specify package build info export (catkin_package())
- Libraries/Executables to build (add_library()/add_executable()/target_link_libraries())
- Tests to build (catkin_add_gtest())
- Install rules (install())
find_package()思想
- CMake中的find模块的作用在于自动寻找已经存在的软件组件,这里的组件概念对应于ROS中的包的概念。如
find_package(catkin REQUIRED COMPONENTS nodelet)
。意思是,寻找catkin库中的nodelet组件,在这个语句中不能添加运行时依赖
- 问题来了,为什么Catkin是一个大库,ROS包是一个组件呢?其实官方文档说了,你可以可以这么写
find_package(catkin REQUIRED);find_package(nodelet REQUIRED)
,因为使用catkin编译,必须包含catkin包,然后你再包含nodelet包,但是这样也太不方便了。所以原因就是要方便,当然也不是方便这么一点点,还有关于环境变量。
- Catkin packages are not really components of catkin. Rather the components feature of CMake was utilized in the design of catkin to save you significant typing time.
- For catkin packages,if you find_package them as components of catkin,this is advantageous as a single set of environment variables is created with the catkin_ prefix.
- 注意:boost不是catkin组件哦
catkin_package()思想
- 是一个CMake 宏,用来明确catkin构建系统信息,这些信息用来生成pkg-config和CMake文件
-
This function must be called before declaring any targets with add_library() or add_executable(). The function has 5 optional arguments:
```
INCLUDE_DIRS - The exported include paths (i.e. cflags) for the package
LIBRARIES - The exported libraries from the project
CATKIN_DEPENDS - Other catkin projects that this project depends on
DEPENDS - Non-catkin CMake projects that this project depends on
CFG_EXTRAS - Additional configuration options
#### 关于标的的构建选项
* 自定义输出目录。
> ```
set_target_properties(python_module_library PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION})
- 包含目录和库,创建可执行文件和库文件
完全是CMake知识
消息,服务和动作
- 一句话,先add_service_files(),再generate_messgaes(),可谓是一键创造消息服务动作
Messages (.msg),services (.srv),and actions (.action) files in ROS require a special preprocessor build step before being built and used by ROS packages. The point of these macros is to generate programming language-specific files so that one can utilize messages,services,and actions in their programming language of choice. The build system will generate bindings using all available generators (e.g. gencpp,genpy,genlisp,etc).
一系列注意事项(懒得翻译了)
- These macros must come BEFORE the catkin_package() macro in order for generation to work correctly.
- Your catkin_package() macro must have a CATKIN_DEPENDS dependency on message_runtime.
- You must use find_package() for the package message_generation,either alone or as a component of catkin
- Your package.xml file must contain a build dependency on message_generation and a runtime dependency on message_runtime. This is not necessary if the dependencies are pulled in transitively from other packages.
- If you have a package which builds messages and/or services as well as executables that use them,you need to create an explicit dependency on the automatically-generated message target so that they are built in the correct order. (some_target is the name of the target set by add_executable()):
单元测试
catkin_add_gtest(myUnitTest test/utest.cpp)
安装(略)
Package.xml
使用XML语言设置依赖(略)
- 实际上就是使用标记语言说明本包的基本情况
- 设置本包为Metapackages
<export>
<metapackage />
</export>
cmake_minimum_required(VERSION 2.8.3)
project(<PACKAGE_NAME>)
find_package(catkin REQUIRED)
catkin_metapackage()
专题:消息,服务,重配置的构造描述文件
- 只有一个包或节点是消息,服务,动作的提供者时,在构造描述文件中才需要添加相应的描述语句,如果是接受者,那么不需要提供。
请比较rosaria和rosaria_client构造描述文件的区别
- 当需要使用到新的消息和服务类型时,才需要再构造描述文件中添加add语句
- 通过包含其他含有std_msgs的包,如rosaria,也可以间接包含std_msgs
- 嘛的,官方例程建立消息和服务都还要
add_dependencies()
,但是rosaria中没有这么多废话
- 消息和服务的构造描述文件
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation)
catkin_package( ... CATKIN_DEPENDS message_runtime ... ...)
generate_messages(
# DEPENDENCIES
# std_msgs
)
<build_depend>message_generation</build_depend>
<run_depend>message_runtime</run_depend>
- 为什么有
add_msgs()
,add_srvs()
,而只有generate_messages()
,没有generate_srvs()
等?因为服务和参数重配置本质上都是基于msg消息机制,多说一句,消息机制是建立在XMLRPC远程过程调用机制上的,进而建立在TCP/IP网络协议上
《UNIX网络编程:进程间通信》
重配置的构造描述文件
实例:解决zsDoor模块缺失问题
查看stereo_wall_detection的CMakeLists.txt