From aa40f6945823d08e171f5e16159d895e8cbd5ccc Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Thu, 16 Feb 2023 12:43:03 +0800 Subject: [PATCH] Specify PySide version in bindings template --- CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 18 ++++++++++-------- src/bindings/bindings.txt.in | 4 ++-- src/bindings/{bindings.xml => bindings.xml.in} | 2 +- src/bindings/src_list.py | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) rename src/bindings/{bindings.xml => bindings.xml.in} (97%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d567a49e..fa5bbbe7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,9 +110,13 @@ if(CUTTER_ENABLE_PYTHON) find_package(Shiboken6 "${Shiboken6_VERSION_REQUIRED}" REQUIRED) find_package(Shiboken6Tools "${Shiboken6_VERSION_REQUIRED}" REQUIRED) find_package(PySide6 "${Shiboken6_VERSION_REQUIRED}" REQUIRED) + get_target_property(LIBSHIBOKEN_INCLUDE_DIRS Shiboken6::libshiboken INTERFACE_INCLUDE_DIRECTORIES) get_target_property(PYSIDE_INCLUDE_DIR PySide6::pyside6 INTERFACE_INCLUDE_DIRECTORIES) # Check the presence of "pysidecleanup.h" + include(CheckIncludeFileCXX) + set(CMAKE_REQUIRED_INCLUDES "${PYSIDE_INCLUDE_DIR};${LIBSHIBOKEN_INCLUDE_DIRS}") CHECK_INCLUDE_FILE_CXX("pysidecleanup.h" HAVE_PYSIDECLEANUP) + add_compile_definitions("HAVE_PYSIDECLEANUP=${HAVE_PYSIDECLEANUP}") else() # 5.12.3 => 5.12 if("${Qt5_VERSION}" MATCHES "^([0-9]+\\.[0-9]+)\\.[0-9]+") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1533719e..009b2962 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -394,10 +394,18 @@ if (CUTTER_ENABLE_PYTHON) endif() if(CUTTER_ENABLE_PYTHON_BINDINGS) + if (CUTTER_QT6) + set(PYSIDE_NAME PySide6) + set(SHIBOKEN_COMMAND Shiboken6::shiboken6) + else() + set(PYSIDE_NAME PySide2) + set(SHIBOKEN_COMMAND Shiboken2::shiboken2) + endif() + set(BINDINGS_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/bindings") set(BINDINGS_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/bindings") - configure_file("${BINDINGS_SRC_DIR}/bindings.xml" "${BINDINGS_BUILD_DIR}/bindings.xml" COPYONLY) # trigger reconfigure if file changes + configure_file("${BINDINGS_SRC_DIR}/bindings.xml.in" "${BINDINGS_BUILD_DIR}/bindings.xml") execute_process(COMMAND "${PYTHON_EXECUTABLE}" "${BINDINGS_SRC_DIR}/src_list.py" cmake "${BINDINGS_BUILD_DIR}" OUTPUT_VARIABLE BINDINGS_SOURCE) @@ -436,15 +444,9 @@ if(CUTTER_ENABLE_PYTHON_BINDINGS) list(APPEND SHIBOKEN_OPTIONS --avoid-protected-hack) endif() - if (CUTTER_QT6) - set(SHIBOKEN_COMMAND Shiboken6::shiboken6) - else() - set(SHIBOKEN_COMMAND Shiboken2::shiboken2) - endif() - add_custom_command(OUTPUT ${BINDINGS_SOURCE} COMMAND "${SHIBOKEN_COMMAND}" --project-file="${BINDINGS_BUILD_DIR}/bindings.txt" ${SHIBOKEN_OPTIONS} ${SHIBOKEN_EXTRA_OPTIONS} - DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/bindings/bindings.xml" "${BINDINGS_BUILD_DIR}/bindings.txt" + DEPENDS "${BINDINGS_BUILD_DIR}/bindings.xml" "${BINDINGS_BUILD_DIR}/bindings.txt" IMPLICIT_DEPENDS CXX "${CMAKE_CURRENT_SOURCE_DIR}/bindings/bindings.h" COMMENT "Generating Python bindings with shiboken2") else() diff --git a/src/bindings/bindings.txt.in b/src/bindings/bindings.txt.in index dd478889..5eb103ee 100644 --- a/src/bindings/bindings.txt.in +++ b/src/bindings/bindings.txt.in @@ -3,7 +3,7 @@ generator-set = shiboken header-file = ${BINDINGS_SRC_DIR}/bindings.h -typesystem-file = ${BINDINGS_SRC_DIR}/bindings.xml +typesystem-file = ${BINDINGS_BUILD_DIR}/bindings.xml output-directory = ${BINDINGS_BUILD_DIR} @@ -14,4 +14,4 @@ typesystem-paths = ${PYSIDE_TYPESYSTEMS} enable-parent-ctor-heuristic enable-pyside-extensions enable-return-value-heuristic -use-isnull-as-nb_nonzero \ No newline at end of file +use-isnull-as-nb_nonzero diff --git a/src/bindings/bindings.xml b/src/bindings/bindings.xml.in similarity index 97% rename from src/bindings/bindings.xml rename to src/bindings/bindings.xml.in index 36386558..0fa194a9 100644 --- a/src/bindings/bindings.xml +++ b/src/bindings/bindings.xml.in @@ -30,7 +30,7 @@ PyErr_Print(); return QString(); } - PythonToCppFunc pythonToCpp = Shiboken::Conversions::isPythonToCppConvertible(SbkPySide2_QtCoreTypeConverters[SBK_QSTRING_IDX], pyResult); + PythonToCppFunc pythonToCpp = Shiboken::Conversions::isPythonToCppConvertible(Sbk${PYSIDE_NAME}_QtCoreTypeConverters[SBK_QSTRING_IDX], pyResult); if (!pythonToCpp) { Shiboken::warning(PyExc_RuntimeWarning, 2, "Invalid return value for plugin metadata VAR_NAME, expected %s, got %s.", "QString", Py_TYPE(pyResult)->tp_name); return ::QString(); diff --git a/src/bindings/src_list.py b/src/bindings/src_list.py index 3175b39e..69e06f5a 100755 --- a/src/bindings/src_list.py +++ b/src/bindings/src_list.py @@ -9,7 +9,7 @@ script_path = os.path.dirname(os.path.realpath(__file__)) def get_cpp_files_gen(args, include_package=True): - ts_tree = et.parse(os.path.join(script_path, "bindings.xml")) + ts_tree = et.parse(os.path.join(script_path, "bindings.xml.in")) ts_root = ts_tree.getroot() package = ts_root.attrib["package"]