QTP0003

Qt ライブラリを作成するときに BUILD_SHARED_LIBS の値を考慮してください。

このポリシーは Qt 6.7 で導入されました。このポリシーは、qt_add_libraryqt_add_pluginqt_add_qml_module のようなQt CMake API を使用して作成されるライブラリのデフォルトのタイプに影響します。

shared staticポリシーがOLD に設定されている場合、選択されるデフォルトのライブラリタイプは Qt のビルドタイプに合わせられます。

ポリシーがNEW に設定されている場合、BUILD_SHARED_LIBSが設定されていれば、その値に従ってライブラリ・タイプが選択されます。BUILD_SHARED_LIBS が設定されていない場合、デフォルトのライブラリ・タイプは Qt ビルド・タイプに戻ります。

たとえば、以下のコードでは、BUILD_SHARED_LIBSON に設定されているにもかかわらず、MyLib ターゲットのデフォルトのライブラリ・タイプとして Qt ビルド・タイプが使用されます:

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

qt_add_library呼び出しの前に QTP0003 をNEW に設定すると、BUILD_SHARED_LIBS がライブラリのデフォルトタイプに影響し、MyLib が共有ライブラリになります。

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

qt_policy,Qt CMake policies,qt_add_libraryも参照してください

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.