Issue
I'm using CMake to build a Qt project, and it uses some of the newer Qt features and requires at least version 5.3 to build properly. I'd like to be nice to the people trying to build the project and fail at CMake configure time with a logical error telling them their CMake version isn't recent enough, rather than with some esoteric build error.
I know that I'll be getting at least version 5.0 by simply using the module find_package
syntax (i.e. find_package(Qt5Widgets REQURIED)
), but it's not so obvious how to make sure I'm using the right minor version.
What's the easiest way to do this?
Solution
These days it is possible to pass a version to find_package
, like this:
find_package(Qt5Core 5.10 REQUIRED)
The find_package
call will fail if no compatible version of Qt5Core can be 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
This is in-depth documented at https://cmake.org/cmake/help/latest/command/find_package.html#version-selection
Answered By - jobor Answer Checked By - Senaida (WPSolving Volunteer)