Imported targets | Build with CMake 6.5.1
Description: Provides an overview of the CMake targets imported by Qt.

- Qt 6.5
- Build with CMake
- Imported targets
- Qt 6.5.1 Reference Documentation

Building projects on the command line ◦ Qt CMake policies

# Imported targets

Each Qt module that is loaded defines a CMake library target. The target names start with `Qt6::`, followed by the module name. For example: `Qt6::Core`, `Qt6::Gui`. Pass the name of the library target to `target_link_libraries` to use the respective library.

Note: The targets are also available with a `Qt::` prefix: `Qt::Core`, `Qt::Gui`, and so on. See also Qt 5 and Qt 6 compatibility.

Imported targets are created with the same configurations as when Qt was configured. That is:

- If Qt was configured with the `-debug` switch, an imported target with the DEBUG configuration is created.
- If Qt was configured with the `-release` switch, an imported target with the RELEASE configuration is created.
- If Qt was configured with the `-debug-and-release` switch, then imported targets are created with both RELEASE and DEBUG configurations.

If your project has custom `CMake` build configurations, you have to map your custom configuration to either the debug or the release Qt configuration.

     find_package(Qt6 REQUIRED COMPONENTS Core)

     set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage")

     # set up a mapping so that the Release configuration for the Qt imported target is
     # used in the COVERAGE CMake configuration.
     set_target_properties(Qt6::Core PROPERTIES MAP_IMPORTED_CONFIG_COVERAGE "RELEASE")

Building projects on the command line ◦ Qt CMake policies