find_package(Qt5Widgets REQUIRED)
if (Qt5Widgets_FOUND)
if (Qt5Widgets_VERSION VERSION_LESS 5.7.0)
message(FATAL_ERROR "Minimum supported Qt5 version is 5.70!")
endif()
else()
message(SEND_ERROR "The Qt5Widgets library could not be found!")
endif(Qt5Widgets_FOUND)
CMake Warning at CMakeLists.txt:15 (find_package):
Could not find a configuration file for package "Qt5Core" that is
compatible with requested version "5.10".
The following configuration files were considered but not accepted:
C:/some/where/lib/cmake/Qt5Core/Qt5CoreConfig.cmake, version: 5.9.4
4条答案
按热度按时间rggaifut1#
我知道这是一个有点旧的帖子,但你可以使用
Qt5Widgets_VERSION
检查版本。下面是一些CMake代码示例:qjp7pelc2#
现在可以将一个版本传递给
find_package
,如下所示:如果找不到兼容的Qt5Core版本,
find_package
调用将失败:这在https://cmake.org/cmake/help/latest/command/find_package.html#version-selection上有详细的文档
taor4pac3#
对于Qt提供的cmake包,没有直接的方法可以做到这一点,但是使用qmake查询Qt版本是很容易的。假设您在cmake文件中已经有类似于下面的内容来定位Qt安装
你可以检查版本和失败的配置步骤,如果它太低,像这样
bxjv4tth4#
一个简单的方法: