CMake Variable Reference

Module variables

Qt modules loaded with find_package set various variables.

Note: You rarely need to access these variables directly. Common tasks like linking against a module should be done through the library targets each module defines.

For example, find_package(Qt5 COMPONENTS Widgets), when successful, makes the following variables available:

VariableDescription
Qt5Widgets_COMPILE_DEFINITIONSA list of compile definitions to use when building against the library.
Qt5Widgets_DEFINITIONSA list of definitions to use when building against the library.
Qt5Widgets_EXECUTABLE_COMPILE_FLAGSA string of flags to use when building executables against the library.
Qt5Widgets_FOUNDA boolean that describes whether the module was found successfully.
Qt5Widgets_INCLUDE_DIRSA list of include directories to use when building against the library.
Qt5Widgets_LIBRARIESThe name of the imported target for the module: Qt5::Widgets
Qt5Widgets_PRIVATE_INCLUDE_DIRSA list of private include directories to use when building against the library and using private Qt API.
Qt5Widgets_VERSION_STRINGA string containing the module's version.

For all packages found with find_package, equivalents of these variables are available; they are case-sensitive.

Installation variables

Additionally, there are also variables that don't relate to a particular package, but to the Qt installation itself.

VariableDescription
QT_DEFAULT_MAJOR_VERSIONAn integer that controls the Qt version that qt_ commands forward to in case of mixed Qt 5 and Qt 6 projects. It needs to be set to either 5 or 6 before the respective find_package() calls.

If set to 5, commands starting with qt_ will call their counterpart starting with qt5_. If set to 6, they will call their counterpart starting with qt6_.

If not set, the first find_package call defines the default version. This functionality was added in Qt 5.15.

QT_LIBINFIXA string that holds the infix used in library names, when Qt is configured with -libinfix.
QT_NO_CREATE_VERSIONLESS_FUNCTIONSSince Qt 5.15, modules define not only commands that start with qt5_, but also ones with qt_. You can set QT_NO_CREATE_VERSIONLESS_FUNCTIONS before find_package to prevent this.
QT_NO_CREATE_VERSIONLESS_TARGETSSince Qt 5.15, modules define not only targets that start with Qt5::, but also ones with Qt::. You can set QT_NO_CREATE_VERSIONLESS_TARGETS before find_package to prevent this.
QT_VISIBILITY_AVAILABLEOn Unix, a boolean that describes whether Qt libraries and plugins were compiled with -fvisibility=hidden. This means that only selected symbols are exported.

© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.