How to Complete CMakeLists.txt and package.xml
In ROS developing, CMakelists.txt
and package.xml
are two important files to build a package. Only the files under your package direcotry need to be modified. Since you are not sure what dependencies you are going to use at the beginning, therefore in real developing process the CMakeLists.txt
and package.xml
writing can’t be done completely by catkin_create_pkg
.
CMakeLists.txt
Here are several basic commands:
Function | Command | Usage |
---|---|---|
Environment Configuration | cmake_minimum_required(VERSION x.x.x) | Set up the minimum version of CMake installed on your computer |
Environment Configuration | project(xxx) | Package name (automatiaclly generated by ROS) |
Find dependencies | find_package(XX REQUIRED xxx) | Normally catkin is necessary |
Add executable targets | add_executable(EXEC FILES) | EXEC-executable file name; FILES-all compilation units (.cpp) |
Add target library | add_library(LIB FILES) | LIB-library name; FILES-all compilation units (.cpp) |
Link libraries | target_link_libraries(EXEC LIB) | EXEC-executable file name;LIB-library name |
Include header files | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) | CMAKE_CURRENT_SOURCE_DIR=PACKAGE/src |
For complete tutorials, go to ROS wiki — CMakeLists.txt for further info.
Here we find that somewhere has
#
commented, somewhere has##
commented, somewhere has no comment. This a small trick:
- No comment———This part is indispensible. You’d better not comment them or your project can’t be made.
#
commented——This part is optional, you can uncomment them when you need.##
commented—–This part is the real comment. Don’t uncomment them.