Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qt_add_library.qdoc
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qt-add-library.html
6\ingroup cmake-commands-qtcore
7
8\title qt_add_library
9\keyword qt6_add_library
10
11\summary {Creates and finalizes a library.}
12
13\include cmake-find-package-core.qdocinc
14
15\cmakecommandsince 6.2
16
17\section1 Synopsis
18
19\badcode
20qt_add_library(target
21 [STATIC | SHARED | MODULE | INTERFACE | OBJECT]
22 [MANUAL_FINALIZATION]
23 sources...
24)
25\endcode
26
27\versionlessCMakeCommandsNote qt6_add_library()
28
29\section1 Description
30
31\c{qt_add_library()} is a wrapper around CMake's built-in
32\c{add_library()} command. It performs the following tasks:
33
34\list
35\li Create a CMake target of an appropriate library type.
36\li Handle finalization of the CMake target.
37\endlist
38
39\section2 Target Creation
40
41The type of library created can be specified explicitly with one of the
42\c STATIC, \c SHARED, \c MODULE, \c INTERFACE or \c OBJECT keywords, just as
43one might for \c{add_library()}. If none of these keywords are given, the
44library type created depends on how Qt was built. If Qt was built statically,
45a static library will be created. Otherwise, a shared library will
46be created. Note that this is different to how CMake's \c{add_library()}
47command works, where the \c BUILD_SHARED_LIBS variable controls the type of
48library created.
49Since 6.7, the \c{qt_add_library()} command considers \c BUILD_SHARED_LIBS
50when deciding the library type only if the variable is set explicitly and
51\l {QTP0003} is set to \c NEW.
52
53Any \c{sources} provided will be passed through to the internal call to
54\c{add_library()}.
55
56\target qt_add_library finalization
57\section2 Finalization
58
59After a target is created, further processing or \e{finalization} steps may be
60needed. The finalization processing is implemented by the
61\l{qt6_finalize_target}{qt_finalize_target()} command.
62
63Finalization can occur either as part of this call or be deferred to sometime
64after this command returns (but it should still be in the same directory scope).
65When using CMake 3.19 or later, finalization is automatically deferred to the
66end of the current directory scope. This gives the caller an opportunity to
67modify properties of the created target before it is finalized. When using
68CMake versions earlier than 3.19, automatic deferral isn't supported. In that
69case, finalization is performed immediately before this command returns.
70
71Regardless of the CMake version, the \c{MANUAL_FINALIZATION} keyword can be
72given to indicate that you will explicitly call
73\l{qt6_finalize_target}{qt_finalize_target()} yourself instead at some later
74time. In general, \c MANUAL_FINALIZATION should not be needed unless the
75project has to support CMake 3.18 or earlier.
76
77\sa {qt6_finalize_target}{qt_finalize_target()},
78 {qt6_add_executable}{qt_add_executable()}, QTP0003
79
80*/