Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yocto SDK with cmake toolchain file

I provide a Yocto SDK to cross-build an application for an embedded target. The application itself is built using CMake. The SDK setup script provides many necessary environment variables (like location of the cross-compiler, sysroot, etc.), which so far was enough to build the application.

However, since recently the application has a dependency to the Boost library (through the command find_package(Boost REQUIRED) in the CMakeLists.txt). Now CMake complains that it cannot find the library, even though it's installed in the SDK sysroot. But if I build the application directly in Yocto, it works fine.

After some research it turned out that Yocto generates a toolchain.cmake file which is added to the cmake call. In this file, the variable CMAKE_FIND_ROOT_PATH is set, which CMake needs to find libraries. Using such a toolchain file, I can also build using the SDK.

Now I'm wondering if Yocto provides any mechanism to export such a toolchain file with the SDK. Or alternatively if the SDK provides a script or something to automatically create a toolchain file directly on the SDK build host.

Or shall I just tell the users of the SDK to manually create a toolchain file and add it to their cmake call?

like image 394
Georg P. Avatar asked Jan 31 '17 18:01

Georg P.


People also ask

How do you use CMake in yocto?

cpp contains the code that outputs "Hello World". The Yocto build system contains classes to support building CMake packages. To use CMake in a recipe you need to inherit the CMake class. Generally the CMake build system knows how to install the software so a overwrite over do_install is not necessary.

Is yocto a toolchain?

The Yocto Project provides an application development environment based on an Application Development Toolkit (ADT) and the availability of stand-alone cross-development toolchains and other tools.

What is a Yocto SDK?

The SDK is installed on any machine and can be used to develop applications, images, and kernels. An SDK can even be used by a QA Engineer or Release Engineer. The fundamental concept is that the machine that has the SDK installed does not have to be associated with the machine that has the Yocto Project installed.


1 Answers

Assuming that you're using the image based SDK, i.e. building it with bitbake <image> -c populate_sdk, adding the following toimage.bb should fix it:

TOOLCHAIN_HOST_TASK += "nativesdk-cmake"

That should give you a OEToolchainConfig.cmake file in the SDK. After sourcing the SDK environment file, cmake will be an alias to cmake -DCMAKE_TOOLCHAIN_FILE=$OECORE_NATIVE_SYSROOT/usr/share/cmake/OEToolchainConfig.cmake to further help your developers.

like image 75
Anders Avatar answered Sep 22 '22 11:09

Anders