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
qtp0003.qdoc
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qt-cmake-policy-qtp0003.html
6\ingroup qt-cmake-policies
7\since 6.7
8\title QTP0003
9\keyword qt_cmake_policy_qtp0003
10
11\summary {Consider the BUILD_SHARED_LIBS value when creating Qt libraries.}
12
13This policy was introduced in Qt 6.7. The policy affects the default type of the
14libraries created using \l {CMake Commands in Qt6 Core}{Qt CMake API}, like
15\l {qt_add_library}, \l{qt_add_plugin}, \l{qt_add_qml_module}.
16
17If the policy is set to \c OLD, the default library type that is selected is
18aligned with the Qt build type, either \c shared or \c static.
19
20If the policy is set to \c NEW, the library type is selected according to the
21\l {CMake BUILD_SHARED_LIBS Documentation}{BUILD_SHARED_LIBS} value if it's set.
22If \c BUILD_SHARED_LIBS is not set, the default library type falls back to the
23Qt build type.
24
25For example, the following code will use the Qt build type as the default
26library type for the \c MyLib target, despite the fact \c BUILD_SHARED_LIBS is
27set to \c ON:
28\badcode
29set(BUILD_SHARED_LIBS ON)
30...
31qt6_add_library(MyLib sourcefile.h sourcefile.cpp)
32\endcode
33
34If you set the QTP0003 to \c NEW before the \l {qt6_add_library}{qt_add_library}
35call, \c BUILD_SHARED_LIBS will affect the library default type and \c MyLib
36will be the shared library.
37\badcode
38set(BUILD_SHARED_LIBS ON)
39...
40qt_policy(SET QTP0003 NEW)
41qt6_add_library(MyLib sourcefile.h sourcefile.cpp)
42\endcode
43
44\sa qt_policy, {Qt CMake policies}, qt_add_library
45
46*/