【问题标题】:'Qt5' not found in CMake project with vcpkg static export在具有 vcpkg 静态导出的 CMake 项目中找不到“Qt5”
【发布时间】:2024-01-12 14:40:01
【问题描述】:

我想创建一个项目使用 VSCode+CMake+VCPKG(VTK+Qt5) 而且我仍然想与队友分享我的 VCPKG 依赖关系。 所以我导出了 VCPKG。

当我尝试find_package(Qt5 COMPONENTS Core REQUIRED) 时发生问题

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.

我尝试set(Qt5_DIR "{vckpg_root_path}\installed\x64-windows\share\qt5")

没有Qt5Config.cmake可以让cmake读取!!

里面就是这样。

我怎样才能准确地使用 Qt5 并在 cmakelist.txt 中设置包含文件目录?

【问题讨论】:

  • Qt5Config 通常在 lib/cmake 文件夹下。我通常倾向于自己构建 QT,所以不确定 vcpkg 版本。

标签: c++ windows qt visual-studio-code cmake


【解决方案1】:

终于找到了制作方法 在 CMALKELIST.txt 中添加脚本

cmake_minimum_required(VERSION 3.0.0)
set(VCPKG_DIR "C:/vcpkg/installed/x64-windows")
set(VCPKG_TARGET_TRIPLET "x64-windows"
      CACHE STRING "")
set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
      CACHE STRING "")

并添加Qt组件,导致Qt包被分成许多位。 因此,请将COMPOMENTS 与您想要包含的 Qt 包一起使用。

find_package(Qt5 COMPONENTS Core Widgets CONFIG REQUIRED)
if (${Qt5Core_FOUND})
    message("Found Qt " ${Qt5_VERSION})
else()
    message("Couldn't find Qt")
endif()

【讨论】: