Yocto SDK with cmake toolchain file
Asked Answered
B

2

15

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?

Bough answered 31/1, 2017 at 18:28 Comment(0)
C
22

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.

Cynthla answered 1/2, 2017 at 7:11 Comment(5)
Just one more question - is it also possible to create this file when building with bitbake meta-ide-support? I tried to create a file meta-ide-support.bbappend which sets the TOOLCHAIN_HOST_TASK, but it doesn't seem to do anything.Bough
Never tried meta-ide-support. Does it even build a toolchainOtherwise, TOOLCHAIN_HOST_TASK` won't work. Why don't you add it to your SDK-build instead of meta-ide-support?Cynthla
In the very most cases, the application is built on the same machine, on which a complete Yocto build is available. In these cases it's easier to use the toolchain and sysroot which is located inside the Yocto build directory, rather than installing a complete SDK in parallel. meta-ide-support creates a script which I can source from outside the Yocto build directory to do cross-compilations. Would be nice if that script also sets the path to the OEToolchainConfig.cmake and the cmake alias.Bough
Well, I'd personally argue the using the SDK is a good idea, but your mileage may vary. You'll likely need to hack the system a little bit to achieve what you want. As a side note, it's quite possible that you'll have to change your workflow once you update to Pyro or later (pyro is going to be released this spring). In Pyro, there won't be a global sysroot, as recipe specific sysroots have been added.Cynthla
/usr/share/cmake does not exist for me whereas /usr/share/cmake-3.10 exists. What can I do? I have nativesdk-cmake added in my image with TOOLCHAIN_HOST_TASK.Schriever
D
1

I'd like to add to Anders answer that while it worked great for me to add nativesdk-cmake this way it did not work when I tried to add nativesdk-python3-numpy. After some googling I found this, suggesting that TOOLCHAIN_HOST_TASK has to be extended using _append instead of +=.

Documentation answered 30/4, 2020 at 7:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.