From 48c8e0c44d4d2a563087171384df7efe8c0b86dc Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Sun, 29 May 2022 16:41:54 +0800 Subject: [PATCH] Allow building Python bindings with Qt6 --- CMakeLists.txt | 29 +++++++++++++++++++++-------- docs/source/building.rst | 2 +- src/CMakeLists.txt | 14 ++++++++++++-- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 60cd6c53..8145e362 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ option(CUTTER_USE_BUNDLED_RIZIN "Use rizin from ./rizin submodule instead of sea option(CUTTER_USE_ADDITIONAL_RIZIN_PATHS "Search rizin in additional paths which are not part of default system library paths.\ Disable this option if you are linking against rizin pacakged as proper system library or in a custom path and additional are paths causing problems." ON) option(CUTTER_ENABLE_PYTHON "Enable Python integration. Requires Python >= ${CUTTER_PYTHON_MIN}." OFF) -option(CUTTER_ENABLE_PYTHON_BINDINGS "Enable generating Python bindings with Shiboken2. Unused if CUTTER_ENABLE_PYTHON=OFF." OFF) +option(CUTTER_ENABLE_PYTHON_BINDINGS "Enable generating Python bindings with Shiboken. Unused if CUTTER_ENABLE_PYTHON=OFF." OFF) option(CUTTER_APPIMAGE_BUILD "Enable Appimage specific changes. Doesn't cause building of Appimage itself." OFF) tri_option(CUTTER_ENABLE_KSYNTAXHIGHLIGHTING "Use KSyntaxHighlighting" AUTO) tri_option(CUTTER_ENABLE_GRAPHVIZ "Enable use of graphviz for graph layout" AUTO) @@ -100,16 +100,29 @@ if(CUTTER_ENABLE_PYTHON) add_definitions(-DCUTTER_ENABLE_PYTHON) if(CUTTER_ENABLE_PYTHON_BINDINGS) - # 5.12.3 => 5.12 - if("${Qt5_VERSION}" MATCHES "^([0-9]+\\.[0-9]+)\\.[0-9]+") - set(Shiboken2_VERSION_REQUIRED "${CMAKE_MATCH_1}") + if (CUTTER_QT6) + # 6.12.3 => 6.12 + if("${Qt6_VERSION}" MATCHES "^([0-9]+\\.[0-9]+)\\.[0-9]+") + set(Shiboken6_VERSION_REQUIRED "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "Failed to recognize Qt version") + endif() + find_package(Shiboken6 "${Shiboken6_VERSION_REQUIRED}" REQUIRED) + find_package(Shiboken6Tools "${Shiboken6_VERSION_REQUIRED}" REQUIRED) + find_package(PySide6 "${Shiboken6_VERSION_REQUIRED}" REQUIRED) + get_target_property(PYSIDE_INCLUDE_DIR PySide6::pyside6 INTERFACE_INCLUDE_DIRECTORIES) else() - message(FATAL_ERROR "Failed to recognize Qt version") + # 5.12.3 => 5.12 + if("${Qt5_VERSION}" MATCHES "^([0-9]+\\.[0-9]+)\\.[0-9]+") + set(Shiboken2_VERSION_REQUIRED "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "Failed to recognize Qt version") + endif() + find_package(Shiboken2 "${Shiboken2_VERSION_REQUIRED}" REQUIRED) + find_package(PySide2 "${Shiboken2_VERSION_REQUIRED}" REQUIRED) + get_target_property(PYSIDE_INCLUDE_DIR PySide2::pyside2 INTERFACE_INCLUDE_DIRECTORIES) endif() - find_package(Shiboken2 "${Shiboken2_VERSION_REQUIRED}" REQUIRED) - find_package(PySide2 "${Shiboken2_VERSION_REQUIRED}" REQUIRED) - get_target_property(PYSIDE_INCLUDE_DIR PySide2::pyside2 INTERFACE_INCLUDE_DIRECTORIES) list(GET PYSIDE_INCLUDE_DIR 0 PYSIDE_INCLUDE_DIR) include_directories(${PYSIDE_INCLUDE_DIR} ${PYSIDE_INCLUDE_DIR}/QtCore diff --git a/docs/source/building.rst b/docs/source/building.rst index 924e638e..762cdd31 100644 --- a/docs/source/building.rst +++ b/docs/source/building.rst @@ -247,7 +247,7 @@ Note that there are some major building options available: * ``CUTTER_USE_BUNDLED_RIZIN`` automatically compile Rizin from submodule (Enabled by default). * ``CUTTER_ENABLE_PYTHON`` compile with Python support. -* ``CUTTER_ENABLE_PYTHON_BINDINGS`` automatically generate Python Bindings with Shiboken2, required for Python plugins! +* ``CUTTER_ENABLE_PYTHON_BINDINGS`` automatically generate Python Bindings with Shiboken, required for Python plugins! * ``CUTTER_ENABLE_KSYNTAXHIGHLIGHTING`` use KSyntaxHighlighting for code highlighting. * ``CUTTER_ENABLE_GRAPHVIZ`` enable Graphviz for graph layouts. * ``CUTTER_EXTRA_PLUGIN_DIRS`` List of addition plugin locations. Useful when preparing package for Linux distros that have strict package layout rules. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 19018beb..404f5d14 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -408,8 +408,14 @@ 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 Shiboken2::shiboken2 --project-file="${BINDINGS_BUILD_DIR}/bindings.txt" ${SHIBOKEN_OPTIONS} ${SHIBOKEN_EXTRA_OPTIONS} + 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" IMPLICIT_DEPENDS CXX "${CMAKE_CURRENT_SOURCE_DIR}/bindings/bindings.h" COMMENT "Generating Python bindings with shiboken2") @@ -487,7 +493,11 @@ if(CUTTER_ENABLE_PYTHON) endif() target_link_libraries(Cutter PRIVATE ${PYTHON_LIBRARIES}) if(CUTTER_ENABLE_PYTHON_BINDINGS) - target_link_libraries(Cutter PRIVATE Shiboken2::libshiboken PySide2::pyside2) + if (CUTTER_QT6) + target_link_libraries(Cutter PRIVATE Shiboken6::libshiboken PySide6::pyside6) + else() + target_link_libraries(Cutter PRIVATE Shiboken2::libshiboken PySide2::pyside2) + endif() get_target_property(RAW_BINDINGS_INCLUDE_DIRS Cutter INCLUDE_DIRECTORIES) if(NOT CUTTER_USE_BUNDLED_RIZIN)