恢复VCPkg(2023-01-27)中Vtk[Qt]的默认依赖为Qt5

非法关键字 / 2024-02-24 / 原文

通过查看vtk的更新的日志已于2023-01-27将默认依赖的Qt的版本由5更新到6

git log -- .\ports\vtk
commit 27fb19bdcc1f6ddb1261cffb5372724ac1d63a93
Author: Lily Wang <94091114+LilyWangLL@users.noreply.github.com>
Date:   2023-08-23

    [many ports] Fix URLS of download patch (#33309)

    * [many ports] Fix URLS of download patch

    * update version

    * Fix opencv4 and minhook

    * update version

.......

commit 46dda5372b08b614645c74679a61a2498d5926f6
Author: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com>
Date:   2023-01-27

    [vtk|opencv4|openimageio] Switch to Qt6 (#29078)

    * Switch stuff to Qt6

    * give opencv4 the correct deps

    * add Qt5Compat to find_dependency

    * refine vtk deps and promote targets to global

    * fix dep

    * ci is probably faster than my desktop pc building.

    * remove invalid patch part

    * add qt6 patch

    * second patch

    * make openimageio ignore qt5

    * [skip actions] qt6 part 3

    * vtk qt6 patch

    * try openimageio again

    * move gl include

    * fix patch

    * does it work now?

    * remove qualified name

    * more qt6 fixes

    * more patches

    * update and fix rtabmap

    * gles feature in qtbase needs to be disabled for vtk since vtk assumes desktop opengl

    * remove patch add error if qtbase was build with gles2

    * disable also second patch

    * fix theia

    * paraview consolidate patches

    * fix case issue

    * fix missing ,

    * add more qt6 changes

    * remove unnecessary patches

    * bump port version

    * remove comments from vtk

    * add platform features for tools.

    * fix format

    * bump ports

    * another one to bump

    * v db

    Co-authored-by: Billy Robert O'Neal III <bion@microsoft.com>

在太多数情况下,还是在使用Qt5的,暂时还没有将项目切换到Qt6,那么需要使用Vtk[Qt]时可能会出现麻烦,以下是经过对比Vtk作者由Qt5更换为Qt6默认依赖时发现,恢复默认依赖为Qt5的办法:
ports/vtk/portfile.cmake
ports/vtk/vcpkg.json
对应的修改如下:

diff --git a/ports/vtk/portfile.cmake b/ports/vtk/portfile.cmake
index f33e09d50..393329b41 100644
--- a/ports/vtk/portfile.cmake
+++ b/ports/vtk/portfile.cmake
@@ -135,13 +135,13 @@ list(TRANSFORM VTK_FEATURE_OPTIONS REPLACE "=OFF" "=DONT_WANT")
 if("qt" IN_LIST FEATURES AND NOT EXISTS "${CURRENT_HOST_INSTALLED_DIR}/tools/Qt5/bin/qmlplugindump${VCPKG_HOST_EXECUTABLE_SUFFIX}")
     list(APPEND VTK_FEATURE_OPTIONS -DVTK_MODULE_ENABLE_VTK_GUISupportQtQuick=NO)
 endif()
-if("qt" IN_LIST FEATURES)
-    file(READ "${CURRENT_INSTALLED_DIR}/share/qtbase/vcpkg_abi_info.txt" qtbase_abi_info)
-    if(qtbase_abi_info MATCHES "(^|;)gles2(;|$)")
-        message(FATAL_ERROR "VTK assumes qt to be build with desktop opengl. As such trying to build vtk with qt using GLES will fail.")
-        # This should really be a configure error but using this approach doesn't require patching.
-    endif()
-endif()
+# if("qt" IN_LIST FEATURES)
+#     file(READ "${CURRENT_INSTALLED_DIR}/share/qtbase/vcpkg_abi_info.txt" qtbase_abi_info)
+#     if(qtbase_abi_info MATCHES "(^|;)gles2(;|$)")
+#         message(FATAL_ERROR "VTK assumes qt to be build with desktop opengl. As such trying to build vtk with qt using GLES will fail.")
+#         # This should really be a configure error but using this approach doesn't require patching.
+#     endif()
+# endif()

 if("python" IN_LIST FEATURES)
     set(python_ver "")
@@ -247,7 +247,7 @@ vcpkg_cmake_configure(
         ${ADDITIONAL_OPTIONS}
         -DVTK_DEBUG_MODULE_ALL=ON
         -DVTK_DEBUG_MODULE=ON
-        -DVTK_QT_VERSION=6
+        -DVTK_QT_VERSION=5
         -DCMAKE_INSTALL_QMLDIR:PATH=qml
         -DVCPKG_HOST_TRIPLET=${_HOST_TRIPLET}
         -DCMAKE_FIND_PACKAGE_TARGETS_GLOBAL=ON # Due to Qt6::Platform not being found on Linux platform
diff --git a/ports/vtk/vcpkg.json b/ports/vtk/vcpkg.json
index 79cec81ca..5f5861da3 100644
--- a/ports/vtk/vcpkg.json
+++ b/ports/vtk/vcpkg.json
@@ -197,21 +197,10 @@
     "qt": {
       "description": "Qt functionality for VTK",
       "dependencies": [
-        {
-          "name": "qtbase",
-          "default-features": false,
-          "features": [
-            "gui",
-            "opengl",
-            "widgets"
-          ]
-        },
-        "qtdeclarative",
-        "qtimageformats",
-        {
-          "name": "qttools",
-          "default-features": false
-        }
+        "qt5-base",
+        "qt5-declarative",
+        "qt5-imageformats",
+        "qt5-tools"
       ]
     },
     "utf8": {