catkin之cmakefiles.txt格式

来源:互联网 发布:网络出版 编辑:程序博客网 时间:2024/04/29 02:58
  • Required CMake Version (cmake_minimum_required)

  • Package Name (project())

  • Find other CMake/Catkin packages needed for build (find_package())

  • Message/Service/Action Generators (add_message_files(), add_service_files(), add_action_files())

  • Invoke message/service/action generation (generate_messages())

  • Specify package build info export (catkin_package())

  • Libraries/Executables to build (add_library()/add_executable()/target_link_libraries())

  • Tests to build (catkin_add_gtest())

  • Install rules (install())


版本
cmake_minimun_required(version 2.8.3)
包含项目名
project(beginner_tutorials)
寻找依赖的包
find_package(catkin REQUIRED)    至少依赖catkin(必要的)
以下可选包元素
find_package(catkin REQUIRED COMPONENTS rospy roscpp std_msgs)
上述写法的另一种形式
find_package(catkin REQUIRED)
find_package(rospy REQUIRED)
find_package(roscpp REQUIRED)
find_package(std_msgs REQUIRED)

if you using C++ and Boost:
find_package(Boost REQUIRED COMPONENTS thread)
catkin包 是cmake的宏
catkin_package()有五个可选属性
catkin_package(   INCLUDE_DIRS include   LIBRARIES ${PROJECT_NAME}   CATKIN_DEPENDS roscpp nodelet  # 比较重要的一条属性   DEPENDS eigen opencv)
输出目标文件名替换
set_target_properties(rviz_image_view                      PROPERTIES OUTPUT_NAME image_view                      PREFIX "")
从rviz_image_view修改为image_view
设置自己的输出目录
set_target_properties(python_module_library  PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION})
include_directories()

The argument to include_directories should be the *_INCLUDE_DIRS variables generated by your find_package calls and any additional directories that need to be included. If you are using catkin and Boost,即

catkin_INCLUDE_DIRS    Boost_INCLUDE_DIRS

include_directories(include  ${catkin_INCLUDE_DIRS}    ${Boost_INCLUDE_DIRS})

可执行目标必须建立


add_executable(myProgram src/main.cpp src/some_file.cpp src/another_file.cpp)
                                   项目名  +   源文件

#    add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS})

       add_library(moo src/moo.cpp)

链接 target_link_libraries()

语法:  target_link_libraries(<executableTargetName>, <lib1>, <lib2>, ... <libN>)

example:


add_executable(foo src/foo.cpp)add_library(moo src/moo.cpp)target_link_libraries(foo moo)  -- This links foo against libmoo.so

for python 参考:http://docs.ros.org/api/catkin/html/howto/format2/installing_python.html

Installing Python Executable Scripts

catkin_install_python(PROGRAMS scripts/myscript  DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
1 0