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:
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. The qt_add_library()
command does not
consider BUILD_SHARED_LIBS
when deciding the library type.
Any 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() 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.
See also qt_finalize_target() and qt_add_executable().
As part of the free Business evaluation, we offer a free welcome call for companies, to talk about your requirements, and how the Felgo SDK & Services can help you. Just sign up and schedule your call.
Sign up now to start your free Business evaluation: