mysql交叉编译 cmake,交叉编译中的CMake CMAKE_AUTOMOC

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)

and in target CMakeList.txt is use:

set(CMAKE_AUTOMOC ON)

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:

If set to NEVER, then the roots in CMAKE_FIND_ROOT_PATH will be

ignored and only the host system root will be used.

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

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.

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?

# EDIT 1

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")

should be:

set(AM_QT_MOC_EXECUTABLE "/usr/bin/moc")

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.

解决方案

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.

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})

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.

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})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值