[Development] CMake: inconsistent behaviour of find_package(Qt5 <minversion> <components>)

René J.V. Bertin rjvbertin at gmail.com
Tue Jan 10 15:21:07 CET 2017


Hi,

I started working with a project that shows what I think is inconsistent `find_package(Qt5 ...)` behaviour. In its stock form, the general Qt5 component isn't found while the rest is except for 1 evident exception:

find_package(Qt5 5.3.0 REQUIRED
    COMPONENTS
        Core Gui Network PrintSupport Svg Test Widgets Xml)
find_package(Qt5 5.3.0 QUIET
    COMPONENTS
        Declarative Quick Sql ...)
--->
 * Qt5Core
 * Qt5Gui
 * Qt5Network
 * Qt5PrintSupport
 * Qt5Svg
 * Qt5Test
 * Qt5Widgets
 * Qt5Xml
 * Qt5Qml (required version >= 5.7.1)
 * Qt5Sql
<snip>
-- The following REQUIRED packages have not been found:

 * Qt5 (required version >= 5.3.0)


When I remove "Declarative" from the 2nd find_package call above, all of a sudden Qt5 is found. When I remove the REQUIRED keyword from the 1st call (but not "Declarative"), Qt5 is still not found but I only get a warning.

The components requested in the 2nd call are all set as RECOMMENDED or OPTIONAL in subsequent statements, so the proper way to handle this (assuming the project wants to continue supporting QtQuick1) appears to be to add a dedicated

find_package(Qt5Declarative 5.3.0 QUIET)


All in all this seems inconsistent and at least counterintuitive behaviour to me (which took me a while to figure out). That 2nd, QUIET find_package() doesn't set the REQUIRED property, and also shouldn't override the status of a package that has already been found (not as long as it finds the same installation).

Is this something that can be rectified in Qt's cmake modules, or is it another CMake issue?

R.



More information about the Development mailing list