学会CMakeLists文件编写是学习ros一个很重要的知识,但是因为每个人编写的CMakeLists不同,当初学习的时候我查了很多学习资料发现依旧很难入门,所以现在准备详细全面的介绍一下CMakeLists里面包含哪些内容,如何根据自己的项目编写自己的CMakeLists文件。
全程我会先全面介绍CMakeLists相关的知识点,然后根据我的机械臂的一个小项目为例子介绍一下CMakeLists文件怎么编写,之后大家就可以自己尝试着写一写了。
首先我们会新建一个工作空间和构建功能包,这部分不会的小伙伴可以参考VScode 使用教程——ros下编译C/C++代码,之后我们点开CMakeLists文件,发现里面不是空的,如下面代码所示。其实这里面已经把CMakeLists的框架都给我们了,我们到时候只需要把相关的地方给取消注释,然后在里面填上相关的内容就行。英语好的同学其实根据注释就能读懂每个模块是要干什么的。不太了解的小伙伴也不用着急,接下来我们就按顺序给大家讲解一下每块代码什么意思。
cmake_minimum_required(VERSION 3.0.2)
project(hello_world)
## 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
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
## System dependencies are found with CMake's conventions
# 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
# catkin_python_setup()
################################################
## 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 exec_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 exec_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 ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * 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(
# 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
# generate_messages(
# 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 exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
## * add "dynamic_reconfigure" to
## find_package(catkin REQUIRED COMPONENTS ...)
## * uncomment the "generate_dynamic_reconfigure_options" section below
## and list every .cfg file to be processed
## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
# 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 your 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(
# INCLUDE_DIRS include
# LIBRARIES hello_world
# CATKIN_DEPENDS roscpp rospy std_msgs
# 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}/hello_world.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(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/hello_world_node.cpp)
## Rename C++ executable without prefix
## 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
# 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(${PROJECT_NAME}_node
# ${catkin_LIBRARIES}
# )
#############
## 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
# catkin_install_python(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_GLOBAL_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 ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_hello_world.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)
cmake_minimum_required(VERSION 3.0.2)
第一行代码表示了cmake所需要的最小版本是3.0.2。(这行不用管)
project(hello_world)
第二行代码表示功能包名称(也就是之前创建功能包的名字),在之后的CMakeLists代码里,可以使用${PROJECT_NAME}变量来引用这个包名。(这行也不用管)
## 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 roscpp rospy std_msgs )
这里是设置构建需要的软件包,基本就这三个。
## System dependencies are found with CMake's conventions 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 catkin_python_setup()
启动python模块支持。(代码如果是用C++写的话,这个保持注释即可,如果是python写的需要取消注释)
声明 ROS 消息、服务、动作
################################################ ## 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 exec_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 exec_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 ...) ## * uncomment the add_*_files sections below as needed ## and list every .msg/.srv/.action file to be processed ## * 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( 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 generate_messages( DEPENDENCIES std_msgs )
这一大块都是跟ROS的消息,服务,动作有关的。具体的如下:
- add_message_files是添加消息文件选项。FILES 将引用当前功能包目录的 msg 目录中的*.msg文件,自动生成一个头文件(*.h)。在这个例子中,我们将使用消息文件 Message1.msg 和 Message2.msg。
## Generate messages in the 'msg' folder add_message_files( FILES Message1.msg Message2.msg )
add_service_files 是添加要使用的服务文件的选项。使用 FILES 会引用功能包目录中的srv 目录中的*.srv 文件。 在这个例子中,用户可以选择使用服务文件Service1.srv 和Service2.srv。
## Generate services in the 'srv' folder add_service_files( FILES Service1.srv Service2.srv )
add_action_files 是添加要使用的动作文件的选项。使用 FILES 会引用功能包目录中的action 目录中的*.action 文件。 在这个例子中,用户可以选择使用服务文件Action1.action 和Action2.action。
## Generate actions in the 'action' folder add_action_files( FILES Action1.action Action2.action )
添加生成消息、服务时的依赖包。generate_messages 是设置依赖的消息的选项。此示例是将 DEPENDENCIES 选项设置为使用std_msgs 消息包。
## Generate added messages and services with any dependencies listed here generate_messages( DEPENDENCIES std_msgs )
声明 ROS 动态参数配置
################################################ ## 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 exec_depend tag for "dynamic_reconfigure" ## * In this file (CMakeLists.txt): ## * add "dynamic_reconfigure" to ## find_package(catkin REQUIRED COMPONENTS ...) ## * uncomment the "generate_dynamic_reconfigure_options" section below ## and list every .cfg file to be processed ## Generate dynamic reconfigure parameters in the 'cfg' folder generate_dynamic_reconfigure_options( cfg/DynReconf1.cfg cfg/DynReconf2.cfg )
一般保持注释状态即可。
catkin特定配置
################################### ## 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 your 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 ## 运行时依赖,INCLUDE_DIRS 表示将使用INCLUDE_DIRS 后面的内部目录 include 的头文件。 ## LIBRARIES 表示将使用随后而来的功能包的库。 ## CATKIN_DEPENDS 后面指定如 roscpp 或 std_msgs 等依赖包。目前的设置是表示依赖于 roscpp 和 std_msgs。 ## DEPENDS 是一个描述系统依赖包的设置。 catkin_package( # INCLUDE_DIRS include # LIBRARIES static_avoidance # CATKIN_DEPENDS roscpp rospy std_msgs # DEPENDS system_lib )
运行时依赖。
- INCLUDE_DIRS 表示将使用INCLUDE_DIRS 后面的内部目录 include 的头文件。
- LIBRARIES 表示将使用随后而来的功能包的库。
- CATKIN_DEPENDS 后面指定如 roscpp 或 std_msgs 等依赖包。目前的设置是表示依赖于 roscpp 和 std_msgs。
- DEPENDS 是一个描述系统依赖包的设置。
(一般不用改这部分,保持默认的样子就行)
添加头文件路径,当前程序包的头文件路径位于其他文件路径之前
## Specify additional locations of header files ## Your package locations should be listed before other locations include_directories( # include ${catkin_INCLUDE_DIRS} )
include_directories 是可以指定包含目录的选项。目前设定为${catkin_INCLUDE_DIRS},这意味着将引用每个功能包中的 include 目录中的头文件。如果想指定一个额外的 include 目录时,写在${catkin_INCLUDE_DIRS}的下一行即可。
(如果你写了头文件,需要把include前面的注释取消)
声明 C++ 库
## Declare a C++ library add_library(${PROJECT_NAME} src/${PROJECT_NAME}/hello_world.cpp )
add_library 声明构建之后需要创建的库。还可以引用位于功能包的 src 目录中的.cpp 文件来创建static_lib库的命令。
举个例子:我写了一个头文件head.h,还在FK_Franka.cpp里面写了一个机械臂正运动学函数,并且在主函数里面调用了这个函数,那么就写成下面这样:
add_library(static_lib include/${PROJECT_NAME}/head.h src/FK_Franka.cpp )
static_lib是我自己取的名字,相当于自己建了一个叫static_lib的库,里面包含了head.h和FK_Franka.cpp
添加库的 cmake 目标依赖
## 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(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
(一般保持注释状态即可)
声明C++可执行文件
## Declare a C++ executable ## With catkin_make all packages are built within a single CMake context ## The recommended prefix ensures that target names across packages don't collide add_executable(${PROJECT_NAME}_node src/hello_world_node.cpp)
要把src/static_main.cpp改成src/<主函数文件名>.cpp
把${PROJECT_NAME}_node改成一个你自己取的名字比如就叫“static_main”,作为你主函数文件的映射名。
重命名 c++可执行文件
## Rename C++ executable without prefix ## 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 add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
添加可执行文件的 cmake 目标依赖,可执行文件的依赖关系,而不是上面提到的库。在建立可执行文件之前,先创建消息文件的情况下会经常用。
- 把${PROJECT_NAME}_node改成之前的主函数文件的映射名,比如上面的就是static_main。
- 把${PROJECT_NAME}_node改成之前的建的C++库名,比如上面的就是static_lib。
举个例子:
add_dependencies(static_lib ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) add_dependencies(static_main ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
指定库、可执行文件的链接库
## Specify libraries to link a library or executable target against target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES} )
target_link_libraries 是在创建特定的可执行文件之前将库和可执行文件进行链接的选项。
举个例子:
target_link_libraries(static_lib ${Franka_LIBRARIES} ${catkin_LIBRARIES} ) target_link_libraries(static_main static_lib ${Franka_LIBRARIES} ${catkin_LIBRARIES} )
分别是自己建的C++库static_lib和主函数映射名static_main添加需要用到的一些外部库。
## Mark executable scripts (Python etc.) for installation ## in contrast to setup.py, you can choose the destination catkin_install_python(PROGRAMS scripts/my_python_script DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} )
设置用于安装的可执行脚本 (保持默认注释状态即可)
剩下的一些不怎么会用到,就不管它了。
然后我给出一个我自己写的CMakeLists的文件,里面也附上了注释,大家可以参考参考。
cmake_minimum_required(VERSION 3.0.2) # 所需的cmake版本
project(avoid_static_obs) # 包名称,会使用${PROJECT_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
# 设置构建所需要的软件包
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
## System dependencies are found with CMake's conventions
# 默认添加系统依赖
# 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
# 启动python模块支持
# catkin_python_setup()
################################################
## 申明ROS消息,服务,动作##
## 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 exec_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 exec_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 ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * 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是添加消息文件选项。
## FILES 将引用当前功能包目录的 msg 目录中的*.msg文件,
## 自动生成一个头文件(*.h)。在这个例子中,我们将使用消息文件 Message1.msg 和 Message2.msg
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )
## Generate services in the 'srv' folder
## add_service_files 是添加要使用的服务文件的选项。
## 使用 FILES 会引用功能包目录中的 srv 目录中的*.srv 文件。
## 在这个例子中,用户可以选择使用服务文件Service1.srv 和Service2.srv。
# 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
## 生成消息、服务时的依赖包
## generate_messages 是设置依赖的消息的选项。此示例是将 DEPENDENCIES 选项设置为使用std_msgs 消息包。
# generate_messages(
# DEPENDENCIES
# std_msgs
# )
################################################
## 声明 ROS 动态参数配置 ##
## 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 exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
## * add "dynamic_reconfigure" to
## find_package(catkin REQUIRED COMPONENTS ...)
## * uncomment the "generate_dynamic_reconfigure_options" section below
## and list every .cfg file to be processed
## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
# cfg/DynReconf1.cfg
# cfg/DynReconf2.cfg
# )
###################################
## catkin 特定配置##
## 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 your 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
## 运行时依赖,INCLUDE_DIRS 表示将使用INCLUDE_DIRS 后面的内部目录 include 的头文件。
## LIBRARIES 表示将使用随后而来的功能包的库。
## CATKIN_DEPENDS 后面指定如 roscpp 或 std_msgs 等依赖包。目前的设置是表示依赖于 roscpp 和 std_msgs。
## DEPENDS 是一个描述系统依赖包的设置。
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES static_avoidance
# CATKIN_DEPENDS roscpp rospy std_msgs
# DEPENDS system_lib
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
## 添加头文件路径,当前程序包的头文件路径位于其他文件路径之前。
## include_directories 是可以指定包含目录的选项。目前设定为${catkin_INCLUDE_DIRS},这意味着将引用每个功能包中的 include 目录中的头文件。
## 当用户想指定一个额外的 include 目录时,写在${catkin_INCLUDE_DIRS}的下一行即可
include_directories(
include
${catkin_INCLUDE_DIRS}
)
include_directories("/usr/include/eigen3") # eigen库的路径
## Declare a C++ library
## 声明 C++ 库,add_library 声明构建之后需要创建的库。以下是引用位于功能包的 src 目录中的.cpp 文件来创建static_lib库的命令。
add_library(static_lib
include/${PROJECT_NAME}/head.h
src/FK_Franka.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 目标依赖
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
## 声明 C++ 可执行文件
add_executable(static_main src/static_main.cpp)
find_package(Franka 0.7.0 REQUIRED)
## Rename C++ executable without prefix
## 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"
## 重命名 c++可执行文件
# 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(static_lib ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_dependencies(static_main ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Specify libraries to link a library or executable target against
## 指定库、可执行文件的链接库.
## target_link_libraries 是在创建特定的可target_link_libraries(hello_ros 执行文件之前将库和可执行文件进行链接的选项。
target_link_libraries(static_lib
${Franka_LIBRARIES}
${catkin_LIBRARIES}
)
target_link_libraries(static_main
static_lib
${Franka_LIBRARIES}
${catkin_LIBRARIES}
)
#############
## 安装 ##
## 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
## 设置用于安装的可执行脚本
# catkin_install_python(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_GLOBAL_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 ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_static_avoidance.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)