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

环境 qt5.12.3  deepin15.10

cmake构建

由于之前使用的是仓库自带的qt环境,后来需要更高版本qt,于是从官网下载安装器自己安装,重新构建之后便出现这个问题,具体报错如下

CMake Warning at src/CMakeLists.txt:45 (find_package):
  By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Qt5", but
  CMake did not find one.

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

    Qt5Config.cmake
    qt5-config.cmake

  Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
  to a directory containing one of the above files.  If "Qt5" provides a
  separate development package or SDK, be sure it has been installed.

我去翻看了cmake官方文档,然后看到一篇文章才明白,cmake在find_package的时候需要提供对应模块的*.cmake文件,根据推测要么是cmake自己提供,显然不是,于是在我的qt安装目录下找到相应目录提供给cmake查找

在我的qt安装路径下的"/opt/Qt/5.12.3/gcc_64/lib/cmake"里面便可以找到提供给cmake的各个模块的文件夹,每个文件夹下提供了对应的*.cmake文件。这篇文章给我的答案:https://stackoverflow.com/questions/15639781/how-to-find-the-qt5-cmake-module-on-windows#

我是这样做的

set(CMAKE_PREFIX_PATH "/opt/Qt/5.12.3/gcc_64")
为每个模块提供*.cmake文件搜索路径
set(Qt5_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5")
set(Qt5Widgets_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5Widgets")
set(Qt5Network_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5Network")
set(Qt5LinguistTools_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5LinguistTools")
然后查找
find_package(Qt5 COMPONENTS Widgets Network LinguistTools)

 

posted @ 2019-05-07 15:08  梁子~  阅读(18338)  评论(1编辑  收藏  举报