본문 바로가기
언어 정리/빌드툴(catkin_make,make,cmake)

CMakeLists 문법 with catkin_make

by 알 수 없는 사용자 2022. 12. 31.

참고 : 

https://runebook.dev/ko/docs/cmake/command/execute_process

 

CMake - execute_process 하나 이상의 자식 프로세스를 실행하십시오.

하나 이상의 자식 프로세스를 실행하십시오. 주어진 하나 이상의 명령 시퀀스를 실행합니다. 명령은 파이프 라인으로 동시에 실행되며 각 프로세스의 표준 출력은 다음 프로세스의 표준 입력으

runebook.dev

 

https://cmake.org/cmake/help/latest/command/find_package.html

 

find_package — CMake 3.25.1 Documentation

Note The Using Dependencies Guide provides a high-level introduction to this general topic. It provides a broader overview of where the find_package() command fits into the bigger picture, including its relationship to the FetchContent module. The guide is

cmake.org

 

https://enssionaut.com/board_robotics/1264

 

로봇 - ROS(Robot Operating System) 개념과 활용 - 10. CMakeLists.txt 파헤치기

CMakeLists.txt는 빌드 설정에 관련된 매우 중요한 파일이지만 주석의 압박과 익숙하지 않은 사용법 때문에 매번 대충 작성했던 경험이 있습니다. 관련 가이드를 찾아 보니 생각보다 간단한 규칙으

enssionaut.com

 

https://www.tuwlab.com/ece/27260

 

[CMake 튜토리얼] 2. CMakeLists.txt 주요 명령과 변수 정리 - ECE - TUWLAB

▶ 이 글에서는 CMake 빌드 스크립트인 CMakeLists.txt 파일을 작성하는 방법에 대해 다룹니다. CMake 2.8.x 버전 기준이며, C언어 프로젝트를 기준으로 자주 사용되는 명령과 변수들을 선별하여 기능에

www.tuwlab.com


http://wiki.ros.org/ko/ROS/Tutorials/BuildingPackages

 

ko/ROS/Tutorials/BuildingPackages - ROS Wiki

패키지 빌드 모든 시스템 의존성이 설치되었으면, 이제 우리가 만든 패키지를 빌드할 때 입니다. rosmake 사용하기 rosmake는 make 명령과는 조금 다른, ROS만의 특별한 마술을 수행합니다. 만약 rosmake

wiki.ros.org

http://wiki.ros.org/catkin/commands/catkin_make

 

catkin/commands/catkin_make - ROS Wiki

catkin_make is a convenience tool for building code in a catkin workspace. catkin_make follows the standard layout of a catkin workspace, as described in REP-128. Usage You should always call catkin_make in the root of your catkin workspace, assuming your

wiki.ros.org

 

catkin_make <- cmake 랑 make를 합쳐서 특정 빌드를 하는 구조.

  • $ cd ~/catkin_ws
    $ catkin_make

위의 내용을 풀어서 쓰면 [ install 은 실행바이너리와 라이브러리등 실행파일, devel은 install 파일들 + 코드파일까지 ]

  • $ cd ~/catkin_ws
    $ cd src
    $ catkin_init_workspace
    $ cd ..
    $ mkdir build
    $ cd build
    $ cmake ../src -DCMAKE_INSTALL_PREFIX=../install -DCATKIN_DEVEL_PREFIX=../devel
    $ make

 

또한 install folder를 만들어 배포용으로 작업 할 수 도 있다. ( src에 작성한 코드가 없으면 의미 없음 )

  • $ cd ~/catkin_ws
    $ catkin_make install

위의 경우는 아래와 동일하다. 

  • $ cd ~/catkin_ws/build
    # If cmake hasn't already been called
    $ cmake ../src -DCMAKE_INSTALL_PREFIX=../install -DCATKIN_DEVEL_PREFIX=../devel
    $ make
    $ make install

 


키워드

 

cmake_minimum_required

  -  CMake 최소 버전

 

project

  -  패키지 이름

 

set

  - Variable 선언 , 1:1 대응이나 밑에 예시처럼 해도 된다.

unset

  - Variable 취소

 

execute_process

  - COMMAND 명령을 실행 : 실행 후 실행에 관련 alias를 이용할 수 있다 위의 예시 처럼 

 

message

  - 메시지 출력

 

find_pacakge

  - 빌드에 필요한 CMake, catkin 관련 패키지 탐색

 

add_message_files(), add_service_files(), add_action_files() 

- ROS 메시지, 서비스, 액션 생성기

 

generate_messages()

  - 메시지, 서비스, 액션 생성

 

catkin_package()

  - catkin 관련 빌드 정보 지정

 

add_library(), add_executable(), target_link_libraries()

  - 라이브러리, 실행 파일 지정

catkin_add_gtest()

  - 유닛 테스트

install()

  - 생성된 target에 대한 설치 옵션 지정

 

if 문

if(NOT _res EQUAL 0 AND NOT _res EQUAL 2)

endif()

 

for 문 

  foreach(path ${CMAKE_PREFIX_PATH})

  endforeach()

 


설명 및 예시

 

cmake_minimum_required

cmake_minimum_required(VERSION 3.0.2)

  -  CMake 최소 버전

 

project

project(Project)

  -  패키지 이름

 

set

set(CATKIN_TOPLEVEL TRUE)

set(_cmd "catkin_find_pkg" "catkin" "${CMAKE_SOURCE_DIR}")

  - Variable 선언 , 1:1 대응이나 밑에 예시처럼 해도 된다.

unset

  - Variable 취소

 

execute_process

execute_process(COMMAND ${_cmd}
  RESULT_VARIABLE _res
  OUTPUT_VARIABLE _out
  ERROR_VARIABLE _err
  OUTPUT_STRIP_TRAILING_WHITESPACE
  ERROR_STRIP_TRAILING_WHITESPACE
)

  - COMMAND 명령을 실행 : 실행 후 실행에 관련 alias를 이용할 수 있다 위의 예시 처럼 

 

message

message(FATAL_ERROR "Search for 'catkin' in workspace failed (${_cmd_str}): ${_err}")

  - 메시지 출력

 

find_pacakge

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)

 위 내용을 바꿔서 보자면 밑에 내용이랑 동일함.

find_package(catkin REQUIRED)
find_package(roscpp REQUIRED)
find_package(rospy REQUIRED)

find_package(std_msgs REQUIRED)

또 예를들어 이런식으로 쓰면 C++ Boost의 threads를 사용하고자 할 경우 : find_package(Boost REQUIRED COMPONENTS thread)

  - 빌드에 필요한 CMake, catkin 관련 패키지 탐색

 

add_message_files(), add_service_files(), add_action_files()

## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )
## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )
## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )
  - ROS 메시지, 서비스, 액션 생성기

 

generate_messages()

## Generate added messages and services with any dependencies listed here
# generate_messages(
#   DEPENDENCIES
#   std_msgs
# )

  - 메시지, 서비스, 액션 생성

 

catkin_package()

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES test_3
#  CATKIN_DEPENDS roscpp rospy std_msgs
#  DEPENDS system_lib
)

  - catkin 관련 빌드 정보 지정

 

add_library(), add_executable(), target_link_libraries()

  - 라이브러리, 실행 파일 지정

catkin_add_gtest()

  - 유닛 테스트

install()

  - 생성된 target에 대한 설치 옵션 지정

 

if 문

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()

 

for 문 

  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()

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'언어 정리 > 빌드툴(catkin_make,make,cmake)' 카테고리의 다른 글

CMake CMakeLists.txt 설명  (0) 2023.01.02
Make Makefile 설명 및 문법  (1) 2023.01.02
make -> cmake -> catkin_make  (1) 2023.01.02

댓글