From 3a7bf8ef22fec548f70c022d401a8a5a46e6f100 Mon Sep 17 00:00:00 2001
From: Dmitry Shachnev <mitya57@gmail.com>
Date: Sat, 4 Jul 2020 13:01:27 +0300
Subject: [PATCH 1/4] Update pyqt_sip_dir for pyqt5 compiled with sip5

---
 cmake/modules/FindPyQt5.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/cmake/modules/FindPyQt5.py b/cmake/modules/FindPyQt5.py
index e0ef9d7bdb..e138ad3107 100644
--- a/cmake/modules/FindPyQt5.py
+++ b/cmake/modules/FindPyQt5.py
@@ -4,6 +4,7 @@
 
 import sys
 import os
+from distutils.sysconfig import get_python_lib
 
 try:
     # On Windows and Python 3.8+ python doesn't load module DLL's
@@ -40,8 +41,9 @@ try:
 except ValueError:
     pass
 
-# FIXME This next line is just a little bit too crude.
-pyqt_sip_dir = os.path.join(sys.prefix, "share", "sip", "PyQt5")
+pyqt_sip_dir = os.path.join(get_python_lib(plat_specific=1), "PyQt5", "bindings")
+if not os.path.exists(pyqt_sip_dir):  # Fallback for older PyQt5/SIP
+    pyqt_sip_dir = os.path.join(sys.prefix, "share", "sip", "PyQt5")
 print("pyqt_sip_dir:%s" % pyqt_sip_dir)
 
 print("pyqt_sip_flags:%s" % PyQt5.QtCore.PYQT_CONFIGURATION["sip_flags"])
-- 
GitLab


From ecc99b3a48c9fa7a80b2fade5a6de2a09c1cca82 Mon Sep 17 00:00:00 2001
From: Dmitry Shachnev <mitya57@gmail.com>
Date: Sat, 4 Jul 2020 13:02:00 +0300
Subject: [PATCH 2/4] Find sip executable directly instead of relying on
 FindSIP.py

---
 cmake/modules/FindSIP.cmake                   | 47 ++++---------------
 cmake/modules/FindSIP.py                      | 15 ------
 plugins/extensions/pykrita/CMakeLists.txt     |  2 +-
 plugins/extensions/pykrita/sip/CMakeLists.txt |  4 --
 4 files changed, 11 insertions(+), 57 deletions(-)
 delete mode 100644 cmake/modules/FindSIP.py

diff --git a/cmake/modules/FindSIP.cmake b/cmake/modules/FindSIP.cmake
index 1ca061ff97..001ac6a11b 100644
--- a/cmake/modules/FindSIP.cmake
+++ b/cmake/modules/FindSIP.cmake
@@ -8,17 +8,11 @@
 #
 # This file defines the following variables:
 #
-# SIP_VERSION - The version of SIP found expressed as a 6 digit hex number
-#     suitable for comparison as a string.
-#
 # SIP_VERSION_STR - The version of SIP found as a human readable string.
 #
 # SIP_EXECUTABLE - Path and filename of the SIP command line executable.
 #
-# SIP_INCLUDE_DIR - Directory holding the SIP C++ header file.
-#
-# SIP_DEFAULT_SIP_DIR - Default directory where .sip files should be installed
-#     into.
+# SIP_MODULE_EXECUTABLE - Path and filename of the sip-module executable.
 
 # Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
 # Redistribution and use is allowed according to the terms of the BSD license.
@@ -26,40 +20,19 @@
 
 
 
-IF(SIP_VERSION)
+IF(SIP_VERSION_STR)
   # Already in cache, be silent
   SET(SIP_FOUND TRUE)
-ELSE(SIP_VERSION)
+ELSE(SIP_VERSION_STR)
 
-  FIND_FILE(_find_sip_py FindSIP.py PATHS ${CMAKE_MODULE_PATH})
-
-  if (WIN32)
-    EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_PREFIX_PATH}/lib/krita-python-libs" ${PYTHON_EXECUTABLE} ${_find_sip_py} OUTPUT_VARIABLE sip_config)
-  else (WIN32)
-    EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_sip_py} OUTPUT_VARIABLE sip_config)
-  endif (WIN32)
-  
-  IF(sip_config)
-    STRING(REGEX REPLACE "^sip_version:([^\n]+).*$" "\\1" SIP_VERSION ${sip_config})
-    STRING(REGEX REPLACE ".*\nsip_version_str:([^\n]+).*$" "\\1" SIP_VERSION_STR ${sip_config})
-    STRING(REGEX REPLACE ".*\nsip_bin:([^\n]+).*$" "\\1" SIP_EXECUTABLE ${sip_config})
-    IF(NOT SIP_DEFAULT_SIP_DIR)
-        STRING(REGEX REPLACE ".*\ndefault_sip_dir:([^\n]+).*$" "\\1" SIP_DEFAULT_SIP_DIR ${sip_config})
-    ENDIF(NOT SIP_DEFAULT_SIP_DIR)
-    STRING(REGEX REPLACE ".*\nsip_inc_dir:([^\n]+).*$" "\\1" SIP_INCLUDE_DIR ${sip_config})
-    FILE(TO_CMAKE_PATH ${SIP_DEFAULT_SIP_DIR} SIP_DEFAULT_SIP_DIR)
-    FILE(TO_CMAKE_PATH ${SIP_INCLUDE_DIR} SIP_INCLUDE_DIR)
-    if (WIN32) 
-        set(SIP_EXECUTABLE ${SIP_EXECUTABLE}.exe)
-    endif()
-    IF(EXISTS ${SIP_EXECUTABLE})
-      SET(SIP_FOUND TRUE)
-    ELSE()
-      MESSAGE(STATUS "Found SIP configuration but the sip executable could not be found.")
-    ENDIF()
-  ENDIF(sip_config)
+  find_program(SIP_EXECUTABLE NAMES sip5 sip)
+  find_program(SIP_MODULE_EXECUTABLE sip-module)
+  macro_bool_to_01(SIP_EXECUTABLE SIP_FOUND)
 
   IF(SIP_FOUND)
+    execute_process(COMMAND ${SIP_EXECUTABLE} -V OUTPUT_VARIABLE SIP_VERSION_STR
+                    OUTPUT_STRIP_TRAILING_WHITESPACE)
+
     IF(NOT SIP_FIND_QUIETLY)
       MESSAGE(STATUS "Found SIP version: ${SIP_VERSION_STR}")
     ENDIF(NOT SIP_FIND_QUIETLY)
@@ -69,4 +42,4 @@ ELSE(SIP_VERSION)
     ENDIF(SIP_FIND_REQUIRED)
   ENDIF(SIP_FOUND)
 
-ENDIF(SIP_VERSION)
+ENDIF(SIP_VERSION_STR)
diff --git a/cmake/modules/FindSIP.py b/cmake/modules/FindSIP.py
deleted file mode 100644
index ecb734f2cc..0000000000
--- a/cmake/modules/FindSIP.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# FindSIP.py
-#
-# Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
-# Redistribution and use is allowed according to the terms of the BSD license.
-# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
-
-import sys
-import sipconfig
-
-sipcfg = sipconfig.Configuration()
-print("sip_version:%06.0x" % sipcfg.sip_version)
-print("sip_version_str:%s" % sipcfg.sip_version_str)
-print("sip_bin:%s" % sipcfg.sip_bin)
-print("default_sip_dir:%s" % sipcfg.default_sip_dir)
-print("sip_inc_dir:%s" % sipcfg.sip_inc_dir)
diff --git a/plugins/extensions/pykrita/CMakeLists.txt b/plugins/extensions/pykrita/CMakeLists.txt
index ee9fe363fb..578d801017 100644
--- a/plugins/extensions/pykrita/CMakeLists.txt
+++ b/plugins/extensions/pykrita/CMakeLists.txt
@@ -1,6 +1,6 @@
 if (HAVE_PYQT5 AND HAVE_SIP AND HAVE_PYTHONLIBS)
 
-    include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${SIP_INCLUDE_DIR} ${PYTHON_INCLUDE_PATH})
+    include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${PYTHON_INCLUDE_PATH})
 
     add_subdirectory(sip)
     add_subdirectory(plugin)
diff --git a/plugins/extensions/pykrita/sip/CMakeLists.txt b/plugins/extensions/pykrita/sip/CMakeLists.txt
index 49ff5e1717..c8a97b8600 100644
--- a/plugins/extensions/pykrita/sip/CMakeLists.txt
+++ b/plugins/extensions/pykrita/sip/CMakeLists.txt
@@ -1,13 +1,9 @@
 include(SIPMacros)
 
-message( ${SIP_VERSION} " - The version of SIP found expressed as a 6 digit hex number suitable for comparison as a string.")
 message( ${SIP_VERSION_STR} " - The version of SIP found as a human readable string.")
 message( ${SIP_EXECUTABLE} " - Path and filename of the SIP command line executable.")
-message( ${SIP_INCLUDE_DIR} " - Directory holding the SIP C++ header file.")
-message( ${SIP_DEFAULT_SIP_DIR} " - default SIP dir" )
 
 set(SIP_INCLUDES
-    ${SIP_DEFAULT_SIP_DIR}
     ${PYQT5_SIP_DIR}
     ${PYQT_SIP_DIR_OVERRIDE}
      ./krita)
-- 
GitLab


From 5379d14c69e3cea45c0f582e0ff7773cc85ecf6f Mon Sep 17 00:00:00 2001
From: Dmitry Shachnev <mitya57@gmail.com>
Date: Sat, 4 Jul 2020 13:03:46 +0300
Subject: [PATCH 3/4] Remove -n from ${PYQT5_SIP_NAME}

---
 cmake/modules/FindPyQt5.py                    | 2 +-
 plugins/extensions/pykrita/sip/CMakeLists.txt | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmake/modules/FindPyQt5.py b/cmake/modules/FindPyQt5.py
index e138ad3107..85c662b9ae 100644
--- a/cmake/modules/FindPyQt5.py
+++ b/cmake/modules/FindPyQt5.py
@@ -36,7 +36,7 @@ print("pyqt_version_tag:%s" % pyqt_version_tag)
 
 try:
     index_n = pyqt_config_list.index('-n')
-    pyqt_sip_name = '-n' + pyqt_config_list[index_n + 1]
+    pyqt_sip_name = pyqt_config_list[index_n + 1]
     print("pyqt_sip_name:%s" % pyqt_sip_name)
 except ValueError:
     pass
diff --git a/plugins/extensions/pykrita/sip/CMakeLists.txt b/plugins/extensions/pykrita/sip/CMakeLists.txt
index c8a97b8600..5f9262322a 100644
--- a/plugins/extensions/pykrita/sip/CMakeLists.txt
+++ b/plugins/extensions/pykrita/sip/CMakeLists.txt
@@ -10,7 +10,7 @@ set(SIP_INCLUDES
 
 set(SIP_CONCAT_PARTS 1)
 set(SIP_TAGS ALL WS_X11 ${PYQT5_VERSION_TAG})
-set(SIP_EXTRA_OPTIONS -g -o -x PyKDE_QVector ${PYQT5_SIP_NAME})
+set(SIP_EXTRA_OPTIONS -g -o -x PyKDE_QVector -n ${PYQT5_SIP_NAME})
 
 set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${LIB_INSTALL_DIR}/krita-python-libs)
 file(GLOB PYKRITA_KRITA_sip_files ./krita/*.sip)
-- 
GitLab


From 67c6a8642920263d7e1879e3edc28ca8b783742b Mon Sep 17 00:00:00 2001
From: Dmitry Shachnev <mitya57@gmail.com>
Date: Sat, 4 Jul 2020 13:08:33 +0300
Subject: [PATCH 4/4] Generate sip.h in ${CMAKE_CURRENT_SIP_OUTPUT_DIR} for SIP
 v5

---
 cmake/modules/SIPMacros.cmake | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/cmake/modules/SIPMacros.cmake b/cmake/modules/SIPMacros.cmake
index 885d10d0b2..bd60188878 100644
--- a/cmake/modules/SIPMacros.cmake
+++ b/cmake/modules/SIPMacros.cmake
@@ -99,6 +99,12 @@ MACRO(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
         COMMAND ${SIP_EXECUTABLE} ${_sip_tags} ${_sip_x} ${SIP_EXTRA_OPTIONS} -j ${SIP_CONCAT_PARTS} -c ${CMAKE_CURRENT_SIP_OUTPUT_DIR} ${_sip_includes} ${_abs_module_sip}
         DEPENDS ${_abs_module_sip} ${SIP_EXTRA_FILES_DEPEND}
     )
+    IF (SIP_MODULE_EXECUTABLE)
+        ADD_CUSTOM_COMMAND(
+            OUTPUT ${_sip_output_files} APPEND
+            COMMAND ${SIP_MODULE_EXECUTABLE} --target-dir ${CMAKE_CURRENT_SIP_OUTPUT_DIR} --sip-h ${PYQT5_SIP_NAME}
+        )
+    ENDIF (SIP_MODULE_EXECUTABLE)
     # not sure if type MODULE could be uses anywhere, limit to cygwin for now
     IF (WIN32 OR CYGWIN OR APPLE)
         ADD_LIBRARY(${_logical_name} MODULE ${_sip_output_files} )
-- 
GitLab