一文带你详解package.xml和CMakeLists.txt文件代码结构

在看工程代码时,顺便对package.xml和CMakeLists.txt文件代码结构进行了探索与知识巩固,下面逐一进行展示:

首先package.xml文件:



		
  ars_40X			
  0.0.0		
  The ars_40X package contains a ROS driver for the Continental radar ARS_404 / ARS_408.		
  org	
  TODO: License declaration		

  catkin	
  message_generation	
  message_runtime	

  costmap_converter	
  geometry_msgs
  nav_msgs
  roscpp
  socket_can
  std_msgs
  std_srvs 	

  message_runtime	

  							
    catkin		
  

CMakeLists.txt文件 :

cmake_minimum_required(VERSION 3.5)		# CMake版本
project(ars_40X)		# 工程名

# Default to C99
if (NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif ()

# Default to C++14
if (NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif ()

if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif ()

# find dependencies,加载外部变量
find_package(catkin REQUIRED
    COMPONENTS
    roscpp
    std_msgs
    geometry_msgs
    message_generation		# 加载catkin中的变量,同时添加roscpp、std_msgs、geometry_msgs、message_generation的依赖
    )

find_package(nav_msgs REQUIRED)
find_package(socket_can REQUIRED)
find_package(std_srvs REQUIRED)
find_package(Eigen3 REQUIRED)		# 加载外部变量

add_message_files(DIRECTORY msg
    FILES
    Cluster.msg
    ClusterList.msg
    Object.msg
    ObjectList.msg
    RadarStatus.msg		#添加自定义消息文件
)

add_service_files(
    FILES
    MaxDistance.srv
    OutputType.srv
    RadarPower.srv
    RCSThreshold.srv
    SensorID.srv
    SortIndex.srv		#添加自定义服务文件
)

generate_messages(DEPENDENCIES std_msgs geometry_msgs)	#添加msg文件生成源代码文件时所需的依赖项

catkin_package(		#catkin_package()是catkin提供的CMake宏,用于为catkin提供构建、生成pkg-config和CMake文件所需要的信息。
    INCLUDE_DIRS	# 声明给其它package的include路径
    include
    LIBRARIES		# 声明给其它package的库
    ${PROJECT_NAME}_can
    ${PROJECT_NAME}_msg
    CATKIN_DEPENDS	#本包依赖的catkin package
    message_runtime
    roscpp
    socket_can
)

include_directories(${catkin_INCLUDE_DIRS})
include_directories(include)	
include_directories(${socket_can_INCLUDE_DIRS})		# 添加头文件路径:  ${catkin_INCLUDE_DIRS}、include、${socket_can_INCLUDE_DIRS}

add_library(ars_40X_msg
    src/cluster_list.cpp
    src/motion_input_signals.cpp
    src/object_list.cpp
    src/radar_cfg.cpp
    src/radar_state.cpp
    )		# 生成库文件,可传入多个源文件

add_library(ars_40X_can
    src/ars_40X_can.cpp
    )		# 生成库文件,可传入多个源文件

target_link_libraries(ars_40X_can ars_40X_msg ${socket_can_LIBRARIES})	#为可执行文件或库添加链接库

add_executable(ars_40X_ros
    src/ros/ars_40X_ros.cpp
    src/ros/cluster_list_ros.cpp
    src/ros/motion_input_signals_ros.cpp
    src/ros/object_list_ros.cpp
    src/ros/radar_cfg_ros.cpp
    src/ros/radar_state_ros.cpp
    )		#生成可执行文件,可以传入多个源文件

add_dependencies(ars_40X_ros ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_generate_messages_cpp)		#为目标文件(add_executable(), add_library()中生成的)指定依赖,前提是已经通过find_package()引入了这个package
target_link_libraries(ars_40X_ros ${catkin_LIBRARIES})		#为可执行文件或库添加链接库,${catkin_LIBRARIES} 为ROS基本库

target_link_libraries(ars_40X_ros ars_40X_can ${catkin_LIBRARIES})		#为可执行文件或库添加链接库,${catkin_LIBRARIES} 为ROS基本库

install(
    TARGETS
    ars_40X_can
    ars_40X_msg
    ars_40X_ros
    ARCHIVE DESTINATION lib/${PROJECT_NAME}
    LIBRARY DESTINATION lib/${PROJECT_NAME}
    RUNTIME DESTINATION lib/${PROJECT_NAME}
)	#默认情况catkin会为每个package在./devel中建立目录,存放目标文件
    # 目标文件可以直接通过rosrun和roslaunch访问
    # 如需制定其它安装位置,则需通过install()命令

 后续再进行补充和完善。

你可能感兴趣的:(ROS,xml,c++,自动驾驶)