QTP0003

Consider the BUILD_SHARED_LIBS value when creating Qt libraries.

This policy was introduced in Qt 6.7. The policy affects the default type of the libraries created using Qt CMake API, like qt_add_library, qt_add_plugin, qt_add_qml_module.

If the policy is set to OLD, the default library type that is selected is aligned with the Qt build type, either shared or static.

If the policy is set to NEW, the library type is selected according to the BUILD_SHARED_LIBS value if it's set. If BUILD_SHARED_LIBS is not set, the default library type falls back to the Qt build type.

For example, the following code will use the Qt build type as the default library type for the MyLib target, despite the fact BUILD_SHARED_LIBS is set to ON:

 set(BUILD_SHARED_LIBS ON)
 ...
 qt6_add_library(MyLib sourcefile.h sourcefile.cpp)

If you set the QTP0003 to NEW before the qt_add_library call, BUILD_SHARED_LIBS will affect the library default type and MyLib will be the shared library.

 set(BUILD_SHARED_LIBS ON)
 ...
 qt_policy(SET QTP0003 NEW)
 qt6_add_library(MyLib sourcefile.h sourcefile.cpp)

See also qt_policy, Qt CMake policies, and qt_add_library.