1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5\page qt-cmake-policy-qtp0003.html
6\ingroup qt-cmake-policies
9\keyword qt_cmake_policy_qtp0003
11\summary {Consider the BUILD_SHARED_LIBS value when creating Qt libraries.}
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}.
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.
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
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
29set(BUILD_SHARED_LIBS ON)
31qt6_add_library(MyLib sourcefile.h sourcefile.cpp)
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.
38set(BUILD_SHARED_LIBS ON)
40qt_policy(SET QTP0003 NEW)
41qt6_add_library(MyLib sourcefile.h sourcefile.cpp)
44\sa qt_policy, {Qt CMake policies}, qt_add_library