Ask for guide about updating CMakeLists.txt and package.xml

Hi there,

I noticed that I can run Python scripts without updating the CMakeLists.txt and package.xml.
I guess it is because the course environment has installed these packages.

Could you please provide a guide about updating these two files?
I took some notes during learning but not sure if it covers everything.

CMakeLists.txt

find_package(catkin REQUIRED COMPONENTS
  dependency_name # add new dependencies here
)


catkin_package(
  # INCLUDE_DIRS include  # Uncomment if you have headers in include directory
  LIBRARIES your_package_name
  CATKIN_DEPENDS dependency_name #add new dependencies here
  # DEPENDS system_lib  # Uncomment if you have dependencies on system libraries
)

catkin_install_python(PROGRAMS scripts/my_script.py 
# add Python script path for each Python script
  DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

package.xml

<build_depend>dependency_name</build_depend>

<exec_depend>dependency_name</exec_depend>

As for the customerized .msg/.srv, the guides are already very clear so I ignore them here.

Hi @min.wang.1997.01.13 , our best “guide” would be our course itself, but I understand that you want to have a quick guide, so here’s one:

  • The CMakeLists.txt file in packages is used by CMake to configure their build process. You are able to run python scripts probably only on the path where the script is, and luckily the program doesn’t depend on any other package.
  1. Find necessary packages:
cmake_minimum_required(VERSION 3.0.2)
project(your_package_name)

find_package(catkin REQUIRED COMPONENTS
  rospy
  std_msgs
  # Add other dependencies here
)
  1. Declare the catkin package:
  CATKIN_DEPENDS rospy std_msgs
  # Other dependencies
)
  1. Install python scripts:
catkin_install_python(PROGRAMS
  scripts/my_script.py
  DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
  • package.xml is used to specify package info and dependencies. The example you provide is perfect for most cases.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.