How to list all CMake components of Qt5?

Viewed 2580

I know that in CMake I can find and require the Qt5 libraries I need with code like this:

find_package(Qt5 5.12.0 REQUIRED
    COMPONENTS Gui Qml QuickControls2 Svg
)

But how do I know the exact names I can list after COMPONENTS?

1 Answers

Component names are interpreted by the package (here: Qt5), not CMake itself (see). So their naming scheme is package specific. In the case of Qt5, ${QT5_DIR}/lib/cmake/Qt5/Qt5Config.cmake shows that their names are the same as the CMake module names when omitting the Qt5 prefix:

foreach(module ${Qt5_FIND_COMPONENTS})
    find_package(Qt5${module} ... )
    ...
endforeach()

So to list all component names, just list the CMake modules (as derived from the corresponding ModuleNameConfig.cmake filenames) and omit the Qt5 prefix. Under Linux, this does the job and also sorts the output into columns:

find /path/to/your/qt5/ -name "*Config.cmake" |
  sed 's/^.*\/Qt5//; s/Config.cmake$//; /^\s*$/d' |
  sort | pr -t -3

As of Qt 5.12, this lists the COMPONENT names as follows:

3DAnimation             Help                    QuickWidgets
3DCore                  LinguistTools           RemoteObjects
3DExtras                Location                RepParser
3DInput                 Multimedia              Scxml
3DLogic                 MultimediaWidgets       Sensors
3DQuick                 Network                 SerialPort
3DQuickAnimation        Nfc                     Sql
3DQuickExtras           OpenGL                  Svg
3DQuickInput            OpenGLExtensions        Test
3DQuickRender           Positioning             TextToSpeech
3DQuickScene2D          PositioningQuick        UiPlugin
3DRender                PrintSupport            UiTools
AndroidExtras           Qml                     WebChannel
Bluetooth               Quick                   WebSockets
Concurrent              QuickCompiler           WebView
Core                    QuickControls2          Widgets
Gamepad                 QuickTemplates2         Xml
Gui                     QuickTest               XmlPatterns
Related