被加載的每一 Qt 模塊定義一 CMake 庫目標。目標名稱開頭采用
Qt6::
,緊隨其後的是模塊名稱。例如:
Qt6::Core
,
Qt6::Gui
。將庫目標的名稱傳遞給
target_link_libraries
以使用各自的庫。
注意:
目標也是可用的采用
Qt::
前綴:
Qt::Core
,
Qt::Gui
,等。另請參閱
QT 5 和 QT 6 兼容性
.
采用相同配置創建導入目標,因為當有配置 Qt 時。即:
-debug
開關,則采用 DEBUG 配置創建導入目標。
-release
開關,則采用 RELEASE 配置創建導入目標。
-debug-and-release
開關,則采用 RELEASE 和 DEBUG 配置創建導入目標。
若您的工程有自定義
CMake
構建配置,必須將自定義配置映射到 debug (調試) 或 release (發行) Qt 配置。
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")