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?

2 Answers 2

21

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.

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.
    – Georg P.
    Feb 1, 2017 at 10:02
  • 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?
    – Anders
    Feb 1, 2017 at 12:36
  • 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.
    – Georg P.
    Feb 1, 2017 at 12:52
  • 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.
    – Anders
    Feb 1, 2017 at 13:30
  • /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. Mar 25, 2018 at 13:55
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 +=.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.