Allow building Python bindings with Qt6

This commit is contained in:
Anton Kochkov 2022-05-29 16:41:54 +08:00 committed by Anton Kochkov
parent 9bfe0c4e1d
commit 48c8e0c44d
3 changed files with 34 additions and 11 deletions

View File

@ -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,6 +100,18 @@ if(CUTTER_ENABLE_PYTHON)
add_definitions(-DCUTTER_ENABLE_PYTHON)
if(CUTTER_ENABLE_PYTHON_BINDINGS)
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()
# 5.12.3 => 5.12
if("${Qt5_VERSION}" MATCHES "^([0-9]+\\.[0-9]+)\\.[0-9]+")
set(Shiboken2_VERSION_REQUIRED "${CMAKE_MATCH_1}")
@ -108,8 +120,9 @@ if(CUTTER_ENABLE_PYTHON)
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()
list(GET PYSIDE_INCLUDE_DIR 0 PYSIDE_INCLUDE_DIR)
include_directories(${PYSIDE_INCLUDE_DIR}
${PYSIDE_INCLUDE_DIR}/QtCore

View File

@ -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.

View File

@ -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)
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)