cmake之(4) target_link_libraries 和 add_dependencies add_custom_target

  • add_dependencies():添加依赖项,在使用ROS的message、service、action时注意添加,如下:
    # 添加对其它package消息的依赖,前提是已经通过find_package()引入了这个package
    add_dependencies(my_target ${catkin_EXPORTED_TARGETS})
    # 添加对本package消息的依赖
    add_dependencies(my_target ${${PROJECT_NAME}_EXPORTED_TARGETS})
  • target_link_libraries():链接库
    # 为可执行文件或库添加链接库
    target_link_libraries(my_node
        ${catkin_LIBRARIES}        # ROS基本库
        ${Boost_LIBRARIES}         # Boost库
    )

 比如:

target_link_libraries(free_space_proto ${PROTOBUF_LIBRARIES})  #为free_space_proto添加链接库
add_dependencies(free_space_proto ${catkin_EXPORTED_TARGETS})  #为free_space_proto引入依赖,保证free_space_proto在构建之前这些依赖已经被构建.

你可能感兴趣的:(cmake)