Creates and finalizes a library.
The command is defined in the
Core component of the
Qt6 package, which can be loaded like so:
find_package(Qt6 REQUIRED COMPONENTS Core)
This command was introduced in Qt 6.2.
qt_add_library(target [STATIC | SHARED | MODULE | INTERFACE | OBJECT] [MANUAL_FINALIZATION] sources... )
If versionless commands are disabled, use
qt6_add_library() instead. It supports the same set of arguments as this command.
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
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. The
qt_add_library() command does not consider
BUILD_SHARED_LIBS when deciding the library type.
sources provided will be passed through to the internal call to
After a target is created, further processing or finalization steps may be needed. The finalization processing is implemented by the qt_finalize_target() command.
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.
© 2022 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.