ROS入门之Cmakelist说明

2023-05-16

Cmakelist

http://wiki.ros.org/catkin/CMakeLists.txt

1 Overall Structure and Ordering

Your CMakeLists.txt file MUST follow this format otherwise your packages will not build correctly. The order in the configuration DOES count. 加*号不在这里详细说明。

  1. *Required CMake Version (cmake_minimum_required)

  2. *Package Name (project())

  3. Find other CMake/Catkin packages needed for build (find_package())

  4. Enable Python module support (catkin_python_setup())

  5. Message/Service/Action Generators (add_message_files(), add_service_files(), add_action_files())

  6. Invoke message/service/action generation (generate_messages())  (generate_messages这个包在find_package中找到)

  7. Specify package build info export (catkin_package()) 指明目标文件的输出位置以及所依赖的包(Cmake与其他非编译包)

  8. Libraries/Executables to build (add_library()/add_executable()/target_link_libraries())

  9. *Tests to build (catkin_add_gtest())    :Unit Tests,a catkin-specific macro for handling gtest-based unit tests

  10. *Install rules (install())                         :Specifying Installable Targets

2 Finding Dependent CMake Packages

Find_package的作用:我们需要指定用来编译我们项目的编译工具(即Cmake Package)。通过find_package会自动找到的编译工具包(即Cmake Package)并为工具包生成Cmake的环境变量。这些环境变量说明了包的输出头文件、源文件、所依赖的库的路径。

We need to then specify which other CMake packages that need to be found to build our project using the CMake find_package function. There is always at least one dependency on catkin:

find_package(catkin REQUIRED)

If your project depends on other wet packages, they are automatically turned into components (in terms of CMake) of catkin. Instead of using find_package on those packages, if you specify them as components, it will make life easier. For example, if you use the package nodelet.

find_package(catkin REQUIRED COMPONENTS nodelet)

NB: You should only find_package components for which you want build flags. You should not add runtime dependencies

If a package is found by CMake through find_package, it results in the creation of several CMake environment variables that give information about the found package. These environment variables can be utilized later in the CMake script. The environment variables describe where the packages exported header files are, where source files are, what libraries the package depends on, and the paths of those libraries.

3 catkin_package()

catkin_package根据find_package中找到的包来编译。因此后者是搜寻定位编译工具包的过程,前者是利用包、指明包该如何编译的过程,并且前者的包除了编译工具包还有其他依赖包(项目)。

catkin_package() is a catkin-provided CMake macro. This is required to specify catkin-specific information to the build system which in turn is used to generate pkg-config and CMake files.

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(Cmake的依赖项)

  • DEPENDS - Non-catkin CMake projects that this project depends on. (项目的依赖项(非Cmake依赖项,因为再上一个argument已经包含了Catkin depend。))

  • CFG_EXTRAS - Additional configuration options

Full macro documentation can be found here.

As an example:

catkin_package(
   INCLUDE_DIRS include
   LIBRARIES ${PROJECT_NAME}
   CATKIN_DEPENDS roscpp nodelet
   DEPENDS eigen opencv)

This indicates that the folder "include" within the package folder is where exported headers go. The CMake environment variable ${PROJECT_NAME} evaluates to whatever you passed to the project() function earlier, in this case it will be "robot_brain". "roscpp" + "nodelet" are packages that need to be present to build/run this package, and "eigen" + "opencv" are system dependencies that need to be present to build/run this package.

4  Specifying Build Targets

两种编译目标文件:执行文件和库文件

Build targets can take many forms, but usually they represent one of two possibilties:

  • Executable Target - programs we can run
  • Library Target - libraries that canf be used by executable targets at build and/or runtime

4.1 Target Naming

无论在构建或安装的文件夹中,生成的目标都必须是唯一的。

It is very important to note that the names of build targets in catkin must be unique regardless of the folders they are built/installed to. This is a requirement of CMake. However, unique names of targets are only necessary internally to CMake. One can have a target renamed to something else using the set_target_properties() function:

Example:

set_target_properties(rviz_image_view
                      PROPERTIES OUTPUT_NAME image_view
                      PREFIX "")

This will change the name of the target rviz_image_view to image_view in the build and install outputs.

4.2 Include Paths and Library Paths

在指定编译目标之前,需要指定用哪些资源(包括头文件和库)的路径,来编译目标文件。可看做是Catkin_package的补充。

Prior to specifying targets, you need to specify where resources can be found for said targets, specifically header files and libraries:

  • Include Paths - Where can header files be found for the code (most common in C/C++) being built
  • Library Paths - Where are libraries located that executable target build against?
  • include_directories(<dir1>, <dir2>, ..., <dirN>)

  • link_directories(<dir1>, <dir2>, ..., <dirN>)

  1. include_directories():

    The argument to include_directories should be the *_INCLUDE_DIRS variables generated by your find_package calls and any additional directories that need to be included. If you are using catkin and Boost, your include_directories() call should look like:(_INCLUDE_DIRS由find_package生成,因此在这里可以很方便地包含所有编译工具包的资源(头文件和库))

    include_directories(include ${Boost_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})
  2. link_directories():

The CMake link_directories() function can be used to add additional library paths, however, this is not recommended. All catkin and CMake packages automatically have their link information added when they are find_packaged.

4.3 Executable Targets

指定所需生成的目标执行文件

To specify an executable target that must be built, we must use the add_executable() CMake function.

add_executable(myProgram src/main.cpp src/some_file.cpp src/another_file.cpp)

This will build a target executable called myProgram which is built from 3 source files: src/main.cpp, src/some_file.cpp and src/another_file.cpp.

所编译好的可执行文件在workspace/devel/lib/pkg 中

4.4 Library Targets

指定所需生成的目标库文件

The add_library() CMake function is used to specify libraries to build. By default catkin builds shared libraries.

add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS})

4.5 target_link_libraries

指定生成的目标执行文件所需的动态链接库文件 .so

Use the target_link_libraries() function to specify which libraries an executable target links against. This is done typically after an add_executable() call. Add ${catkin_LIBRARIES} if ros is not found.

Syntax:

target_link_libraries(<executableTargetName>, <lib1>, <lib2>, ... <libN>)

Example:(下面的so就是动态链接库)

add_executable(foo src/foo.cpp)
add_library(moo src/moo.cpp)
target_link_libraries(foo moo)  -- This links foo against libmoo.so

or:

add_executable(foo src/foo.cpp)
target_link_libraries(foo ${catkin_LIBRARIES})  省略了add_library(moo src/moo.cpp)

Note that there is no need to use link_directories() in most use cases as that information is automatically pulled in via find_package().

5 Messages, Services, and Action Targets

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.(这些macros通过生成msg、srv、action的相关编程语言文件来给编译应用这三者) The build system will generate bindings using all available generators (e.g. gencpp, genpy, genlisp, etc).

There are three macros provided to handle messages, services, and actions respectively:

  • add_message_files

  • add_service_files

  • add_action_files

These macros must then be followed by a call to the macro that invokes generation:

 generate_messages() (括号中添加msg、srv、action所需要的依赖)

5.1 Important Prerequisites/Constraints

  • These macros must come BEFORE the catkin_package() macro in order for generation to work correctly.

          在宏catkin_package利用外加的massage/service/action之前,首先添加这些相关文件。

 find_package(catkin REQUIRED COMPONENTS ...)
 add_message_files(...)
 add_service_files(...)
 add_action_files(...)
 generate_messages(...)
 catkin_package(...)
 ...
  • You must use find_package() for the package message_generation, either alone or as a component of catkin:

find_package(catkin REQUIRED COMPONENTS message_generation)
  • Your catkin_package() macro must have a CATKIN_DEPENDS dependency on message_runtime.

catkin_package(
 ...
 CATKIN_DEPENDS message_runtime ...
 ...)

message_runtime 来自包message_generation

  • 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 target which (even transitively) depends on some other target that needs messages/services/actions to be built, you need to add an explicit dependency on target catkin_EXPORTED_TARGETS, so that they are built in the correct order. This case applies almost always, unless your package really doesn't use any part of ROS. Unfortunately, this dependency cannot be automatically propagated. (some_target is the name of the target set by add_executable()):

 

      dd_dependencies(some_target ${catkin_EXPORTED_TARGETS})
  • If you have a package which builds messages and/or services as well as executables that use these, 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()):

  • 如果在编译包或者执行文件时,需要用到msg和srv,就要显示调用由message_generation自动生成的message target依赖项${${PROJECT_NAME}_EXPORTED_TARGETS}。

      add_dependencies(some_target ${${PROJECT_NAME}_EXPORTED_TARGETS})

(其中,${PROJECT_NAME}是目标包的项目名称,在CMakelist中的前面已声明)

  • If you your package satisfies both of the above conditions, you need to add both dependencies, i.e.:

  •  

      add_dependencies(some_target ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

具体例子可到官网查看

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ROS入门之Cmakelist说明 的相关文章

  • 分布式之数据库和缓存双写一致性方案解析

    本文转自博客园 作者 xff1a 孤独烟 原文链接 xff1a https www cnblogs com rjzheng p 9041659 html 为什么写这篇文章 首先 xff0c 缓存由于其高并发和高性能的特性 xff0c 已经在
  • TVM在Windows10下编译安装

    本教程记录了Windows端安装tvm的过程 xff0c 欢迎交流 教程参考 TVM Windows下全功能编译方法 xff1a 从入门到劝退 https blog csdn net znsoft article details 11503
  • V4L2视频驱动框架---v4l2_device管理模块简述

    v4l2框架由4个主要的部分 数据结构 组成 xff1a v4l2 devices 包括v4l2 subdev xff1a v4l2 device管理所有的设备 media device xff1a meida device框架管理运行时的
  • Pixhawk uORB通信

    Pixhawk 飞控 系统是基于ARM的四轴以上飞行器的飞行控制器 xff0c 它的前身是PX4 IMU xff0c Pixhawk 把之前的IMU进行了完整的重构 xff0c 最新版本是2 4 3 而对应的Pixhawk 1 x版本与2
  • 深入了解C++linux工程师的技术需求,为你以后的职业发展定方向

    一 C 43 43 服务器程序员 xff08 流媒体后台 xff0c 游戏后台 xff0c 高性能服务器后台 xff09 1 精通C 43 43 xff0c STL xff0c Linux等 xff0c 熟悉设计模式 xff1b 2 熟练掌
  • C/C++ Linux后台服务器开发高级架构师学习知识点路线总结(2021架构师篇完整版)

    C C 43 43 Linux后台服务器开发高级架构师学习知识点路线总结 xff08 2021架构师篇完整版 xff09 前言 xff1a 小编之前有跟大家分享过一篇架构师体系知识点总结的文章 xff0c 今天在原来的基础上有所改变更新 x
  • (音视频开发)WebRTC进阶流媒体服务器开发-多人互动架构

    一 xff1a 多人互动架构方案 xff08 一 xff09 WebRTC回顾 xff0c 两层含义 xff1a 1 WebRTC是google开源的流媒体客户端 xff0c 可以进行实时通讯 xff0c 主要应用于浏览器之间进行实时通讯
  • Linux C/C++后台开发高级架构师进阶指南-剑指腾讯T9

    C 43 43 后台开发是一个庞杂的技术栈 xff0c 因为没有统一的开发框架并且应用行业非常广泛 所有涉猎广泛 xff0c 这里就把C C 43 43 43 43 后台开发的技术点进行整理总结 xff0c 看完以后 xff0c 不会让你失
  • 如何让shell脚本变成可执行文件

    导读在本教程中介绍创建bash脚本并使用chmod命令使脚本可执行 xff0c 无需脚本前面加上sh或bash命令就可以运行它 创建脚本文件 第一步是使用以下命令创建一个扩展名为 sh的新文件 xff1a root 64 localhost
  • Fast-RTPS

    Fast RTPS是eprosima对于RTPS的C 43 43 实现 xff0c 是一个免费开源软件 xff0c 遵循Apache License 2 0 Fast RTPS现在被称为Fast DDS xff0c 作为ROS2的默认中间件
  • 如何使你的直流电机闭环?(PID讲解)

    前言 xff1a 看了看很多大佬写的PID讲解很全面也很复杂 xff0c 实在是不适合很多萌新入坑 xff0c 所以想按自己的理解写一篇通俗易懂的PID算法讲解 一 xff1a PID的基本定义 PID xff0c 就是 比例 xff08
  • Linux内核深度解析之中断、异常和系统调用——系统调用

    系统调用 系统调用是内核给用户程序提供的编程接口 用户程序调用系统调用 xff0c 通常使用glibc库针对单个系统调用封装的函数 如果glibc库没有针对某个系统调用封装的函数 xff0c 用户程序可以使用通用的封装函数syscall x
  • 面试题(嵌入式经典)

    1 用预处理指令 define声明一个常数 xff0c 用以表明1年中有多少秒 xff08 忽略闰年问题 xff09 define SECONDS PER YEAR 60 60 24 365 UL 2 写一个 标准 宏MIN xff0c 这
  • 择业面对选择,嵌入式 or 互联网,该进哪个?

    这个话题可能是不少电子相关专业的毕业生面临的困惑 xff0c 怎么选择 xff0c 可以听听别人的意见来作为参考 xff0c 但最终还是要由自己的兴趣和爱好决定 知乎上有这样一个提问 xff1a 本人大一开始玩各种单片机 FPGA DSP
  • 大疆无人机-图传技术

    大疆无人机 xff08 航拍器 xff09 遥控连接电脑驱动解决方案 http mini eastday com mobile 160722051432373 html 无人机系列之图传技术https blog csdn net ad360
  • 【2】uC/OS-III应用开发————>启动流程(STM32F767)

    简述 xff1a 上电启动 xff0c 分为三个阶段 CPU内核的初始化 xff0c ARM公司编写 xff0c 所用CPU的 s文件外设模块的初始化OS相关操作的初始化 启动 调度等等系统的启动 上电执行启动文件里面的复位函数Reset
  • Windows11原版镜像

    Windows 11 xff08 企业版 xff09 版本 22H2 xff08 2023年02月发布 xff09 64 位简体中文 文件 xff1a zh cn windows 11 business editions version 2
  • 树莓派操作系统

    树莓派操作系统 树莓派操作系统 介绍更新和升级树莓派操作系统 使用 APT使用 rpi 更新播放音频和视频 OMXPlayer 应用程序如何播放音频如何播放视频播放期间的选项在后台播放使用 USB 网络摄像头 基本用法自动化图像捕获延时拍摄
  • ARM平台FS6818/s5p6818开发板实验7 —— 通过I2C读取MMA8451三轴加速度传感器芯片实现计步器功能的实验

    实验目的 掌握I2C协议的内容 xff0c 了解I2C接口的特点 了解陀螺仪MMA8451的用途及数据采集过程 熟悉s5p6818处理器的I2C配置 xff0c 完成通过I2C读取MMA8451三轴加速度传感器芯片和加速度的改变实现计步功能
  • uC/OS-II 一些细节问题

    最高和最低优先级的任务最好不要使用 xff0c 而用户使用的任务多达56个 xff0c 0表示最高优先级 建立任务的函数有两个 OSTaskCreate OSTaskCreateExt xff08 可设置更多任务细节 xff09 OSSta

随机推荐

  • CubeMX配置FreeRTOS

    01 说在前面 RTOS为了提高任务调度效率一般都包含汇编程序 xff0c 因此移植起来需要一些汇编知识 xff0c 就算网上肯定有移植教程 xff0c 初次搞起来还是挺费劲的 初学时对RTOS代码不熟悉 xff0c 一开始就打击了积极性可
  • 云台控制协议VISCA、PELCO-D、PELCO-P

    1 VISCA部分协议命令 控制 命令 格式 备注 预置点 清除预置点 8X 01 04 3F 00 ZZ FF X 61 1 7 8是广播码 xff0c 下同 xff1b ZZ 61 00 3F xff0c 共64个预置点 设预置点 8X
  • lpms-ig1 IMU使用

    1 xff09 打开网址 https bitbucket org lpresearch lpmsig1opensourcelib 实现1 2 3块编译 2 xff09 给串口 ttyUSB0 赋予权限sudo chmod 777 dev t
  • Vitis AI1.1 系列教程1 - 软件安装

    这里写自定义目录标题 我的安装环境 安装过程在VMware中安装ubuntu 16 04安装Vitis AI几个常见的docker指令 我的安装环境 windows 10VMware 15 5Vitis AI 1 1ubuntu 16 04
  • PX4/Pixhawk - 编译环境搭建

    最近在学习px4的二次开发 xff0c 发现网上的环境搭建教程五花八门 xff0c 大多复杂 xff0c 重重踩坑之后 xff0c 发现还是官方的教程好使 xff0c 总结如下 xff1a 环境准备 采用vmware虚拟机搭建环境系统是ub
  • PX4/Pixhawk 教程 - 任务线程 - workqueue 和 task

    介绍 一个完整的px4的应用程序 xff08 或者叫任务 xff09 分为前台部分和后台部分 xff0c 前台部分是跑在shell任务中的 xff0c 比如helloworld那个程序就只有前台部分 xff0c 敲入指令即可在ssh中运行
  • PX4/Pixhawk 教程 - 可视化参数配置和自启动 - param

    px4常见的设置模块自启动的方式有两种 xff0c 一种是在rx xxx文件中添加需要启动的项 xff0c 另一种是通过yaml参数配置文件 通过添加系统启动项 通过修改系统的启动项实现模块的自启动 xff1a 在px4 ROMFS px4
  • PX4/Pixhawk 教程 - uavcan v1 - libcanard传输层最简例子

    介绍 上一篇主要是介绍libcanard的基础知识和函数 xff0c 比较偏理论一点 xff0c 这一篇呢主要注重于实践 主要解决以下问题 xff1a xff08 1 xff09 如何把uavcan v1编译到default标签 xff08
  • 如何把git的submoudule变为本仓库依赖

    介绍 一些著名的开源项目往往运用了大量的其他submodule xff0c 但是对于嵌入式开发 xff0c 我们希望可以维护一个稳定的完整的仓库 xff0c 因此需要把submodule的外部依赖改成本仓库依赖 步骤 删掉仓库根目录下的 g
  • qgroundcontrol编译环境搭建

    qgc编译环境搭建和编译 qt安装 从官网下载安装程序 http www qt io download open source 给安装程序授权 span class token function chmod span 43 x qt uni
  • STM32F4教程从零开始0——从官网获取固件库

    从大二到现在玩stm32也有两年了 xff0c 估计以后用stm32 的机会不多了 xff0c 所以打算写一系列的教程来纪念一下陪我走过大学时光 xff0c 成为我的科技竞赛重要利器的STM32F4 这系列的教程将用stm32F407VGT
  • STM32F4教程从零开始1——建工程

    今天 xff0c 新买的机械到手 xff0c 很开心 xff0c 用得很爽 xff0c 所以决定再写一篇 xff0c 话说这是我第一次买机械键盘 xff0c 我现在也支持程序员可以没有一个好的电脑 xff0c 但必须有一个好的键盘的说法了
  • '\0'就是 字符串结束标志

    39 0 39 就是 字符串结束标志 比如说 xff0c 把一个字符串赋值给数组 xff1a u8 str1 61 34 cxjr 21ic org 34 实际上数组str1在内存中的实际存放情况为 xff1a c x j r 2 1 i
  • Git教程之局域网服务器搭建教程(Gitlab)

    Gitlab局域网服务器搭建教程 简介在ubuntu服务器上安装Gitlab安装过程登入界面常见问题Group项目push失败 xff08 403错误 xff09 如何删除项目 简介 Git是一个程序员必备的版本管理软件 xff0c 个人使
  • QuadrotorFly-四旋翼无人机动力学仿真环境介绍

    QuadrotorFly四旋翼无人机动力学模型 主要目的是开发一个用于无人机动力学仿真的简单易用 功能相对齐全的仿真环境 xff08 也许是水论文环境 xff09 这个仿真是基于python编写的 xff0c GPL开源 git的地址在 x
  • HTML5 APP项目展示响应式网页模板

    简介 xff1a 国外的一款APP项目展示HTML单页模板 1 该模板代码干净整洁 xff1b 2 效果相当的炫酷 xff0c 相当简洁大气高端 xff0c 模板简单 xff0c 全部已数据调用 3 网站手工DIV 43 css xff0c
  • 自动驾驶仿真工具之AirSim简介

    简介 开源 xff0c 跨平台 xff0c 支持Linux Windows PX4 xff0c 基于Unreal Engine xff0c 有Unity版本 xff08 实验版 xff09 Github链接 多种语言API xff0c 包括
  • MobaXterm 远程linux服务器图像界面打不开

    如图所示 xff0c 本人用的是 MobaXterm软件 远程连接linux系统 xff0c 但是显示图形界面的时候 这里无法显示 xff0c 报错 xff1a demo 895 Gtk WARNING 23 06 41 170 canno
  • linux+opencv 将摄像头视频通过UDP协议发送给服务器端并显示

    我这边有一块rock3a开发板 xff0c 并童工USB接口外接一个USB 海康威视高清摄像头 200万像素 首先源码编译aarch版本的opencv xff0c 之前的博客中有讲 xff0c 这里不再赘述 进入linux开发界面 xff0
  • ROS入门之Cmakelist说明

    Cmakelist http wiki ros org catkin CMakeLists txt 1 Overall Structure and Ordering Your CMakeLists txt file MUST follow