Using CMake With The SDK


Although Yocto seems to use Autotools more than CMake, you can easily configure a generated Yocto SDK to include all the neccessary tools so that you can build a targeted software application using CMake instead (which, IMO, is much better than Autotools).

Add CMake To The Yocto SDK

This first thing is to add the CMake binary to the Yocto SDK. This version of CMake will be set up exactly as needed to build applications for your target architecture (which is typically not the same as your host/development system!).

Add the following line to your local.conf:

Then rebuild the SDK command with:

Replacing core-image-minimal with a different target if needed.

Install The New SDK

Now install the new SDK:

The new SDK should contain cmake.

Source Environment Variables And Build

Because you are now going to be using a custom version of cmake, you don’t have to modify the CMakeLists.txt of the project you are building!

Before building, source the environment setup script.

This will create an alias to cmake. You can check this by running the command which cmake.

Now go to the root directory of the CMake project you wish to build and use the standard CMake process as below:

The above assumes CMake will use make to do the actual building, but this could be different.