ros1的原始CMakeLists.txt文件备份

ros1的原始CMakeLists.txt文件备份

# toplevel CMakeLists.txt for a catkin workspace
# catkin/cmake/toplevel.cmake

cmake_minimum_required(VERSION 2.8.3)

set(CATKIN_TOPLEVEL TRUE)

# search for catkin within the workspace
set(_cmd "catkin_find_pkg" "catkin" "${CMAKE_SOURCE_DIR}")
execute_process(COMMAND ${_cmd}
  RESULT_VARIABLE _res
  OUTPUT_VARIABLE _out
  ERROR_VARIABLE _err
  OUTPUT_STRIP_TRAILING_WHITESPACE
  ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _res EQUAL 0 AND NOT _res EQUAL 2)
  # searching fot catkin resulted in an error
  string(REPLACE ";" " " _cmd_str "${_cmd}")
  message(FATAL_ERROR "Search for 'catkin' in workspace failed (${_cmd_str}): ${_err}")
endif()

# include catkin from workspace or via find_package()
if(_res EQUAL 0)
  set(catkin_EXTRAS_DIR "${CMAKE_SOURCE_DIR}/${_out}/cmake")
  # include all.cmake without add_subdirectory to let it operate in same scope
  include(${catkin_EXTRAS_DIR}/all.cmake NO_POLICY_SCOPE)
  add_subdirectory("${_out}")

else()
  # use either CMAKE_PREFIX_PATH explicitly passed to CMake as a command line argument
  # or CMAKE_PREFIX_PATH from the environment
  if(NOT DEFINED CMAKE_PREFIX_PATH)
    if(NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")
      string(REPLACE ":" ";" CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
    endif()
  endif()

  # list of catkin workspaces
  set(catkin_search_path "")
  foreach(path ${CMAKE_PREFIX_PATH})
    if(EXISTS "${path}/.catkin")
      list(FIND catkin_search_path ${path} _index)
      if(_index EQUAL -1)
        list(APPEND catkin_search_path ${path})
      endif()
    endif()
  endforeach()

  # search for catkin in all workspaces
  set(CATKIN_TOPLEVEL_FIND_PACKAGE TRUE)
  find_package(catkin QUIET
    NO_POLICY_SCOPE
    PATHS ${catkin_search_path}
    NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
  unset(CATKIN_TOPLEVEL_FIND_PACKAGE)

  if(NOT catkin_FOUND)
    message(FATAL_ERROR "find_package(catkin) failed. catkin was neither found in the workspace nor in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was sourced before.")
  endif()
endif()

catkin_workspace()

ROS中,CMakeLists.txt文件是用于构建catkin工程的重要文件之一,它定义了工程的编译规则和依赖关系。下面是一个基本的CMakeLists.txt文件结构: ``` cmake_minimum_required(VERSION 2.8.3) project(my_project) ## Find catkin macros and libraries find_package(catkin REQUIRED COMPONENTS roscpp std_msgs ) ## Declare a catkin package catkin_package( CATKIN_DEPENDS roscpp std_msgs ) ## Build include_directories( ${catkin_INCLUDE_DIRS} ) add_executable(my_node src/my_node.cpp) target_link_libraries(my_node ${catkin_LIBRARIES}) ``` 其中,`cmake_minimum_required` 和 `project` 命令是必须的,用于指定CMake最低版本和工程名称。`find_package` 命令是用来查找ROS依赖的,`catkin_package` 命令是声明catkin工程的一些信息,如依赖项等。`include_directories` 命令用于指定头文件路径,`add_executable` 用于添加可执行文件,`target_link_libraries` 用于链接库。 除此之外,CMakeLists.txt文件还可以包含一些其他的命令,例如: - add_library:添加一个库文件 - add_dependencies:添加依赖项 - install:安装目标文件到指定目录 - catkin_add_gtest:添加gtest单元测试 - catkin_add_nosetests:添加nosetests单元测试 - catkin_python_setup:设置Python包 这些命令可以根据实际需要进行添加,以实现工程的编译和构建。需要注意的是,CMakeLists.txt 文件是通过层层递归调用来完成构建的,因此,所有的依赖项必须在CMakeLists.txt文件中明确声明,否则会出现编译错误。 总之,CMakeLists.txt文件ROS工程构建中的重要组成部分,它定义了工程的编译规则和依赖关系,同时也可以包含一些与catkin相关的命令,方便管理ROS工程的编译和构建。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值