The Catkin_make of Ros is compiled by way of _cmake

Source: Internet
Author: User
Tags gstreamer
Catkin_make how to compile the entire workspace package.

①GCC is the GNU Compiler Collection (GNU compiler Suite), or simply a compiler, you can call GCC directly when you have a source file;

② But when your program contains a number of source files, the GCC command to compile one at a time, you are easily confused and the workload is high, you need make tools, but make itself does not compile and link the function, Instead, they are compiled and linked by calling a user-specified command in the makefile file in a way that is similar to batch processing.

What ③makefile is. Simply like a cookbook, make tools are like cooks, cooks know what to do with a recipe, and the making tool compiles and links to the commands in makefile.

④makefile in some simple works can be artificial hand, but when the project is very large, handwritten makefile is also very troublesome, if a platform makefile to be changed again.

⑤ This is the time to cmake this tool, CMake can be more simple to generate makefile files to make. Of course, CMake can also build a platform to use the makefile, you do not have to modify your own.

⑥cmake according to what generate makefile it. It is also based on the CMakeLists.txt file to generate makefile, the CMakeLists.txt. We should be more familiar with it, that is, we create a new software package automatically help us generate.

⑦ the Last Catkin_make is the compilation of CMake and make a package of instruction tools, standardize the work path and the path to generate files, And when creating a new workspace, we create a top-level CMakeLists.txt file that recursively looks for all the packages in the current workspace and compiles each package CMakeLists.txt in turn. Cmakelist is dependent on the ROS compilation package

# Top
cmake_minimum_required (VERSION 2.8.3)
Project (GSCAM)//Represents the name of the current package
How to find a link library find_package (pkgconfig) pkg_check_modules

Their grammatical rules find_package (<name>[version] [EXACT] [QUIET] [No_module] [[REQUIRED | Components] [componets ...]] )

Name and version are the names and versions of libraries
The arguments that follow
EXACT requires that the version number must match exactly
QUIET is not found and there is no warning message, the switch will not be detected when there is no warning message
REQUIRED If the report is not found, the CMake process terminates and outputs a warning message (stating that the module is necessary for the project)
After the Components components option, you can list some of the package-dependent (components list) parts

For example
Find_package (Pkgconfig) #查找PkgConfig所指向库文件和头文件

Find_package (Catkin REQUIRED
Components Roscpp Image_transport sensor_msgs Nodelet
Camera_calibration_parsers Camera_info_manager
) Pkg_check_modules (<prefix>[quiet] [REQUIRED] <MODULE>)

To detect all modules.

PREFIX a custom prefix, which can be used to represent the corresponding module after it has been found.
Quiet/required similar to the previous

The difference between quiet/required and
If not found, one will not complain, then proceed, one will warn, and terminate CMake
If you look for it, you can use the following variables in either mode

<name>_found
<name>_include_dirs or <name>_includes//header files
<name>_libraries or < Name>_libraries or <name>_libs//library file
<name>_definitions

Look at a more typical example.
The implementation of the function is in the ROS project, the use of GStreamer library
First consider gstreamer-1.0, then consider gstreamer-0.10, if not, CMake will not go on,
No matter which one of the following
Behind the
Catkin_package can depends GSTREAMER Gst_app
Include_directories can contain ${gst_app_include_dirs}
Add_library can contain ${gstreamer_libraries} ${gst_app_libraries}

 # System Dependencies find_package (pkgconfig) #查找PkgConfig所指向库文件和头文件 #通过PkgConfig的环境变量下配置的 XX.PC manages many of the Software's library and header files Pkg_check_modules (GSTREAMER QUIET gstreamer-0.10) # looks up the gstreamer-0.10 module and customizes the prefix GSTREAMER if (not gstreamer_found) #如果找的 , of course you can use Gstreamer_found, or even the back of the _include_dirs, not found of course is not gstreamer_found set (gstreamer_version_1_x TRUE) # Set a variable gstreamer_version_1_x = 1 endif () if (gstreamer_version_1_x) #GSTREAMER_VERSION_1_x为真, indicating no gstreamer-0.10 messag E (STATUS "GST 1.0") #暂且先把消息类型为STATUS类型的消息设置为 "GST 1.0" pkg_check_modules (GSTREAMER REQUIRED gstreamer-1.0) pkg_check_                      Modules (Gst_app REQUIRED gstreamer-app-1.0) #再查找一下gstreamer -1.0,gstreamer-app-1.0 This time the condition for the lookup is REQUIRED else () #GSTREAMER_VERSION_1_x为假, note that there is a gstreamer-0.10 message (STATUS "GST 0.1") pkg_check_modules (GSTREAMER REQUIRED gstr eamer-0.10) pkg_check_modules (Gst_app REQUIRED gstreamer-app-0.10) #再查找一下gstreamer -0.10,gstreamer-app-0.10 The condition for this return lookup is required endif () 
Add dependent libraries Find_package Catkin_package

The find_package command is common cmake and are needed to-load the Catkin macros and specify dependencies to other ROS PAC Kages.

  Find_package (Catkin REQUIRED 
    components roscpp image_transport sensor_msgs nodelet
    camera_calibration_ Parsers Camera_info_manager
    )
###################################
# Catkin specific configuration # #
################################## # #
# The Catkin_package macro generates cmake config files for your package
# Declare Things to be passed to Depe Ndent Projects
# Include_dirs:uncomment This if your package contains header files
# # libraries:libraries you c Reate in this project that dependent projects also need # Catkin_depends:catkin_packages dependent projects also nee
D
# # Depends:system dependencies of this project so dependent projects also need Catkin_package
(
#  in Clude_dirs include
#  libraries Gstcamera
#  catkin_depends other_catkin_pkg
#  Depends System_lib
)
  Catkin_package (
    include_dirs INCLUDE
    libraries Gscam
    catkin_depends roscpp nodelet image_transport Sensor_msgs
    camera_calibration_parsers camera_info_manager
    depends GSTREAMER Gst_app
    )

Some parameters of Catkin_package
Macro defined in Catkin_package.cmake
Parameters
Include_dirs under current project include
–cmake_current_source_dir-relative paths to C + + includes

Libraries and find_package the same ROS internal-dependent libraries
–names of library targets that would appear in the catkin_libraries and ${project_name}_libraries of other projects that s Earch for your via find_package. #CATKIN_DEPENDS –a List of Catkin projects which this project depends on.

External libraries for depends engineering dependencies
–a List of CMake projects which this project depends on. Add header file, library file, executable header file to project

  Include_directories (
    include # under current project include
    ${catkin_include_dirs}  #<name_include_dirs>
    $ {Glib_include_dirs}
    ${gst_app_include_dirs})
Library files

Add a library to the project using the specified source files.

Link a target to given libraries. Usually after the add_library,add_executable.

  Add_library (Gscam src/gscam.cpp)
  target_link_libraries (Gscam
    ${catkin_libraries}
    ${gstreamer_ Libraries}
    ${gst_app_libraries})
Executable file
  Add_executable (Gscam_node src/gscam_node.cpp)
  target_link_libraries (Gscam_node gscam ${catkin_LIBRARIES
    }
    ${gstreamer_libraries}
    ${gst_app_libraries})
  set_target_properties (Gscam_node properties Output_ Name Gscam)
 #变更target的属性 Here's the name of the change.
Install

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.