在 Yocto 中使用 Cmake 构建 Qt5

Build Qt5 with Cmake in Yocto

我们正在 Yocto/Bitbake 使用 CMake for Cortex ARM 9 交叉编译我们的 Qt5 应用程序。

无论我做什么,我都无法让 Cmake 找到所需的 Qt5Config.cmake 配置文件。

错误消息众所周知:

 CMake Error at CMakeLists.txt:71 (find_package):
 By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
 asked CMake to find a package configuration file provided by "Qt5", but
 CMake did not find one.

 Could not find a package configuration file provided by "Qt5" with any of
 the following names:

     Qt5Config.cmake
     qt5-config.cmake

 Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
 to a directory containing one of the above files.  If "Qt5" provides a
 separate development package or SDK, be sure it has been installed.

 -- Configuring incomplete, errors occurred!

到目前为止,收件人似乎还不错。我依赖 Qt 并通过以下方式使用 Cmake:

RDEPENDS_${PN} += " qtconnectivity "
inherit pkgconfig cmake

不幸的是,我不确定两件事:

  1. 当我构建 Yocto(在 2 个内核上)时,为什么 bitbake 在我的错误配方之前或同时构建 qt5 包?依赖关系不应该解决这个问题吗?我也尝试使用 DEPENDS 而不是 RDEPENDS,但这并没有什么区别。

  2. 我不知道 Qt 安装在哪个 sysroots 中。当我做 find . -name Qt5Config.cmake 时,我发现了很多地方。其中一个地方看起来比其他地方更有希望。它是:./tmp/sysroots-components/cortexa9hf-neon-mx6qdl/qtbase/usr/lib/cmake/Qt5/Qt5Config.cmake。但是,Qt 库不应该在 "my recipe" 的 sysroot 中吗?

所以,毕竟,我尽量让CMake知道Qt5Config.cmake的位置。我尝试通过设置

export Qt5_DIR = "/home/vagrant/build/tmp/sysroots-components/cortexa9hf-neon-mx6qdl/qtbase/usr/lib/cmake/Qt5/"

在配方中,可以通过 CMake 输出确认它知道路径 Qt5_DIR。在 CMake 中设置路径(使用 set(Qt5_DIR ...))也无​​济于事。

路径仍然未知。即使我现在很乐意让 CMake 了解 Qt5 在哪里 - 似乎配置错​​误,因为我认为我的食谱应该自动知道 Qt。

我还能尝试什么?

终于抽出时间来回答了。我有一段时间遇到同样的问题并发现了 cmake_qt5 bitbake class。

使用此 class 代替 cmake 应该填充在 Yocto 项目中将 Qt5 与 CMake 一起使用所需的所有必要标志。