交叉编译中的CMake CMAKE_AUTOMOC [英] CMake CMAKE_AUTOMOC in cross compilation

查看:775
本文介绍了交叉编译中的CMake CMAKE_AUTOMOC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注问题。我正在尝试使用CMake中的本机机制进行交叉编译。我准备了以下toolchain.cmake文件:

I've following issue. I'm tring to use native mechanism build in CMake for cross compilation. I prepared following toolchain.cmake file:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_SYSROOT /tmp/filesystem)

set(tools /opt/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux/bin/arm-linux-gnueabihf)
set(CMAKE_C_COMPILER ${tools}-gcc)
set(CMAKE_CXX_COMPILER ${tools}-g++)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

并在目标 CMakeList.txt 被使用:

set(CMAKE_AUTOMOC ON)

我希望当我使用 CMAKE_FIND_ROOT_PATH_MODE_PROGRAM 设置为 Never 根据文档,CMake将使用 HOST 中的moc:

I expect that when I use CMAKE_FIND_ROOT_PATH_MODE_PROGRAM set to NEVER the CMake, according to documentation, will use moc from HOST:


如果设置为NEVER,则根目录为CMAKE_FIND_ROOT_PA TH将被
忽略,仅使用主机系统根目录。

If set to NEVER, then the roots in CMAKE_FIND_ROOT_PATH will be ignored and only the host system root will be used.

但是它仍然尝试使用 TARGET 手臂映像rootfs。

However it still try to use moc from TARGET arm image rootfs.

我尝试重新引用moc可执行文件,如本帖子的第一个答案:如何使用CMake包括某些Qt安装?但没有

I try to refind the moc executable like in first answer from this post: How to include a certain Qt installation using CMake? but with no luck.

我还尝试将 QT_MOC_EXECUTABLE 变量设置为从 HOST rootfs而不是 TARGET 之一,但也没有运气。我事件认为将 CMAKE_AUTOMOC 设置为 ON 时,CMake不使用此变量,因为在强制更改后此缓存变量cmake仍然使用 TARGET rootfs中的moc。

I also try to set the QT_MOC_EXECUTABLE variable to proper path from HOST rootfs instead of TARGET one but also with no luck there. I event think that this variable isn't use by CMake when CMAKE_AUTOMOC is set to ON since after forcing change this cached variable cmake still use moc from TARGET rootfs.

有什么想法可以解决此问题吗?

Any ideas how to resolve this issue?

#编辑1

我发现automoc在生成文件夹中生成了此类文件:

I found that the automoc generates such file in build folder:

CMakeFiles / * target_name * _automoc.dir / AutogenInfo.cmake

在我的情况下,此类变量设置为错误的路径:

And in my case such variable is set to wrong path:

set(AM_QT_MOC_EXECUTABLE / tmp / filesystem / usr / lib / arm- linux-gnueabihf / qt5 / bin / moc)

应为:

set(AM_QT_MOC_EXECUTABLE / usr / bin / moc)

我设置 AM_QT_MOC_EXECUTABLE 来更正主 CMakeList.txt 中的值,但仍然在从 TARGET rootfs。

I set AM_QT_MOC_EXECUTABLE to correct value in main CMakeList.txt but still after mentioned file is generated with wrong path from TARGET rootfs.

推荐答案

由于这篇文章,我终于找到了解决方案:如何将CMake的AUTOMOC功能与自定义Qt软件包一起使用?。我假设 AUTOMOC 不直接使用 QT_MOC_EXECUTABLE

I finally found the solution thanks to this post: How can I use CMake's AUTOMOC feature with a custom Qt package?. As I assumed the QT_MOC_EXECUTABLE isn't use directly by AUTOMOC.

在第一个qt find_package 之前必须添加以下行:

Before first qt find_package following lines must be added:

set(QT_MOC_EXECUTABLE /usr/bin/moc)
add_executable(Qt5::moc IMPORTED)
set_property(TARGET Qt5::moc PROPERTY IMPORTED_LOCATION ${QT_MOC_EXECUTABLE})

这里的问题是不仅变量 QT_MOC_EXECUTABLE 必须设置为适当的值但最后automoc仅使用 Qt5:moc 目标,必须在将任何qt软件包包含在 CMakeList.txt 文件。

The issue here was that not only the variable QT_MOC_EXECUTABLE has to be set to proper value but finally the automoc uses just Qt5:moc target which must be declared before any qt package will be included in CMakeList.txt file.

其他qt工具也存在此问题,因此更通用的选择是:

This same issue is with other qt tools so more generic option will be:

file(GLOB Qt_bin /usr/bin)
find_program(QT_MOC_EXECUTABLE qt_moc moc PATHS ${Qt_bin})
add_executable(Qt5::moc IMPORTED)
set_property(TARGET Qt5::moc PROPERTY IMPORTED_LOCATION ${QT_MOC_EXECUTABLE})

这篇关于交叉编译中的CMake CMAKE_AUTOMOC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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