Pip installed PySide6

As Debian 12 does not provide PySide6 package, I installed it using pip. It seems there is some support for that since 2f7be9e782b0 (“cMake: Add support for compiling against Qt6 (#7647)”), but it ends this way:

CMake Warning (dev) at cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake:195 (set):
  Cannot set "Shiboken6_INCLUDE_DIRS": current scope has no parent.
Call Stack (most recent call first):
  cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake:46 (find_pip_package)
  CMakeLists.txt:82 (SetupShibokenAndPyside)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake:196 (set):
  Cannot set "Shiboken6_LIBRARIES": current scope has no parent.
Call Stack (most recent call first):
  cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake:46 (find_pip_package)
  CMakeLists.txt:82 (SetupShibokenAndPyside)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found pip-installed Shiboken6 in  /usr/local/lib/python3.11/dist-packages/shiboken6
CMake Warning (dev) at cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake:195 (set):
  Cannot set "PySide6_INCLUDE_DIRS": current scope has no parent.
Call Stack (most recent call first):
  cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake:61 (find_pip_package)
  CMakeLists.txt:82 (SetupShibokenAndPyside)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake:196 (set):
  Cannot set "PySide6_LIBRARIES": current scope has no parent.
Call Stack (most recent call first):
  cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake:61 (find_pip_package)
  CMakeLists.txt:82 (SetupShibokenAndPyside)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found pip-installed PySide6 in  /usr/local/lib/python3.11/dist-packages/PySide6
-- Found PYSIDE6 tools: /usr/lib/qt6/libexec/uic, /usr/lib/qt6/libexec/rcc
CMake Warning at cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake:119 (message):
  Shiboken6 include files not found, FREECAD_USE_SHIBOKEN automatically set
  to OFF
Call Stack (most recent call first):
  CMakeLists.txt:82 (SetupShibokenAndPyside)


CMake Warning at cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake:147 (message):
  PySide6 include files not found, FREECAD_USE_PYSIDE automatically set to
  OFF
Call Stack (most recent call first):
  CMakeLists.txt:82 (SetupShibokenAndPyside)


-- PySide 6.6.1 Python module found at /usr/local/lib/python3.11/dist-packages/PySide6.

Since it sits in the repository for quite a long time, there’s a good chance I’m doing something wrong. Here’s patch that works for me:

--- a/cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake
+++ b/cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake
@@ -45,9 +45,9 @@ macro(SetupShibokenAndPyside)
     if(NOT SHIBOKEN_INCLUDE_DIR)
         find_pip_package(Shiboken${SHIBOKEN_MAJOR_VERSION})
         if (Shiboken${SHIBOKEN_MAJOR_VERSION}_FOUND)
-            set(Shiboken_INCLUDE_DIR ${Shiboken${SHIBOKEN_MAJOR_VERSION}_INCLUDE_DIRS})
-            set(Shiboken_LIBRARY ${Shiboken${SHIBOKEN_MAJOR_VERSION}_LIBRARIES})
-            set(Shiboken_FOUND TRUE)
+            set(SHIBOKEN_INCLUDE_DIR ${Shiboken${SHIBOKEN_MAJOR_VERSION}_INCLUDE_DIRS})
+            set(SHIBOKEN_LIBRARY ${Shiboken${SHIBOKEN_MAJOR_VERSION}_LIBRARIES})
+            set(SHIBOKEN_FOUND TRUE)
         endif()
     endif()
 
@@ -60,9 +60,9 @@ macro(SetupShibokenAndPyside)
     if(NOT PYSIDE_INCLUDE_DIR)
         find_pip_package(PySide${PYSIDE_MAJOR_VERSION})
         if (PySide${PYSIDE_MAJOR_VERSION}_FOUND)
-            set(PySide_INCLUDE_DIR ${PySide${PYSIDE_MAJOR_VERSION}_INCLUDE_DIRS})
-            set(PySide_LIBRARY ${PySide${PYSIDE_MAJOR_VERSION}_LIBRARIES})
-            set(PySide_FOUND TRUE)
+            set(PYSIDE_INCLUDE_DIR ${PySide${PYSIDE_MAJOR_VERSION}_INCLUDE_DIRS})
+            set(PYSIDE_LIBRARY ${PySide${PYSIDE_MAJOR_VERSION}_LIBRARIES})
+            set(PYSIDE_FOUND TRUE)
         endif()
     endif()
 
@@ -192,9 +192,9 @@ macro(find_pip_package PACKAGE)
         endforeach()
         file(TO_NATIVE_PATH "${PIP_PACKAGE_LOCATION}/${PIP_PACKAGE_NAME}/include" INCLUDE_DIR)
         file(TO_NATIVE_PATH "${PIP_PACKAGE_LOCATION}/${PIP_PACKAGE_NAME}/lib" LIBRARY)
-        set(${PACKAGE}_INCLUDE_DIRS ${INCLUDE_DIR} PARENT_SCOPE)
-        set(${PACKAGE}_LIBRARIES ${LIBRARY} PARENT_SCOPE)
-        set(${PACKAGE}_FOUND ${LIBRARY} TRUE)
+        set(${PACKAGE}_INCLUDE_DIRS ${INCLUDE_DIR})
+        set(${PACKAGE}_LIBRARIES ${LIBRARY})
+        set(${PACKAGE}_FOUND TRUE)
         message(STATUS "Found pip-installed ${PACKAGE} in ${PIP_PACKAGE_LOCATION}/${PIP_PACKAGE_NAME}")
     endif()
 endmacro()

Is anyone using pip installed PySide6? @chennes, does above make sense to you? I do not know much about cmake nor the usual ways of detecting packages.

I never did get a pip-installed PySide6 to work properly, I have been using a self-compiled version myself. If you have a GitHub account, can you submit your patch as a PR? I can’t test it today or tomorrow, but possibly on Sunday.

You are right, there’s some more to fix, so PR will be opened once I fix remaining issues.

Hmm, it seems to work with pip installed PySide6==6.4.2. It just needed minor tweak in src/Gui/PythonWrapper.cpp:

std::string PythonWrapper::shiboken{"shiboken6"};

And here comes a question: who is supposed to define those HAVE_SHIBOKEN6 or HAVE_SHIBOKEN2?
wmayer, question seems to be related to fd7c7f35cf4c (“Gui: Use shiboken6 & PySide6 API”).