catkin_make install安装与打包ros功能包

假设有以下工程文件:
catkin_make install安装与打包ros功能包_第1张图片
其中bus_control是主文件,而pure_pursuit、planing均是其依赖文件。
在bus_control层级的CMakeLists.txt写法:

cmake_minimum_required(VERSION 3.0.2)
project(bus_control)
# set(CMAKE_BUILD_TYPE Release)
SET(CMAKE_BUILD_TYPE Debug)
## 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
  tf
  tf2_ros
  bus_msgs
  nav_msgs
  geodesy
  route_planner
  pure_pursuit
)

## System dependencies are found with CMake's conventions
find_package(Boost REQUIRED COMPONENTS system)
find_package(Eigen3 REQUIRED)


catkin_package(
CATKIN_DEPENDS 
  roscpp 
  rospy 
  std_msgs 
)

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

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  ${EIGEN3_INCLUDE_DIR}
)
## Declare a C++ library
add_library(bus_control
  src/bus_control.cc
  src/pid_controller.cc
)
target_link_libraries(bus_control
  ${catkin_LIBRARIES}
  ${Boost_LIBRARIES}
)
add_dependencies(bus_control ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

add_executable(bus_control_node src/bus_control_node.cc)
add_dependencies(bus_control_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(bus_control_node
   ${catkin_LIBRARIES}
   bus_control
)

#############
## Install ##
#############
install(TARGETS
bus_control
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(TARGETS bus_control_node 
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}

install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
install(DIRECTORY rviz
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
install(DIRECTORY params
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
install(FILES 
  launch/bus_control.launch
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
)

而以pure_pursuit为例,其CMakeLists.txt写法,planning模块类似:

cmake_minimum_required(VERSION 3.0.2)
project(pure_pursuit)

add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  jsk_recognition_msgs
  message_generation
  roscpp
  roslint
  rosunit
  sensor_msgs
  tf
  bus_msgs
  geodesy
  geographic_msgs
)

find_package(Eigen3 QUIET)

if (NOT EIGEN3_FOUND)
  # Fallback to cmake_modules
  find_package(cmake_modules REQUIRED)
  find_package(Eigen REQUIRED)
  set(EIGEN3_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS})
  set(EIGEN3_LIBRARIES ${EIGEN_LIBRARIES})  # Not strictly necessary as Eigen is head only
  # Possibly map additional variables to the EIGEN3_ prefix.
else ()
  set(EIGEN3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR})
endif ()


catkin_package(
  INCLUDE_DIRS include
  LIBRARIES pure_pursuit
#  CATKIN_DEPENDS geometry_msgs jsk_recognition_msgs message_generation roscpp roslint rosunit sensor_msgs tf
#  DEPENDS system_lib
)

###########
## Build ##
###########
include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  ${EIGEN3_INCLUDE_DIR}
)

add_library(libwaypoint_follower src/libwaypoint_follower.cpp)
add_dependencies(libwaypoint_follower ${catkin_EXPORTED_TARGETS})
target_link_libraries(libwaypoint_follower ${catkin_LIBRARIES})


add_library(pure_pursuit
  src/pure_pursuit.cpp
  src/pure_pursuit_viz.cpp
  src/pure_pursuit_node.cpp
)
target_link_libraries(pure_pursuit
  ${catkin_LIBRARIES}
  libwaypoint_follower
)
add_dependencies(pure_pursuit ${catkin_EXPORTED_TARGETS})

install(TARGETS libwaypoint_follower
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)
install(TARGETS pure_pursuit
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)

然后使用catkin_make install编译与安装,会在src层级生成install文件夹,其内容为

请添加图片描述
其中lib文件夹:
catkin_make install安装与打包ros功能包_第2张图片
share文件夹:
catkin_make install安装与打包ros功能包_第3张图片
bus_control文件夹:
catkin_make install安装与打包ros功能包_第4张图片
相应的launch参数,param设置可以在这里设置。
程序运行?可以拷贝install文件到任意目录,然后

source setup.bash
roslaunch bus_control bus_control.launch

即可运行程序。

你可能感兴趣的:(Linux知识点,自动驾驶,c++,人工智能)