Skip to content

Commit

Permalink
Simplify python binding include handling (#3268)
Browse files Browse the repository at this point in the history
* Simplify python binding include handling

* remove duplicate code introduced in #2952
* specify include path using  multiple include-path lines instead  instead of single line with with directories separated by ; or :
* Fix macoS qt6 python bindings build
  • Loading branch information
karliss authored Nov 29, 2023
1 parent 653435c commit a6af291
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 35 deletions.
50 changes: 16 additions & 34 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -429,33 +429,7 @@ if(CUTTER_ENABLE_PYTHON_BINDINGS)

include_directories("${BINDINGS_BUILD_DIR}/CutterBindings")

set(SHIBOKEN_INCLUDE_DIRS "")
if(APPLE AND _qt6Core_install_prefix)
list(APPEND BINDINGS_INCLUDE_DIRS "${_qt6Core_install_prefix}/include")
list(APPEND BINDINGS_INCLUDE_DIRS "${_qt6Core_install_prefix}/include/QtCore")
list(APPEND BINDINGS_INCLUDE_DIRS "${_qt6Core_install_prefix}/include/QtGui")
list(APPEND BINDINGS_INCLUDE_DIRS "${_qt6Core_install_prefix}/include/QtWidgets")
endif()

if (CUTTER_QT6)
list(APPEND SHIBOKEN_INCLUDE_DIRS ${Qt6Core_INCLUDE_DIRS} ${Qt6Widgets_INCLUDE_DIRS} ${Qt6Gui_INCLUDE_DIRS})
else()
list(APPEND SHIBOKEN_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS})
endif()

foreach(_dir ${CUTTER_INCLUDE_DIRECTORIES})
list(APPEND SHIBOKEN_INCLUDE_DIRS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${_dir}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/cutter/${_dir}>
)
endforeach()
list(APPEND SHIBOKEN_INCLUDE_DIRS ${Rizin_INCLUDE_DIRS})
if (NOT WIN32)
string(REPLACE ";" ":" SHIBOKEN_INCLUDE_DIRS "${SHIBOKEN_INCLUDE_DIRS}")
endif()

set(SHIBOKEN_OPTIONS)
list(APPEND SHIBOKEN_OPTIONS --include-paths="${SHIBOKEN_INCLUDE_DIRS}")
if (WIN32)
list(APPEND SHIBOKEN_OPTIONS --avoid-protected-hack)
endif()
Expand Down Expand Up @@ -558,11 +532,16 @@ if(CUTTER_ENABLE_PYTHON)
endif()
endforeach()

if(APPLE AND _qt5Core_install_prefix)
list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include")
list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include/QtCore")
list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include/QtGui")
list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include/QtWidgets")
set(BINDINGS_INCLUDE_DIR_LINES "")
if(APPLE)
if (_qt5Core_install_prefix)
list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include")
list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include/QtCore")
list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include/QtGui")
list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include/QtWidgets")
elseif(CUTTER_QT6)
string(APPEND BINDINGS_INCLUDE_DIR_LINES "framework-include-path=${QT6_INSTALL_PREFIX}/${QT6_INSTALL_LIBS}\n")
endif()
endif()
if (CUTTER_QT6)
list(APPEND BINDINGS_INCLUDE_DIRS ${Qt6Core_INCLUDE_DIRS} ${Qt6Widgets_INCLUDE_DIRS} ${Qt6Gui_INCLUDE_DIRS})
Expand All @@ -571,9 +550,12 @@ if(CUTTER_ENABLE_PYTHON)
endif()
list(APPEND BINDINGS_INCLUDE_DIRS ${Rizin_INCLUDE_DIRS})
list(APPEND BINDINGS_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}")
if (NOT WIN32)
string(REPLACE ";" ":" BINDINGS_INCLUDE_DIRS "${BINDINGS_INCLUDE_DIRS}")
endif()

foreach(_dir ${BINDINGS_INCLUDE_DIRS})
if (NOT "${_dir}" STREQUAL "")
string(APPEND BINDINGS_INCLUDE_DIR_LINES "include-path = ${_dir}\n")
endif()
endforeach()

configure_file("${BINDINGS_SRC_DIR}/bindings.txt.in" "${BINDINGS_BUILD_DIR}/bindings.txt")
add_definitions(-DWIN32_LEAN_AND_MEAN)
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/bindings.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typesystem-file = ${BINDINGS_BUILD_DIR}/bindings.xml

output-directory = ${BINDINGS_BUILD_DIR}

include-path = ${BINDINGS_INCLUDE_DIRS}
${BINDINGS_INCLUDE_DIR_LINES}

typesystem-paths = ${PYSIDE_TYPESYSTEMS}

Expand Down

0 comments on commit a6af291

Please sign in to comment.