带有 cmake 工具链文件的 Yocto SDK [英] Yocto SDK with cmake toolchain file

查看:53
本文介绍了带有 cmake 工具链文件的 Yocto SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提供了一个 Yocto SDK 来为嵌入式目标交叉构建应用程序.应用程序本身是使用 CMake 构建的.SDK 设置脚本提供了许多必要的环境变量(如交叉编译器的位置、sysroot 等),到目前为止已经足够构建应用程序了.

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.

然而,最近应用程序依赖于 Boost 库(通过 CMakeLists.txt 中的命令 find_package(Boost REQUIRED)).现在 CMake 抱怨它找不到库,即使它安装在 SDK sysroot 中.但是如果我直接在 Yocto 中构建应用程序,它就可以正常工作.

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.

经过一番研究,发现 Yocto 生成了一个 toolchain.cmake 文件,该文件被添加到 cmake 调用中.在这个文件中,设置了变量CMAKE_FIND_ROOT_PATH,CMake需要它来查找库.使用这样的工具链文件,我也可以使用 SDK 进行构建.

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.

现在我想知道 Yocto 是否提供任何机制来使用 SDK 导出此类工具链文件.或者,如果 SDK 提供脚本或其他东西来直接在 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.

或者我应该告诉 SDK 的用户手动创建一个工具链文件并将其添加到他们的 cmake 调用中?

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

推荐答案

假设您使用的是基于图像的 SDK,即使用 bitbake <image> 构建它-c populate_sdk,将以下内容添加到image.bb 应该可以修复它:

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"

这应该会在 SDK 中为您提供一个 OEToolchainConfig.cmake 文件.获取 SDK 环境文件后,cmake 将成为 cmake -DCMAKE_TOOLCHAIN_FILE=$OECORE_NATIVE_SYSROOT/usr/share/cmake/OEToolchainConfig.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.

这篇关于带有 cmake 工具链文件的 Yocto SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆