CMake 找不到 Qt5QuickCompiler

CMake doesn't find Qt5QuickCompiler

我正在尝试使用 CMake 构建一个 Qt Quick Controls 应用程序。我使用以下文档:

http://doc.qt.io/QtQuickCompiler/qquickcompiler-building-with-cmake.html

当 运行ning CMake 时,我收到此错误:

By not providing "FindQt5QuickCompiler.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "Qt5QuickCompiler", but CMake did not find one.

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

    Qt5QuickCompilerConfig.cmake
    qt5quickcompiler-config.cmake

在这一行:

FIND_PACKAGE(Qt5QuickCompiler)

显然 CMake 没有找到 Qt5QuickCompiler。我检查了我的 Qt 文件夹 (C:\Qt),但它不在那里。但是我可以 运行 这个应用程序 QMake.

我需要设置什么才能找到Qt5QuickCompiler

错误很明显:CMake 没有供 Qt5QuickCompiler 找到的模块。它只是不知道它是什么。我刚刚检查了相应的 cmake 文件夹,它没有那个文件。我不确定 Qt 文档页面在谈论什么,但 CMake 发行版中没有这样的文件。也许 Qt 资源在某处有这个文件?

您需要使用 Qt Quick 编译器构建 Qt5,您可以从 http://www.qt.io/qt-quick/ 下载该编译器。在Qt Quick编译器的build目录下,你会发现Qt5QuickCompilerConfig.cmake.
把路径复制到这个目录,然后像这样添加到CMAKE_PREFIX_PATH

cmake -DCMAKE_PRFEIX_PATH=<pathToFile> <pathToSrcDirOfYourProject>

我刚刚在 Linux 下偶然发现了与 Qt 5.12 相同的问题。 https://doc.qt.io/QtQuickCompiler/qquickcompiler-building-with-cmake.html下的文档目前好像有错

在 Qt5 find_package 中的 COMPONENTS 之后使用 QuickCompiler 而不是尝试通过 find_package(Qt5QuickCompiler) 添加它。改编 link 中的示例,使用

find_package(Qt5 COMPONENTS Quick Core Network QuickCompiler)
qtquick_compiler_add_resources(RESOURCES example.qrc)
add_executable(myapp ${SRC_LIST} ${RESOURCES)

而不是

find_package(Qt5 COMPONENTS Quick Core Network)
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources(RESOURCES example.qrc)
add_executable(myapp ${SRC_LIST} ${RESOURCES)