Gtest With Cmake

broken image


Note: This tutorial assumes that you have completed the previous tutorials: creating a ROS package.
Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.
Description:

Cd /usr/src/gtest sudo mkdir build && cd build sudo cmake. Sudo make install the build dir can be put anywhere, such as /tmp/build or /build. The above configuration enables testing in CMake, declares the C test binary you want to build (hellotest), and links it to GoogleTest (gtestmain). The last two lines enable CMake's test runner to discover the tests included in the binary, using the GoogleTest CMake module. Now you can build and run your test: myproject$ cmake -S.

This tutorial covers the toolchain to build a package.
With
  1. I suppose the best move is to update to be compatible (no warnings) with new versions of CMake while still supporting CMake 2.8 for compatibility. As for needing to update all four gtest/gmock targets that is because of a change in version 1.7. Rather than having the other targets link against gtest they all compile it in directly.
  2. Cmake是Linux(这里默认是Ubuntu系统)下常使用的编译C的工具,而使用cmake就需要先在CmakeLists.txt文件中对编译规则进行。 这里介绍常用的三种指令 addlibrary 、 targetlinklibraries 和 linkdirectories ,该 笔记 主要参考了 cmake 官网给的教程,如有需要请访问以下网址.

Tutorial Level: BEGINNER
Next Tutorial:Understanding ROS Nodes

Contents

  1. Building Packages

Building Packages

As long as all of the system dependencies of your package are installed, we can now build your new package.

Note: If you installed ROS using apt or some other package manager, you should already have all of your dependencies.

Before continuing remember to source your environment setup file if you have not already. On Ubuntu it would be something like this:

Using catkin_make

catkin_make is a command line tool which adds some convenience to the standard catkin workflow. You can imagine that catkin_make combines the calls to cmake and make in the standard CMake workflow.

Usage:

For people who are unfamiliar with the standard CMake workflow, it breaks down as follows:

Note: If you run the below commands it will not work, as this is just an example of how CMake generally works.

This process is run for each CMake project. In contrast catkin projects can be built together in workspaces. Building zero to many catkin packages in a workspace follows this work flow:

The above commands will build any catkin projects found in the src folder. This follows the recommendations set by REP128. If your source code is in a different place, say my_src then you would call catkin_make like this:

Note: If you run the below commands it will not work, as the directory my_src does not exist.

For more advanced uses of catkin_make see the documentation: catkin/commands/catkin_make

Building Your Package

If you are using this page to build your own code, please also take a look at the later tutorials (C++)/(Python) since you may need to modify CMakeLists.txt.

You should already have a catkin workspace and a new catkin package called beginner_tutorials from the previous tutorial, Creating a Package. Go into the catkin workspace if you are not already there and look in the src folder:

You should see that there is a folder called beginner_tutorials which you created with catkin_create_pkg in the previous tutorial. We can now build that package using catkin_make:

Gtest Cmake Find_package

You should see a lot of output from cmake and then make, which should be similar to this:

Note that catkin_make first displays what paths it is using for each of the 'spaces'. The spaces are described in the REP128 and by documentation about catkin workspaces on the wiki: catkin/workspaces. The important thing to notice is that because of these default values several folders have been created in your catkin workspace. Take a look with ls:

The build folder is the default location of the build space and is where cmake and make are called to configure and build your packages. The devel folder is the default location of the devel space, which is where your executables and libraries go before you install your packages.

Contents

  1. Building Packages
Example
  1. I suppose the best move is to update to be compatible (no warnings) with new versions of CMake while still supporting CMake 2.8 for compatibility. As for needing to update all four gtest/gmock targets that is because of a change in version 1.7. Rather than having the other targets link against gtest they all compile it in directly.
  2. Cmake是Linux(这里默认是Ubuntu系统)下常使用的编译C的工具,而使用cmake就需要先在CmakeLists.txt文件中对编译规则进行。 这里介绍常用的三种指令 addlibrary 、 targetlinklibraries 和 linkdirectories ,该 笔记 主要参考了 cmake 官网给的教程,如有需要请访问以下网址.

Tutorial Level: BEGINNER
Next Tutorial:Understanding ROS Nodes

Contents

  1. Building Packages

Building Packages

As long as all of the system dependencies of your package are installed, we can now build your new package.

Note: If you installed ROS using apt or some other package manager, you should already have all of your dependencies.

Before continuing remember to source your environment setup file if you have not already. On Ubuntu it would be something like this:

Using catkin_make

catkin_make is a command line tool which adds some convenience to the standard catkin workflow. You can imagine that catkin_make combines the calls to cmake and make in the standard CMake workflow.

Usage:

For people who are unfamiliar with the standard CMake workflow, it breaks down as follows:

Note: If you run the below commands it will not work, as this is just an example of how CMake generally works.

This process is run for each CMake project. In contrast catkin projects can be built together in workspaces. Building zero to many catkin packages in a workspace follows this work flow:

The above commands will build any catkin projects found in the src folder. This follows the recommendations set by REP128. If your source code is in a different place, say my_src then you would call catkin_make like this:

Note: If you run the below commands it will not work, as the directory my_src does not exist.

For more advanced uses of catkin_make see the documentation: catkin/commands/catkin_make

Building Your Package

If you are using this page to build your own code, please also take a look at the later tutorials (C++)/(Python) since you may need to modify CMakeLists.txt.

You should already have a catkin workspace and a new catkin package called beginner_tutorials from the previous tutorial, Creating a Package. Go into the catkin workspace if you are not already there and look in the src folder:

You should see that there is a folder called beginner_tutorials which you created with catkin_create_pkg in the previous tutorial. We can now build that package using catkin_make:

Gtest Cmake Find_package

You should see a lot of output from cmake and then make, which should be similar to this:

Note that catkin_make first displays what paths it is using for each of the 'spaces'. The spaces are described in the REP128 and by documentation about catkin workspaces on the wiki: catkin/workspaces. The important thing to notice is that because of these default values several folders have been created in your catkin workspace. Take a look with ls:

The build folder is the default location of the build space and is where cmake and make are called to configure and build your packages. The devel folder is the default location of the devel space, which is where your executables and libraries go before you install your packages.

Contents

  1. Building Packages

Building Packages

Once all the system dependencies are installed, we can build our package that we just created.

Using rosmake

rosmake is just like the make command, but it does some special ROS magic. When you type rosmake beginner_tutorials, it builds the beginner_tutorials package, plus every package that it depends on, in the correct order. Since we listed rospy, roscpp, and std_msgs as dependencies when creating our ROS package, these packages (and their dependiencies, and so on) will be built by rosmake as well.

Usage:

Link Gtest In Cmake

Try:

This previous command may take a while to finish. As it is running you should see some output like:

On Fuerte, since dependencies are greatly reduced, this takes almost no time and produces:

rosmake multiple packages

We can also use rosmake to build multiple packages at once.

Usage:

Gtest Cmakelists

Review

Gtest With Cmake Crack

Lets just list some of the commands we've used so far:

Gtest With Cmake Tv

  • rosdep = ros+dep(endencies) : a tool to install package dependencies
  • rosmake = ros+make : makes (compiles) a ROS package

Using Gtest With Cmake

Now that you have built your ROS package let's talk more about ROS Nodes.





broken image