Generate Bindings in QMake

Fix typesystem-paths
This commit is contained in:
Florian Märkl 2019-02-11 21:26:11 +01:00
parent 436842222e
commit 2be8ec8456
7 changed files with 125 additions and 55 deletions

View File

@ -124,23 +124,22 @@ qmake_configure_file("${CMAKE_CURRENT_SOURCE_DIR}/CutterConfig.h.in"
if(CUTTER_ENABLE_PYTHON_BINDINGS)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bindings/bindings.xml"
"${CMAKE_CURRENT_BINARY_DIR}/bindings/bindings.xml"
COPYONLY) # trigger reconfigure if file changes
set(BINDINGS_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/bindings")
set(BINDINGS_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/bindings")
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/bindings/src_list.py" cmake "${CMAKE_CURRENT_BINARY_DIR}/bindings"
OUTPUT_VARIABLE BINDINGS_SOURCE)
configure_file("${BINDINGS_SRC_DIR}/bindings.xml" "${BINDINGS_BUILD_DIR}/bindings.xml" COPYONLY) # trigger reconfigure if file changes
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "${BINDINGS_SRC_DIR}/src_list.py" cmake "${BINDINGS_BUILD_DIR}" OUTPUT_VARIABLE BINDINGS_SOURCE)
set_property(SOURCE ${BINDINGS_SOURCE} PROPERTY SKIP_AUTOGEN ON)
include_directories("${CMAKE_CURRENT_BINARY_DIR}/bindings/CutterBindings")
include_directories("${BINDINGS_BUILD_DIR}/CutterBindings")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/widgets")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/common")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/plugins")
add_custom_command(OUTPUT ${BINDINGS_SOURCE}
COMMAND shiboken2 --project-file="${CMAKE_CURRENT_BINARY_DIR}/bindings/bindings.txt"
COMMAND shiboken2 --project-file="${BINDINGS_BUILD_DIR}/bindings.txt"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/bindings/bindings.xml"
IMPLICIT_DEPENDS CXX "${CMAKE_CURRENT_SOURCE_DIR}/bindings/bindings.h"
COMMENT "Generating Python bindings with shiboken2")
@ -170,8 +169,7 @@ if(CUTTER_ENABLE_PYTHON)
list(APPEND BINDINGS_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} "${CMAKE_CURRENT_SOURCE_DIR}")
string(REPLACE ";" ":" BINDINGS_INCLUDE_DIRS "${BINDINGS_INCLUDE_DIRS}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bindings/bindings.txt.in"
"${CMAKE_CURRENT_BINARY_DIR}/bindings/bindings.txt" @ONLY)
qmake_configure_file("${BINDINGS_SRC_DIR}/bindings.txt.in" "${BINDINGS_BUILD_DIR}/bindings.txt")
endif()
endif()

View File

@ -32,25 +32,54 @@ QT += core gui widgets svg network
QT_CONFIG -= no-pkg-config
CONFIG += c++11
!defined(CUTTER_ENABLE_JUPYTER, var) CUTTER_ENABLE_JUPYTER=true
equals(CUTTER_ENABLE_JUPYTER, true) CONFIG += CUTTER_ENABLE_JUPYTER
!defined(CUTTER_ENABLE_PYTHON, var) CUTTER_ENABLE_PYTHON=true
equals(CUTTER_ENABLE_PYTHON, true) CONFIG += CUTTER_ENABLE_PYTHON
!defined(CUTTER_ENABLE_QTWEBENGINE, var) CUTTER_ENABLE_QTWEBENGINE=false
equals(CUTTER_ENABLE_JUPYTER, true) {
equals(CUTTER_ENABLE_QTWEBENGINE, true) CONFIG += CUTTER_ENABLE_QTWEBENGINE
!defined(CUTTER_ENABLE_PYTHON_BINDINGS, var) CUTTER_ENABLE_PYTHON_BINDINGS=true
equals(CUTTER_ENABLE_PYTHON, true) {
equals(CUTTER_ENABLE_PYTHON_BINDINGS, true) {
CONFIG += CUTTER_ENABLE_PYTHON_BINDINGS
!defined(SHIBOKEN_EXECUTABLE, var) SHIBOKEN_EXECUTABLE=shiboken2
}
}
!defined(CUTTER_BUNDLE_R2_APPBUNDLE, var) CUTTER_BUNDLE_R2_APPBUNDLE=false
equals(CUTTER_BUNDLE_R2_APPBUNDLE, true) CONFIG += CUTTER_BUNDLE_R2_APPBUNDLE
!defined(CUTTER_ENABLE_JUPYTER, var) CUTTER_ENABLE_JUPYTER=true
equals(CUTTER_ENABLE_PYTHON, true) {
equals(CUTTER_ENABLE_JUPYTER, true) CONFIG += CUTTER_ENABLE_JUPYTER
}
!defined(CUTTER_APPVEYOR_R2DEC, var) CUTTER_APPVEYOR_R2DEC=false
equals(CUTTER_APPVEYOR_R2DEC, true) CONFIG += CUTTER_APPVEYOR_R2DEC
!defined(CUTTER_ENABLE_QTWEBENGINE, var) CUTTER_ENABLE_QTWEBENGINE=false
equals(CUTTER_ENABLE_JUPYTER, true) {
equals(CUTTER_ENABLE_QTWEBENGINE, true) CONFIG += CUTTER_ENABLE_QTWEBENGINE
}
!defined(CUTTER_BUNDLE_R2_APPBUNDLE, var) CUTTER_BUNDLE_R2_APPBUNDLE=false
equals(CUTTER_BUNDLE_R2_APPBUNDLE, true) CONFIG += CUTTER_BUNDLE_R2_APPBUNDLE
!defined(CUTTER_APPVEYOR_R2DEC, var) CUTTER_APPVEYOR_R2DEC=false
equals(CUTTER_APPVEYOR_R2DEC, true) CONFIG += CUTTER_APPVEYOR_R2DEC
!defined(CUTTER_APPVEYOR_R2DEC, var) CUTTER_APPVEYOR_R2DEC=false
CUTTER_ENABLE_PYTHON {
message("Python enabled.")
DEFINES += CUTTER_ENABLE_PYTHON
} else {
message("Python disabled.")
}
CUTTER_ENABLE_PYTHON_BINDINGS {
message("Python Bindings enabled.")
DEFINES += CUTTER_ENABLE_PYTHON_BINDINGS
} else {
message("Python Bindings disabled. (requires CUTTER_ENABLE_PYTHON=true)")
}
CUTTER_ENABLE_JUPYTER {
message("Jupyter support enabled.")
DEFINES += CUTTER_ENABLE_JUPYTER
} else {
message("Jupyter support disabled.")
message("Jupyter support disabled. (requires CUTTER_ENABLE_PYTHON=true)")
}
CUTTER_ENABLE_QTWEBENGINE {
@ -58,10 +87,10 @@ CUTTER_ENABLE_QTWEBENGINE {
DEFINES += CUTTER_ENABLE_QTWEBENGINE
QT += webenginewidgets
} else {
message("QtWebEngine support disabled.")
message("QtWebEngine support disabled. (requires CUTTER_ENABLE_JUPYTER=true)")
}
INCLUDEPATH *= .
INCLUDEPATH *= . widgets dialogs common plugins
win32 {
# Generate debug symbols in release mode
@ -88,30 +117,63 @@ unix {
# Libraries
include(lib_radare2.pri)
win32:CUTTER_ENABLE_JUPYTER {
pythonpath = $$quote($$system("where python"))
pythonpath = $$replace(pythonpath, ".exe ", ".exe;")
pythonpath = $$section(pythonpath, ";", 0, 0)
pythonpath = $$clean_path($$dirname(pythonpath))
LIBS += -L$${pythonpath} -L$${pythonpath}/libs -lpython3
INCLUDEPATH += $${pythonpath}/include
}
unix:CUTTER_ENABLE_JUPYTER|macx:CUTTER_ENABLE_JUPYTER|bsd:CUTTER_ENABLE_JUPYTER {
defined(PYTHON_FRAMEWORK_DIR, var) {
message("Using Python.framework at $$PYTHON_FRAMEWORK_DIR")
INCLUDEPATH += $$PYTHON_FRAMEWORK_DIR/Python.framework/Headers
LIBS += -F$$PYTHON_FRAMEWORK_DIR -framework Python
DEFINES += MACOS_PYTHON_FRAMEWORK_BUNDLED
} else {
CONFIG += link_pkgconfig
!packagesExist(python3) {
error("ERROR: Python 3 could not be found. Make sure it is available to pkg-config.")
CUTTER_ENABLE_PYTHON {
win32 {
PYTHON_EXECUTABLE = $$quote($$system("where python"))
pythonpath = $$replace(PYTHON_EXECUTABLE, ".exe ", ".exe;")
pythonpath = $$section(pythonpath, ";", 0, 0)
pythonpath = $$clean_path($$dirname(pythonpath))
LIBS += -L$${pythonpath} -L$${pythonpath}/libs -lpython3
INCLUDEPATH += $${pythonpath}/include
BINDINGS_SRC_LIST_CMD = "${PYTHON_EXECUTABLE} bindings/src_list.py"
}
unix|macx|bsd {
defined(PYTHON_FRAMEWORK_DIR, var) {
message("Using Python.framework at $$PYTHON_FRAMEWORK_DIR")
INCLUDEPATH += $$PYTHON_FRAMEWORK_DIR/Python.framework/Headers
LIBS += -F$$PYTHON_FRAMEWORK_DIR -framework Python
DEFINES += MACOS_PYTHON_FRAMEWORK_BUNDLED
} else {
CONFIG += link_pkgconfig
!packagesExist(python3) {
error("ERROR: Python 3 could not be found. Make sure it is available to pkg-config.")
}
PKGCONFIG += python3
}
PKGCONFIG += python3
BINDINGS_SRC_LIST_CMD = "bindings/src_list.py"
}
CUTTER_ENABLE_PYTHON_BINDINGS {
BINDINGS_SRC_DIR = "$${PWD}/bindings"
BINDINGS_BUILD_DIR = "$${OUT_PWD}/bindings"
BINDINGS_SOURCE = $$system("$${BINDINGS_SRC_LIST_CMD} qmake \"$${BINDINGS_BUILD_DIR}\"")
BINDINGS_INCLUDE_DIRS = "$$[QT_INSTALL_HEADERS]" \
"$$[QT_INSTALL_HEADERS]/QtCore" \
"$$[QT_INSTALL_HEADERS]/QtWidgets" \
"$$[QT_INSTALL_HEADERS]/QtGui" \
"$$R2_INCLUDEPATH"
for(path, INCLUDEPATH) {
BINDINGS_INCLUDE_DIRS += $$absolute_path("$$path")
}
BINDINGS_INCLUDE_DIRS = $$join(BINDINGS_INCLUDE_DIRS, ":")
message("Joined: $$BINDINGS_INCLUDE_DIRS")
PYSIDE_TYPESYSTEMS = $$system("pkg-config --variable=typesystemdir pyside2")
PYSIDE_INCLUDEDIR = $$system("pkg-config --variable=includedir pyside2")
QMAKE_SUBSTITUTES += bindings/bindings.txt.in
bindings.target = bindings_target
bindings.commands = shiboken2 --project-file="$${BINDINGS_BUILD_DIR}/bindings.txt"
QMAKE_EXTRA_TARGETS += bindings
GENERATED_SOURCES += $${BINDINGS_SOURCE}
INCLUDEPATH += "$${BINDINGS_BUILD_DIR}/CutterBindings"
PRE_TARGETDEPS += bindings_target
PKGCONFIG += shiboken2 pyside2
INCLUDEPATH += "$$PYSIDE_INCLUDEDIR/QtCore" "$$PYSIDE_INCLUDEDIR/QtWidgets" "$$PYSIDE_INCLUDEDIR/QtGui"
}
}
macx:CUTTER_BUNDLE_R2_APPBUNDLE {
message("Using r2 rom AppBundle")
DEFINES += MACOS_R2_BUNDLED
@ -443,7 +505,7 @@ unix {
# built-in no need for files atm
target.path = $$PREFIX/bin
INSTALLS += target share_appdata share_metadata share_applications share_pixmaps
INSTALLS += target share_appdata share_applications share_pixmaps
# Triggered for example by 'qmake APPIMAGE=1'
!isEmpty(APPIMAGE){

View File

@ -2,14 +2,14 @@
generator-set = shiboken
header-file = @CMAKE_CURRENT_SOURCE_DIR@/bindings/bindings.h
typesystem-file = @CMAKE_CURRENT_SOURCE_DIR@/bindings/bindings.xml
header-file = $${BINDINGS_SRC_DIR}/bindings.h
typesystem-file = $${BINDINGS_SRC_DIR}/bindings.xml
output-directory = @CMAKE_CURRENT_BINARY_DIR@/bindings
output-directory = $${BINDINGS_BUILD_DIR}
include-path = @BINDINGS_INCLUDE_DIRS@
include-path = $${BINDINGS_INCLUDE_DIRS}
typesystem-paths=@PYSIDE_TYPESYSTEMS@
typesystem-paths = $${PYSIDE_TYPESYSTEMS}
enable-parent-ctor-heuristic
enable-pyside-extensions

3
src/bindings/src_list.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/bin/env python3
import os
import xml.etree.ElementTree as et
@ -30,7 +31,7 @@ def cmd_cmake(args):
def cmd_qmake(args):
sys.stdout.write(" ".join(get_cpp_files_gen(args)))
sys.stdout.write("\n".join(get_cpp_files_gen(args)) + "\n")
cmds = {"cmake": cmd_cmake, "qmake": cmd_qmake}

View File

@ -1,3 +1,5 @@
#ifdef CUTTER_ENABLE_PYTHON
#include "PythonAPI.h"
#include "PythonManager.h"
@ -122,3 +124,5 @@ void PythonManager::saveThread()
pyThreadState = PyEval_SaveThread();
}
}
#endif

View File

@ -1,14 +1,15 @@
win32 {
DEFINES += _CRT_NONSTDC_NO_DEPRECATE
DEFINES += _CRT_SECURE_NO_WARNINGS
INCLUDEPATH += "$$PWD/../radare2/libr/include/msvc"
R2_INCLUDEPATH += "$$PWD/../radare2/libr/include/msvc"
!contains(QT_ARCH, x86_64) {
LIBS += -L"$$PWD/../r2_dist_x86/radare2/lib"
INCLUDEPATH += "$$PWD/../r2_dist_x86/include"
R2_INCLUDEPATH += "$$PWD/../r2_dist_x86/include"
} else {
LIBS += -L"$$PWD/../r2_dist_x64/radare2/lib"
INCLUDEPATH += "$$PWD/../r2_dist_x64/include"
R2_INCLUDEPATH += "$$PWD/../r2_dist_x64/include"
}
INCLUDEPATH += $$R2_INCLUDEPATH
LIBS += \
-lr_core \
@ -51,29 +52,31 @@ win32 {
PKG_CONFIG_PATH=$$PKG_CONFIG_PATH:$$PREFIX/lib/pkgconfig
} else {
LIBS += -L$$PREFIX/lib
INCLUDEPATH += $$PREFIX/include/libr
R2_INCLUDEPATH += $$PREFIX/include/libr
USE_PKGCONFIG = 0
}
}
macx {
LIBS += -L$$PREFIX/lib
INCLUDEPATH += $$PREFIX/include/libr
R2_INCLUDEPATH += $$PREFIX/include/libr
USE_PKGCONFIG = 0
}
bsd {
!exists($$PKG_CONFIG_PATH/r_core.pc) {
LIBS += -L$$PREFIX/lib
INCLUDEPATH += $$PREFIX/include/libr
R2_INCLUDEPATH += $$PREFIX/include/libr
USE_PKGCONFIG = 0
}
}
}
INCLUDEPATH += $$R2_INCLUDEPATH
DEFINES += _CRT_NONSTDC_NO_DEPRECATE
DEFINES += _CRT_SECURE_NO_WARNINGS
equals(USE_PKGCONFIG, 1) {
CONFIG += link_pkgconfig
PKGCONFIG += r_core
R2_INCLUDEPATH = "$$system("pkg-config --variable=includedir r_core")/libr"
} else {
LIBS += \
-lr_core \

View File

@ -2,10 +2,10 @@
#ifdef CUTTER_ENABLE_PYTHON
#include <Python.h>
#include <cutterbindings_python.h>
#include "PythonManager.h"
#endif
#include "PluginManager.h"
#include "PythonManager.h"
#include "CutterPlugin.h"
#include <QDir>
@ -51,11 +51,13 @@ void PluginManager::loadPlugins()
loadNativePlugins(nativePluginsDir);
}
#ifdef CUTTER_ENABLE_PYTHON
QDir pythonPluginsDir = pluginsDir;
pythonPluginsDir.mkdir("python");
if (pythonPluginsDir.cd("python")) {
loadPythonPlugins(pythonPluginsDir.absolutePath());
}
#endif
qInfo() << "Loaded" << plugins.length() << "plugin(s).";
}