Details
Description
This one's a quicky. Promise.
PySide2's CMakeLists.txt finds the PythonInterp and PythonLibs packages in the wrong order. Ideally, the former should be found first and the latter second. Why? Because PythonInterp sets global CMake variables accessed by PythonLibs. Finding these packages in the wrong order invites desynchronization between the executable, library, and include paths of the Python interpreter to be built against.
As commented in /usr/share/cmake/Modules/FindPythonLibs.cmake:
# If calling both ``find_package(PythonInterp)`` and # ``find_package(PythonLibs)``, call ``find_package(PythonInterp)`` first to # get the currently active Python version by default with a consistent version # of PYTHON_LIBRARIES.
Shiboken2 does it oh-so-right:
if (USE_PYTHON_VERSION) find_package(PythonInterp ${USE_PYTHON_VERSION} REQUIRED) find_package(PythonLibs ${USE_PYTHON_VERSION} REQUIRED) else() find_package(PythonInterp 2.6) find_package(PythonLibs 2.6) endif()
PySide2 does it not-so-right:
if (USE_PYTHON_VERSION) find_package(PythonLibs ${USE_PYTHON_VERSION} REQUIRED) find_package(PythonInterp ${USE_PYTHON_VERSION} REQUIRED) else() find_package(PythonLibs 2.6) find_package(PythonInterp 2.6) endif()
Fortunately, the fix is trivial. And that's something we can all drink to.