使用Qt的CMake包括模块xmlpatterns [英] CMake with Qt to include modules xmlpatterns

查看:474
本文介绍了使用Qt的CMake包括模块xmlpatterns的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从QMake切换到CMake。我收到这样的第一个错误:

I am trying to switch from QMake to CMake. I get my first error like this:

Target "aacmakeqt" links to target "Qt::xmlpatterns" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?

我想知道如何知道或找到模块的名称吗?为什么是 find_package(Qt5Widgets)而不是 find_package(Qt5widgets)
为什么是 target_link_libraries(项目Qt5 :: Widgets),而不是 Qt5 :: widgets Qt5Widgets ?在哪里可以找到这些信息?而最重要的是如何使用 Qt XML模式

I wonder how to know or find the name of the module? Why it is find_package(Qt5Widgets) but not find_package(Qt5widgets)? Why it is target_link_libraries(project Qt5::Widgets) but not Qt5::widgets or Qt5Widgets? Where can I find these information? And the most important is how to use link the Qt XML Patterns?

我在QtCreator中的.pro文件

My .pro file in QtCreator

#-------------------------------------------------
#
# Project created by QtCreator 2015-11-07T19:23:43
#
#-------------------------------------------------   
QT       += core gui xmlpatterns widgets

TARGET = myapp
TEMPLATE = app

SOURCES += main.cpp ......... 
HEADERS  += mainwindow.h ........
FORMS    += mainwindow.ui ........
RESOURCES += resources.qrc

我的CMakeList文件

My CMakeList File

cmake_minimum_required(VERSION 3.0)

## Setting ProjectId by current directory
get_filename_component(ProjectId ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" ProjectId ${ProjectId})
MESSAGE(STATUS "\tProjectId: " ${ProjectId} ) ## Debug Message

## Defining project
project(${ProjectId})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Find the library
find_package(Qt5Widgets)
find_package(Qt5Xmlpatterns)

MESSAGE(STATUS "Project Source Directory: " ${PROJECT_SOURCE_DIR} ) ## Debug Message

file(GLOB_RECURSE SRC_CPP ${PROJECT_SOURCE_DIR} *.cpp)
MESSAGE(STATUS "\tsource: " ${SRC_CPP}) ## Debug Message
add_executable(${ProjectId} ${SRC_CPP})

# Use the Widgets module from Qt 5.
target_link_libraries(${ProjectId} Qt5::Widgets)
target_link_libraries(${ProjectId} Qt5::xmlpatterns)

解决方案:

<$ c提供了更详细的错误消息$ c> find_package(需要Qt5XmlPatterns),我了解CMake无法找到 Qt5XmlPatternsConfig.cmake qt5xmlpatterns-config.cmake

With a more detailed error message provided by find_package(Qt5XmlPatterns REQUIRED), I understanding CMake cannot find either Qt5XmlPatternsConfig.cmake or qt5xmlpatterns-config.cmake.

所需的 .cmake 文件应随Qt一起提供。事实证明,我的Qt目录位于我的主目录中,而不是 \usr\lib 。 (我不知道这是怎么发生的。我应该使用默认选项安装Qt。)

The required .cmake files should come with Qt. It turns out that my Qt directory is located in my home directory rather than \usr\lib. (I don't know how this happen. I should have install Qt with default options.)

因此,我只是帮助cmake找到正确的目录。就我而言,位于〜/ Qt5.5.1 / 5.5 / gcc_64 / lib / cmake .cmake 文件c>。
根据文档 find_package 进行搜索 CMAKE_PREFIX_PATH CMAKE_FRAMEWORK_PATH CMAKE_APPBUNDLE_PATH 依次返回软件包。所以我只需添加

So, I simply help cmake to locate the correct directory. In my case, all the .cmake files for Qt located under ~/Qt5.5.1/5.5/gcc_64/lib/cmake. Base on the document for find_package, it searches CMAKE_PREFIX_PATH CMAKE_FRAMEWORK_PATH CMAKE_APPBUNDLE_PATH for packages in turn. So I just add

set(CMAKE_FRAMEWORK_PATH ${CMAKE_FRAMEWORK_PATH} "~/Qt5.5.1/5.5/gcc_64/lib/cmake")

,以便正确搜索。

最后,我们可以在 Your_Qt_Install_directory / Qt5.5.1 / 5.5 / gcc_64 / lib / cmake 下找到包的名称。

Finally, we can find the name of the package under Your_Qt_Install_directory/Qt5.5.1/5.5/gcc_64/lib/cmake".

推荐答案

使用

find_package(Qt5XmlPatterns REQUIRED)

然后

target_link_libraries(name Qt5::XmlPatterns)

find_package中出现错误的情况需要也可以做到。

这篇关于使用Qt的CMake包括模块xmlpatterns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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