使用什么代替`qt5_use_modules`? [英] What to use instead of `qt5_use_modules`?

查看:1267
本文介绍了使用什么代替`qt5_use_modules`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Qt 5 CMake手册说明 qt5_use_modules 宏已弃用:


此宏已过时。请使用target_link_libraries与IMPORTED目标。

This macro is obsolete. Use target_link_libraries with IMPORTED targets instead.

...但 qt5_use_modules 而不是简单地指定链接库:它指定包括目录,必要的编译标志等等(参见上面链接文档中的完整描述)。

... But qt5_use_modules does more than simply specify link libraries: it specifies include directories, necessary compile flags, and more (see the full description in the linked documentation above).

变量 QTMODULES 包含一些应该用于项目的Qt模块列表,推荐方法替换以下已弃用的CMake行?

Assuming, then, that the variable QTMODULES contains some list of Qt modules that should be used for a project, what is the "recommended" way to replace the following "deprecated" CMake line?

qt5_use_modules(${myProjectName} ${QTMODULES})

以下不工作,主要是因为它没有添加任何Qt包含路径:

The following does NOT work, primarily because it does not add any Qt include paths:

    target_link_libraries(${myProjectName} IMPORTED ${QTMODULES})

QTMODULES 变量需要手动迭代,以便可以为每个单独的模块名称调用 include_directories ?这似乎是从 qt5_use_modules 向后的一个重要步骤,它很简单,只是工作。

Does the QTMODULES variable need to be manually iterated over, so that include_directories can be called for each individual module name? This seems like a major step backward from qt5_use_modules, which is simple and "just works." Am I missing something?

推荐答案

有关使用IMPORTED目标的消息实际上是指Qt5的CMake模块为您提供的生成目标,不是你应该在 target_link_libraries 宏中设置IMPORTED属性。例如:

The message about using IMPORTED targets actually refers to the generated targets that Qt5's CMake modules provide for you, not that you should be setting the IMPORTED property on the target_link_libraries macro. For example, something like:

target_link_libraries(${myProjectName} Qt5::Core Qt5::Widgets)

将会处理添加所有必要的包含路径,链接路径和库以使用 Qt5Core Qt5Widgets 模块。

will take care of adding all the necessary include paths, link paths, and libraries for using the Qt5Core and Qt5Widgets modules.

这篇关于使用什么代替`qt5_use_modules`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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