Hi,
I hope I can help you to create CMakeLists.txt files for your ROS projects. Please let me know if I miss some information you are looking for.
Firstly, you can specify dependencies when you call catkin_create_pkg
on the command line so that not only will the components be automatically included in the find_package
call but the file package.xml will also be updated correctly. If you want to create a new package based on C++, then enter catkin_create_pkg <your new package name> roscpp
on the command line and roscpp will be included in find_package
automatically. A number of other packages can also be listed at the end of catkin_create_pkg
, separated by spaces, to include them too. If you want to also include compiled Boost libraries such as filesystem, then you enter catkin_create_pkg -b filesystem<your new package name> roscpp
on the command line.
Now if I want to run the new C++ codes for which components I don't know, should I have to guess components form #include statements of cpp file?
If you are creating your own ROS project from scratch, you should know which libraries you will be using, but you may not know the CMake components, of which there could be many. When you're going to be using MoveIt, your project will depend on the moveit_core
, moveit_msgs
, and moveit_ros_planning_interface
components. You can see all the components for major ROS libraries at the top of their wiki page as links separated by |. Each component will have its own sub-dependencies too. If you are using someone else's code in your project, you may have to look inside the #include
statements they use to know which libraries you will depend on; however, the original author should also provide a list of dependencies on GitHub or wherever the code was shared.
Unfortunately, I don't know of any tool that will scan #include
statements in C++ files to determine appropriate catkin components. I think it would definitely be possible to make such a tool though, and it would be useful!
Finally, you don't have to worry about including certain components, especially Boost libraries like bind, explicitly in your CMakeLists.txt because they are most likely included automatically when you specify other components like roscpp. I usually add all the components I think I will need to find_package
then build and see if any errors appear, which will let me know I am still missing a component.