简体   繁体   English

在带有 vcpkg static 导出的 CMake 项目中找不到“Qt5”

[英]'Qt5' not found in CMake project with vcpkg static export

I wanna create a project use VSCode+CMake+VCPKG(VTK+Qt5) And I still want to share my VCPKG depencies with teammate.我想创建一个使用 VSCode+CMake+VCPKG(VTK+Qt5) 的项目而且我仍然想与队友分享我的 VCPKG 依赖。 So I export VCPKG.所以我导出 VCPKG。

When I try to find_package(Qt5 COMPONENTS Core REQUIRED) problem happened当我尝试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.

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

There is no Qt5Config.cmake to let cmake read!!没有Qt5Config.cmake让cmake读取!!

在此处输入图像描述

That's what inside.里面就是这样。

How can I exactly use Qt5 And set include file directories in cmakelist.txt?如何准确使用 Qt5 并在 cmakelist.txt 中设置包含文件目录?

Finally, I found how to make it Add script in CMALKELIST.txt最后,我找到了如何在 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 "")

and to add Qt compoment, cause Qt package is divide to many bit.并添加 Qt 组件,导致 Qt package 被划分为多个位。 So use COMPOMENTS with Qt package you want to include.因此,将COMPOMENTS与您想要包含的 Qt package 一起使用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM