cartographer的CMakeLists.txt与package.xml文件

先看看xml文件:

cartographer_ros
1.0.0

这个是project的名称和版本号,记住有个/在结尾处

catkin

依赖工具为catkin,说明是ros

google-mock

这些是依赖项

rosbag

这些是依赖的库,必须有,要不编译会出错


    

这些是插件依赖

再看CMakeLists.txt文件

project(cartographer_ros): 这个为工程名,我感觉可有可无,之前自己没写也编译通过,不影响编译

set(PACKAGE_DEPENDANCIES ...

这个就是把设置变量,把...定义为PACKAGE_DEPENDANCIES,以后用的方便

find_package(包名  *REQUIRED  ...)

找包,REQUIRED可选,若选,则找不到的情况下报错退出编译

include("${CARTOGRAPHER_CMAKE_DIR}/functions.cmake")

在cartographer的cmake文件夹下找到functions.cmake,类似c的include

functions.cmake文件主要是一些cmake的一些函数

google_initialize_cartographer_project():这个就是在functions.cmake中定义的一个函数

find_package(catkin REQUIRED COMPONENTS ${PACKAGE_DEPENDENCIES})

上面这个是找到catkin和之前set定义的变量代表的库(见上)

include_directories(

${urdfdom_headers_INCLUDE_DIRS}

)

这个是把urdf的所有头文件放到当前目录,相当于include了

catkin_package(
  CATKIN_DEPENDS
    ${PACKAGE_DEPENDENCIES}
  DEPENDS
    # TODO(damonkohler): This should be here but causes Catkin to abort because
    # protobuf specifies a library '-lpthread' instead of just 'pthread'.
    # CARTOGRAPHER
    PCL
    EIGEN3
    Boost
    urdfdom_headers
  INCLUDE_DIRS "."
  LIBRARIES ${PROJECT_NAME}
)

上面的是ROS包的依赖,${PACKAGE_DEPENDENCIES}是定义的所有ros的依赖,下面的PCL等是非ros的依赖.

file(GLOB_RECURSE ALL_SRCS "cartographer_ros/*.cc" "cartographer_ros/*.h")

这个是循环找cartographer_ros里面所有的.cc文件和.h文件并命名成变量ALL_SRCS

add_library(${PROJECT_NAME} STATIC ${ALL_SRCS})

把ALL_SRCS做成${PROJECT_NAME}的静态库

add_subdirectory("cartographer_ros")

添加子目录,生成可执行文件,这个子目录就是把其他的文件生成可执行文件然后install到系统文件夹下(静态库,动态库,可执行文件等)

target_link_libraries(${PROJECT_NAME} PUBLIC cartographer)

把cartographer和cartographer_ros链接起来

add_dependencies(${PROJECT_NAME} ${catkin_EXPORTED_TARGETS})

这个意思是cartographer_ros需要添加指定的依赖(catkin),必须编译完这些依赖并且生成相应文件后才会编译cartographer_ros

install(DIRECTORY launch urdf configuration_files

DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}

)

上面的意思是把launch urdf configuration_files这些文件夹安装在CATKIN_PACKAGE_SHARE_DESTINATION变量代表的文件夹上面

install(PROGRAMS scripts/tf_remove_frames.py

DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}

):把scripts/tf_remove_frames.py作为程序文件安装在CATKIN_PACKAGE_BIN_DESTINATION变量含义上面

file(GLOB_RECURSE HDRS "cartographer_ros/*.h")

foreach(HDR ${HDRS})

file(RELATIVE_PATH REL_FIL ${PROJECT_SOURCE_DIR} ${HDR})

get_filename_component(INSTALL_DIR ${REL_FIL} DIRECTORY)

install(

FILES

${HDR}

DESTINATION

include/${INSTALL_DIR}

)

endforeach()

:把cartographer_ros所有的.h文件循环找到后命名成变量HDRS,对于HDRS的每个元素遍历安装在include/${INSTALL_DIR}上

在cartographer的CMakeLists.txt中

install(FILES package.xml DESTINATION share/cartographer):

把文件package.xml安装在share/cartographer上面

file(GLOB_RECURSE ALL_DOTFILES ".*/*")

......

移除所有.开头的文件,以防止编译的时候受污染

file(GLOB_RECURSE INTERNAL_HDRS "cartographer/*/internal/*.h")
list(REMOVE_ITEM INSTALL_SOURCE_HDRS ${INTERNAL_HDRS})

file(GLOB_RECURSE ALL_PROTOS "cartographer/*.proto")
file(GLOB_RECURSE ALL_GRPC_SERVICES "cartographer/*_service.proto")
list(REMOVE_ITEM ALL_PROTOS ALL_GRPC_SERVICES)
if (NOT ${BUILD_GRPC})
  list(REMOVE_ITEM ALL_PROTOS ${ALL_GRPC_FILES})
endif()

移除所有internal文件夹内的头文件,不进行安装

file(GLOB_RECURSE ALL_PROTOS "cartographer/*.proto")

file(GLOB_RECURSE ALL_GRPC_SERVICES "cartographer/*_service.proto")

找到所有.proto的文件并且命名为相应参数

list(REMOVE_ITEM ALL_PROTOS ALL_GRPC_SERVICES)

删除上面提到的所有proto文件

list(APPEND ALL_PROTO_SRCS "${PROJECT_BINARY_DIR}/${DIR}/${FIL_WE}.pb.cc")

list(APPEND ALL_PROTO_HDRS "${PROJECT_BINARY_DIR}/${DIR}/${FIL_WE}.pb.h")

proto编译生成的文件为.pb.cc,.pb.h文件,分别命名

list(APPEND ALL_LIBRARY_HDRS ${ALL_PROTO_HDRS})

list(APPEND ALL_LIBRARY_SRCS ${ALL_PROTO_SRCS})

添加.pb.h与.pb.cc到头文件源文件列表

add_library(${PROJECT_NAME} STATIC ${ALL_LIBRARY_HDRS} ${ALL_LIBRARY_SRCS})

把所有头文件和src文件静态编译成cartographer文件

target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC
  "${EIGEN3_INCLUDE_DIR}")
target_link_libraries(${PROJECT_NAME} PUBLIC ${EIGEN3_LIBRARIES})

对cartographer进行一些头文件引入和链接工作

...

install(
  TARGETS ${PROJECT_NAME}
  EXPORT CartographerExport
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)

安装cartographer到系统文件夹里面(lib)文件夹里

foreach(HDR ${INSTALL_SOURCE_HDRS})
  file(RELATIVE_PATH REL_FIL ${PROJECT_SOURCE_DIR} ${HDR})
  get_filename_component(DIR ${REL_FIL} DIRECTORY)
  install(
    FILES ${HDR}
    DESTINATION include/${DIR}
  )
endforeach()

安装头文件到系统文件夹下(include里面),注意,之前把所有internal的头文件都删了,所以不会安装

你可能感兴趣的:(cartographer,slam,c++)