[graphics/krita] /: Add support for SIP v5 bindings

L. E. Segovia null at kde.org
Tue Jun 15 15:10:00 BST 2021


Git commit 5bb4874ad04b771a0fec12827de748780b5b395b by L. E. Segovia.
Committed on 23/05/2021 at 02:34.
Pushed by lsegovia into branch 'master'.

Add support for SIP v5 bindings

SIP v5 and above rely on a PEP-0518 based tooling system to build
bindings (usually distutils). v4, as our currently supported generator,
is only a dummy tool -- it relies on the user to compile and link the
bindings.

This commit adds support for SIP v5.

- I've added a "sip-generate" tool, that differs from the standard
sip-build in that it only generates the binding glue; this relies on a
private, undocumented method of the sipbuild.Builder class.

- The cmake/modules directory now has a pyproject.toml skeleton
manifest, which is processed by the new add_sip_python_module_v5 macro.
It works identically to the v4 macro, but targets the sip-generate tool.
Compilation happens in the exact same was as we do with v4.

Key remarks:

- All the data must be now injected in the skeleton manifest (as opposed
to build flags in v4).
- SIP v5 makes use of protected Qt methods; for this reason, it supplies
a "protected-as-public" override, which I emulate in the
add_sip_python_module_v5 macro.
- Like v4, v5 also needs to be told the fully qualified name of the SIP
package (e.g. `import PyQt5.sip` -- PyQt5.sip is the value). Otherwise,
the native library will not find the package and the initialization will
fail.
- The initialization function changes, from "PyInit_pykrita" to
"PyInit_krita" (the innermost module name). This has been macro'd for
backwards compatibility.

BUG: 415743

CCMAIL: kimageshop at kde.org

M  +5    -0    cmake/modules/FindPyQt5.cmake
M  +5    -0    cmake/modules/FindPyQt5.py
M  +3    -3    cmake/modules/FindSIP.cmake
M  +7    -4    cmake/modules/FindSIP.py
M  +103  -6    cmake/modules/SIPMacros.cmake
A  +15   -0    cmake/modules/pyproject.toml.in
A  +24   -0    cmake/modules/sip-generate.py
M  +2    -3    plugins/extensions/pykrita/plugin/PykritaModule.cpp
M  +9    -1    plugins/extensions/pykrita/plugin/PykritaModule.h
M  +3    -0    plugins/extensions/pykrita/plugin/config.h.cmake
M  +3    -2    plugins/extensions/pykrita/plugin/utilities.cpp
M  +33   -25   plugins/extensions/pykrita/sip/CMakeLists.txt

https://invent.kde.org/graphics/krita/commit/5bb4874ad04b771a0fec12827de748780b5b395b

diff --git a/cmake/modules/FindPyQt5.cmake b/cmake/modules/FindPyQt5.cmake
index 150ed88898..bbbfa52279 100644
--- a/cmake/modules/FindPyQt5.cmake
+++ b/cmake/modules/FindPyQt5.cmake
@@ -1,6 +1,7 @@
 # Find PyQt5
 # ~~~~~~~~~~
 # SPDX-FileCopyrightText: 2014 Simon Edwards <simon at simonzone.com>
+# SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -21,6 +22,8 @@
 # PYQT5_SIP_DIR - The directory holding the PyQt5 .sip files.
 #
 # PYQT5_SIP_FLAGS - The SIP flags used to build PyQt.
+#
+# PYQT5_SIP_TAGS - The SIP tags necessary to bind to PyQt. (v5+)
 
 IF(EXISTS PYQT5_VERSION)
   # Already in cache, be silent
@@ -49,6 +52,8 @@ ELSE(EXISTS PYQT5_VERSION)
     STRING(REGEX REPLACE ".*\npyqt_version_tag:([^\n]+).*$" "\\1" PYQT5_VERSION_TAG ${pyqt5_config})
     STRING(REGEX REPLACE ".*\npyqt_sip_dir:([^\n]+).*$" "\\1" PYQT5_SIP_DIR ${pyqt5_config})
     STRING(REGEX REPLACE ".*\npyqt_sip_flags:([^\n]+).*$" "\\1" PYQT5_SIP_FLAGS ${pyqt5_config})
+    STRING(REGEX REPLACE ".*\npyqt_sip_tags:([^\n]+).*$" "\\1" _tags ${pyqt5_config})
+    STRING(REPLACE "," ";" PYQT5_SIP_TAGS ${_tags})
     IF(${pyqt5_config} MATCHES pyqt_sip_name)
       STRING(REGEX REPLACE ".*\npyqt_sip_name:([^\n]+).*$" "\\1" PYQT5_SIP_NAME ${pyqt5_config})
     ENDIF(${pyqt5_config} MATCHES pyqt_sip_name)
diff --git a/cmake/modules/FindPyQt5.py b/cmake/modules/FindPyQt5.py
index 171e8dc461..e4293d5be7 100644
--- a/cmake/modules/FindPyQt5.py
+++ b/cmake/modules/FindPyQt5.py
@@ -1,8 +1,10 @@
 # SPDX-FileCopyrightText: 2014 Simon Edwards <simon at simonzone.com>
+# SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
+import re
 import sys
 import os
 from distutils.sysconfig import get_python_lib
@@ -48,3 +50,6 @@ if not os.path.exists(pyqt_sip_dir):  # Fallback for older PyQt5/SIP
 print("pyqt_sip_dir:%s" % pyqt_sip_dir)
 
 print("pyqt_sip_flags:%s" % PyQt5.QtCore.PYQT_CONFIGURATION["sip_flags"])
+
+tags = re.findall(r"-t ([^\s]+)", PyQt5.QtCore.PYQT_CONFIGURATION["sip_flags"])
+print("pyqt_sip_tags:%s" % ",".join(tags))
diff --git a/cmake/modules/FindSIP.cmake b/cmake/modules/FindSIP.cmake
index 1a02fd92af..f8675153a2 100644
--- a/cmake/modules/FindSIP.cmake
+++ b/cmake/modules/FindSIP.cmake
@@ -42,10 +42,10 @@ ELSE(SIP_VERSION)
     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)
     IF(${SIP_VERSION_STR} VERSION_LESS 5)
+        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_INCLUDE_DIR} SIP_INCLUDE_DIR)
     ELSE(${SIP_VERSION_STR} VERSION_LESS 5)
diff --git a/cmake/modules/FindSIP.py b/cmake/modules/FindSIP.py
index 63f62f6c45..424620d6ee 100644
--- a/cmake/modules/FindSIP.py
+++ b/cmake/modules/FindSIP.py
@@ -1,6 +1,7 @@
 # FindSIP.py
 #
 # SPDX-FileCopyrightText: 2007 Simon Edwards <simon at simonzone.com>
+# SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -14,8 +15,6 @@ def osAwareSuffix():
     return os.path.join("lib", "python3.8", "site-packages","sipconfig.py") if os.name != 'nt' else os.path.join("lib","krita-python-libs","sipconfig.py")
 
 try:
-    import sipbuild
-except ImportError:  # Code for SIP v4
     import sipconfig
 
     sipcfg = sipconfig.Configuration()
@@ -42,12 +41,16 @@ except ImportError:  # Code for SIP v4
     print("sip_bin:%s" % sip_bin)
     print("default_sip_dir:%s" % default_sip_dir)
     print("sip_inc_dir:%s" % sip_inc_dir)
-else:  # Code for SIP v5
+except ImportError:  # Code for SIP v5+
+    import sipbuild
+
     print("sip_version:%06.0x" % sipbuild.version.SIP_VERSION)
     print("sip_version_str:%s" % sipbuild.version.SIP_VERSION_STR)
 
     import shutil
-    print("sip_bin:%s" % shutil.which("sip5"))
+
+    # sip v5 and higher need to invoke sip-build
+    print("sip_bin:%s" % shutil.which("sip-build"))
 
     from distutils.sysconfig import get_python_lib
     python_modules_dir = get_python_lib(plat_specific=1)
diff --git a/cmake/modules/SIPMacros.cmake b/cmake/modules/SIPMacros.cmake
index 6042d55986..e8017b3a84 100644
--- a/cmake/modules/SIPMacros.cmake
+++ b/cmake/modules/SIPMacros.cmake
@@ -41,6 +41,8 @@ SET(SIP_CONCAT_PARTS 8)
 SET(SIP_DISABLE_FEATURES)
 SET(SIP_EXTRA_OPTIONS)
 
+if (${SIP_VERSION_STR} VERSION_LESS 5)
+
 MACRO(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
 
     SET(EXTRA_LINK_LIBRARIES ${ARGN})
@@ -99,12 +101,6 @@ 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} )
@@ -126,3 +122,104 @@ MACRO(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
     INSTALL(TARGETS ${_logical_name} DESTINATION "${PYTHON_SITE_PACKAGES_INSTALL_DIR}/${_parent_module_path}")
 
 ENDMACRO(ADD_SIP_PYTHON_MODULE)
+
+else()
+    find_file(sip_generate "sip-generate.py" PATHS ${CMAKE_MODULE_PATH})
+    find_file(pyproject_toml "pyproject.toml.in" PATHS ${CMAKE_MODULE_PATH})
+
+    macro(add_sip_python_module_v5 MODULE_NAME MODULE_SIP)        
+        get_filename_component(module_name_toml ${MODULE_SIP} NAME_WE)
+        set(module_srcs "${SIP_EXTRA_FILES_DEPEND}")
+
+        set(EXTRA_LINK_LIBRARIES ${ARGN})
+
+        if (SIP_MODULE)
+            set(sip_name ${SIP_MODULE})
+        else()
+            set(sip_name "sip")
+        endif()
+
+        set(module_tags)
+        foreach(_tag ${SIP_TAGS})
+            string(APPEND module_tags "\"${_tag}\",")
+        endforeach()
+        set(module_tags "[${module_tags}]")
+
+        set(sip_include_dirs)
+        foreach(_inc ${SIP_INCLUDES})
+            get_filename_component(_abs_inc ${_inc} ABSOLUTE)
+            string(APPEND sip_include_dirs "\"${_abs_inc}\",")
+        endforeach()
+        set(sip_include_dirs "[${sip_include_dirs}]")
+
+        string(REPLACE "." "/" _x ${MODULE_NAME})
+        get_filename_component(_parent_module_path ${_x} PATH)
+        get_filename_component(_child_module_name ${_x} NAME)
+
+        get_filename_component(_module_path ${MODULE_SIP} PATH)
+
+        set(CMAKE_CURRENT_SIP_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/_tmp")
+
+        get_filename_component(_abs_module_sip ${MODULE_SIP} ABSOLUTE)
+
+        # We give this target a long logical target name.
+        # (This is to avoid having the library name clash with any already
+        # install library names. If that happens then cmake dependency
+        # tracking get confused.)
+        string(REPLACE "." "_" _logical_name ${MODULE_NAME})
+        set(_logical_name "python_module_${_logical_name}")
+
+        set(_sip_output_files)
+        foreach(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS})
+            if(${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS})
+                set(_sip_output_files ${_sip_output_files} ${CMAKE_CURRENT_SIP_OUTPUT_DIR}/${_child_module_name}/sip${_child_module_name}part${CONCAT_NUM}.cpp )
+            endif( ${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS})
+        endforeach(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS})
+
+        configure_file(
+            ${pyproject_toml}
+            ${CMAKE_CURRENT_BINARY_DIR}/pyproject.toml
+        )
+        add_custom_command(
+            COMMAND
+                ${CMAKE_COMMAND} -E echo "Generating SIP 5+ bindings for ${MODULE_NAME}..."
+            COMMAND
+                ${PYTHON_EXECUTABLE}
+                ${sip_generate}
+                --build-dir ${CMAKE_CURRENT_SIP_OUTPUT_DIR}
+                --target-dir ${PYTHON_SITE_PACKAGES_INSTALL_DIR}/${_parent_module_path}
+                --concatenate ${SIP_CONCAT_PARTS}
+            WORKING_DIRECTORY
+                ${CMAKE_CURRENT_BINARY_DIR}
+            DEPENDS
+                ${CMAKE_CURRENT_BINARY_DIR}/pyproject.toml
+            OUTPUT
+                ${_sip_output_files}
+        )
+
+        # not sure if type MODULE could be usec anywhere, limit to cygwin for now
+        if (WIN32 OR CYGWIN OR APPLE)
+            add_library(${_logical_name} MODULE ${_sip_output_files})
+        else ()
+            add_library(${_logical_name} SHARED ${_sip_output_files})
+        endif ()
+        target_include_directories(${_logical_name} PRIVATE ${CMAKE_CURRENT_SIP_OUTPUT_DIR})
+        target_link_libraries(${_logical_name} ${PYTHON_LIBRARY})
+        target_link_libraries(${_logical_name} ${EXTRA_LINK_LIBRARIES})
+        set_target_properties(${_logical_name} PROPERTIES PREFIX "" OUTPUT_NAME ${_child_module_name})
+
+        if (MINGW)
+            target_compile_definitions(${_logical_name} PRIVATE _hypot=hypot)
+        else()
+            # SIP v5+ redefines access to protected variables.
+            target_compile_definitions(${_logical_name} PRIVATE SIP_PROTECTED_IS_PUBLIC)
+            target_compile_definitions(${_logical_name} PRIVATE protected=public)
+        endif ()
+
+        if (WIN32)
+            SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES SUFFIX ".pyd")
+        ENDIF ()
+
+        install(TARGETS ${_logical_name} DESTINATION "${PYTHON_SITE_PACKAGES_INSTALL_DIR}/${_parent_module_path}")
+    endmacro()
+endif()
diff --git a/cmake/modules/pyproject.toml.in b/cmake/modules/pyproject.toml.in
new file mode 100644
index 0000000000..090b2d4b0c
--- /dev/null
+++ b/cmake/modules/pyproject.toml.in
@@ -0,0 +1,15 @@
+[build-system]
+requires = ["sip >=5, <7", "PyQt5"]
+build-backend = "sipbuild.api"
+
+[tool.sip.metadata]
+name = "@module_name_toml@"
+
+[tool.sip.project]
+sip-module = "@sip_name@"
+sip-include-dirs = @sip_include_dirs@
+sip-files-dir = "@module_srcs@"
+abi-version = "12"
+
+[tool.sip.bindings. at module_name_toml@]
+tags = @module_tags@
diff --git a/cmake/modules/sip-generate.py b/cmake/modules/sip-generate.py
new file mode 100644
index 0000000000..d55116a230
--- /dev/null
+++ b/cmake/modules/sip-generate.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+# SPDX-FileCopyrightText: 2019 Riverbank Computing Limited
+# SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+from sipbuild.abstract_project import AbstractProject
+from sipbuild.exceptions import handle_exception
+
+def main():
+    """ Generate the project bindings from the command line. """
+
+    try:
+        project = AbstractProject.bootstrap(
+            'build', "Generate the project bindings.")
+        project.builder._generate_bindings()
+        project.progress("The project bindings are ready for build.")
+    except Exception as e:
+        handle_exception(e)
+
+    return 0
+
+if __name__ == "__main__":
+    main()
diff --git a/plugins/extensions/pykrita/plugin/PykritaModule.cpp b/plugins/extensions/pykrita/plugin/PykritaModule.cpp
index f0f9e76c96..4379080aa2 100644
--- a/plugins/extensions/pykrita/plugin/PykritaModule.cpp
+++ b/plugins/extensions/pykrita/plugin/PykritaModule.cpp
@@ -3,6 +3,7 @@
 // SPDX-FileCopyrightText: 2006 Paul Giannaros <paul at giannaros.org>
 // SPDX-FileCopyrightText: 2012, 2013 Shaheed Haque <srhaque at theiet.org>
 // SPDX-FileCopyrightText: 2013 Alex Turbov <i.zaufi at gmail.com>
+// SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
 //
 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 //
@@ -11,8 +12,6 @@
 
 #include "kis_debug.h"
 
-#define PYKRITA_INIT PyInit_pykrita
-
 struct module_state {
     PyObject *error;
 };
@@ -70,7 +69,7 @@ static struct PyModuleDef moduledef = {
 
 #define INITERROR return NULL
 
-PyMODINIT_FUNC PyInit_pykrita()
+PyMODINIT_FUNC PYKRITA_INIT()
 
 #else
 #define INITERROR return
diff --git a/plugins/extensions/pykrita/plugin/PykritaModule.h b/plugins/extensions/pykrita/plugin/PykritaModule.h
index dc0a91d0fc..4c75222966 100644
--- a/plugins/extensions/pykrita/plugin/PykritaModule.h
+++ b/plugins/extensions/pykrita/plugin/PykritaModule.h
@@ -3,6 +3,7 @@
  *
  * SPDX-FileCopyrightText: 2013 Alex Turbov <i.zaufi at gmail.com>
  * SPDX-FileCopyrightText: 2014-2016 Boudewijn Rempt <boud at valdyas.org>
+ * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
  *
  * SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only
  */
@@ -11,6 +12,7 @@
 #define  __PYKRITA_MODULE_H__
 
 #include <Python.h>
+#include "config.h"
 
 #if PY_MAJOR_VERSION >= 3
 #ifndef IS_PY3K
@@ -18,11 +20,17 @@
 #endif
 #endif
 
+#if SIP_VERSION >= 0x0500000
+#define PYKRITA_INIT PyInit_krita
+#else
+#define PYKRITA_INIT PyInit_pykrita
+#endif
+
 /**
  * Initializer for the built-in Python module.
  */
 #if defined(IS_PY3K)
-PyMODINIT_FUNC PyInit_pykrita();
+PyMODINIT_FUNC PYKRITA_INIT();
 #else
 void initpykrita();
 #endif
diff --git a/plugins/extensions/pykrita/plugin/config.h.cmake b/plugins/extensions/pykrita/plugin/config.h.cmake
index c84ea0c9ab..d1c3c9f015 100644
--- a/plugins/extensions/pykrita/plugin/config.h.cmake
+++ b/plugins/extensions/pykrita/plugin/config.h.cmake
@@ -1,10 +1,13 @@
 // This file is part of PyKrita, Krita' Python scripting plugin.
 //
 // SPDX-FileCopyrightText: 2006 Paul Giannaros <paul at giannaros.org>
+// SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
 //
 // SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only
 
 #define PYKRITA_PYTHON_LIBRARY "${PYTHON_LIBRARY}"
 
+#define SIP_VERSION 0x at SIP_VERSION@
+
 /// Name of the file where per-plugin configuration is stored
 #define CONFIG_FILE "kritapykritarc"
diff --git a/plugins/extensions/pykrita/plugin/utilities.cpp b/plugins/extensions/pykrita/plugin/utilities.cpp
index 37781bf750..83f99b2f2c 100644
--- a/plugins/extensions/pykrita/plugin/utilities.cpp
+++ b/plugins/extensions/pykrita/plugin/utilities.cpp
@@ -2,6 +2,7 @@
 //
 // SPDX-FileCopyrightText: 2006 Paul Giannaros <paul at giannaros.org>
 // SPDX-FileCopyrightText: 2012, 2013 Shaheed Haque <srhaque at theiet.org>
+// SPDX-FileCopyrightText: 2021 L. E. Segovia <amy at amyspark.me>
 //
 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 //
@@ -63,7 +64,7 @@ namespace PyKrita
         }
 
 #if defined(IS_PY3K)
-        if (0 != PyImport_AppendInittab(Python::PYKRITA_ENGINE, PyInit_pykrita)) {
+        if (0 != PyImport_AppendInittab(Python::PYKRITA_ENGINE, PYKRITA_INIT)) {
 #else
         if (0 != PyImport_AppendInittab(Python::PYKRITA_ENGINE, initpykrita)) {
 #endif
@@ -82,7 +83,7 @@ namespace PyKrita
 
 #if defined(IS_PY3K)
         // Initialize our built-in module.
-        auto pykritaModule = PyInit_pykrita();
+        auto pykritaModule = PYKRITA_INIT();
 
         if (!pykritaModule) {
             initStatus = INIT_CANNOT_LOAD_PYKRITA_MODULE;
diff --git a/plugins/extensions/pykrita/sip/CMakeLists.txt b/plugins/extensions/pykrita/sip/CMakeLists.txt
index 23a13426f0..07611d5a09 100644
--- a/plugins/extensions/pykrita/sip/CMakeLists.txt
+++ b/plugins/extensions/pykrita/sip/CMakeLists.txt
@@ -3,33 +3,41 @@ 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.")
-IF(${SIP_VERSION_STR} VERSION_LESS 5)
+if(${SIP_VERSION_STR} VERSION_LESS 5)
+    message( ${SIP_DEFAULT_SIP_DIR} " - default SIP dir" )
     message( ${SIP_INCLUDE_DIR} " - Directory holding the SIP C++ header file.")
-ENDIF(${SIP_VERSION_STR} VERSION_LESS 5)
-message( ${SIP_DEFAULT_SIP_DIR} " - default SIP dir" )
 
-set(SIP_INCLUDES
-    ${SIP_DEFAULT_SIP_DIR}
-    ${PYQT5_SIP_DIR}
-    ${PYQT_SIP_DIR_OVERRIDE}
-     ./krita)
+    set(SIP_INCLUDES
+        ${SIP_DEFAULT_SIP_DIR}
+        ${PYQT5_SIP_DIR}
+        ${PYQT_SIP_DIR_OVERRIDE}
+        ./krita)
 
-set(SIP_CONCAT_PARTS 1)
-set(SIP_TAGS ALL WS_X11 ${PYQT5_VERSION_TAG})
-set(SIP_EXTRA_OPTIONS -g -o -x PyKDE_QVector)
-IF (PYQT5_SIP_NAME)
-    set(SIP_EXTRA_OPTIONS ${SIP_EXTRA_OPTIONS} -n ${PYQT5_SIP_NAME})
-ENDIF (PYQT5_SIP_NAME)
+    set(SIP_CONCAT_PARTS 1)
+    set(SIP_TAGS ALL WS_X11 ${PYQT5_VERSION_TAG})
+    set(SIP_EXTRA_OPTIONS -g -o -x PyKDE_QVector)
+    IF (PYQT5_SIP_NAME)
+        set(SIP_EXTRA_OPTIONS ${SIP_EXTRA_OPTIONS} -n ${PYQT5_SIP_NAME})
+    ENDIF (PYQT5_SIP_NAME)
 
-set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${LIB_INSTALL_DIR}/krita-python-libs)
-file(GLOB PYKRITA_KRITA_sip_files ./krita/*.sip)
-set(SIP_EXTRA_FILES_DEPEND ${PYKRITA_KRITA_sip_files})
-add_sip_python_module(PyKrita.krita ./krita/kritamod.sip kritalibkis kritaui kritaimage kritalibbrush)
+    set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${LIB_INSTALL_DIR}/krita-python-libs)
+    file(GLOB PYKRITA_KRITA_sip_files ./krita/*.sip)
+    set(SIP_EXTRA_FILES_DEPEND ${PYKRITA_KRITA_sip_files})
+    add_sip_python_module(PyKrita.krita ./krita/kritamod.sip kritalibkis kritaui kritaimage kritalibbrush)
 
-if (ENABLE_PYTHON_2)
-    # Add an init file to turn it into a valid py2 module.
-    # Otherwise PyKrita cannot be loaded.
-    install(FILES
-        ./__init__.py
-        DESTINATION ${PYTHON_SITE_PACKAGES_INSTALL_DIR}/PyKrita)
-endif (ENABLE_PYTHON_2)
+    if (ENABLE_PYTHON_2)
+        # Add an init file to turn it into a valid py2 module.
+        # Otherwise PyKrita cannot be loaded.
+        install(FILES
+            ./__init__.py
+            DESTINATION ${PYTHON_SITE_PACKAGES_INSTALL_DIR}/PyKrita)
+    endif (ENABLE_PYTHON_2)
+else()
+    set(SIP_CONCAT_PARTS 1)
+    set(SIP_MODULE ${PYQT5_SIP_NAME})
+    set(SIP_TAGS ${PYQT5_SIP_TAGS})
+    set(SIP_INCLUDES ${PYQT5_SIP_DIR})
+    set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${LIB_INSTALL_DIR}/krita-python-libs)
+    set(SIP_EXTRA_FILES_DEPEND "${CMAKE_CURRENT_SOURCE_DIR}/krita")
+    add_sip_python_module_v5(PyKrita.krita ./krita/kritamod.sip kritalibkis kritaui kritaimage kritalibbrush)
+endif()



More information about the kimageshop mailing list