qt_add_library

创建并定稿库。

命令的定义在 核心 组件对于 Qt6 包,可以像这样加载:

find_package(Qt6 REQUIRED COMPONENTS Core)
					

该命令在 Qt 6.2 引入。

概要

qt_add_library(target
    [STATIC | SHARED | MODULE | INTERFACE | OBJECT]
    [MANUAL_FINALIZATION]
    sources...
)
					

无版本命令 被禁用,使用 qt6_add_library() 代替。它支持如此命令的一组相同自变量。

描述

qt_add_library() is a wrapper around CMake's built-in add_library() command. It performs the following tasks:

  • Create a CMake target of an appropriate library type.
  • Handle finalization of the CMake target.

创建目标

The type of library created can be specified explicitly with one of the STATIC , SHARED , MODULE , INTERFACE or OBJECT keywords, just as one might for add_library() . If none of these keywords are given, the library type created depends on how Qt was built. If Qt was built statically, a static library will be created. Otherwise, a shared library will be created. Note that this is different to how CMake's add_library() command works, where the BUILD_SHARED_LIBS variable controls the type of library created. Since 6.7, the qt_add_library() command considers BUILD_SHARED_LIBS when deciding the library type only if the variable is set explicitly and QTP0003 被设为 NEW .

任何 sources provided will be passed through to the internal call to add_library() .

定稿

After a target is created, further processing or finalization steps may be needed. The finalization processing is implemented by the qt_finalize_target() 命令。

Finalization can occur either as part of this call or be deferred to sometime after this command returns (but it should still be in the same directory scope). When using CMake 3.19 or later, finalization is automatically deferred to the end of the current directory scope. This gives the caller an opportunity to modify properties of the created target before it is finalized. When using CMake versions earlier than 3.19, automatic deferral isn't supported. In that case, finalization is performed immediately before this command returns.

Regardless of the CMake version, the MANUAL_FINALIZATION keyword can be given to indicate that you will explicitly call qt_finalize_target() yourself instead at some later time. In general, MANUAL_FINALIZATION should not be needed unless the project has to support CMake 3.18 or earlier.

另请参阅 qt_finalize_target() , qt_add_executable() ,和 QTP0003 .