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) if(CUTTER_ENABLE_PYTHON_BINDINGS)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bindings/bindings.xml" set(BINDINGS_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/bindings")
"${CMAKE_CURRENT_BINARY_DIR}/bindings/bindings.xml" set(BINDINGS_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/bindings")
COPYONLY) # trigger reconfigure if file changes
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/bindings/src_list.py" cmake "${CMAKE_CURRENT_BINARY_DIR}/bindings" configure_file("${BINDINGS_SRC_DIR}/bindings.xml" "${BINDINGS_BUILD_DIR}/bindings.xml" COPYONLY) # trigger reconfigure if file changes
OUTPUT_VARIABLE BINDINGS_SOURCE)
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) 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}/widgets")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/common") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/common")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/plugins") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/plugins")
add_custom_command(OUTPUT ${BINDINGS_SOURCE} 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" DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/bindings/bindings.xml"
IMPLICIT_DEPENDS CXX "${CMAKE_CURRENT_SOURCE_DIR}/bindings/bindings.h" IMPLICIT_DEPENDS CXX "${CMAKE_CURRENT_SOURCE_DIR}/bindings/bindings.h"
COMMENT "Generating Python bindings with shiboken2") 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}") 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}") string(REPLACE ";" ":" BINDINGS_INCLUDE_DIRS "${BINDINGS_INCLUDE_DIRS}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/bindings/bindings.txt.in" qmake_configure_file("${BINDINGS_SRC_DIR}/bindings.txt.in" "${BINDINGS_BUILD_DIR}/bindings.txt")
"${CMAKE_CURRENT_BINARY_DIR}/bindings/bindings.txt" @ONLY)
endif() endif()
endif() endif()

View File

@ -32,25 +32,54 @@ QT += core gui widgets svg network
QT_CONFIG -= no-pkg-config QT_CONFIG -= no-pkg-config
CONFIG += c++11 CONFIG += c++11
!defined(CUTTER_ENABLE_JUPYTER, var) CUTTER_ENABLE_JUPYTER=true !defined(CUTTER_ENABLE_PYTHON, var) CUTTER_ENABLE_PYTHON=true
equals(CUTTER_ENABLE_JUPYTER, true) CONFIG += CUTTER_ENABLE_JUPYTER equals(CUTTER_ENABLE_PYTHON, true) CONFIG += CUTTER_ENABLE_PYTHON
!defined(CUTTER_ENABLE_QTWEBENGINE, var) CUTTER_ENABLE_QTWEBENGINE=false !defined(CUTTER_ENABLE_PYTHON_BINDINGS, var) CUTTER_ENABLE_PYTHON_BINDINGS=true
equals(CUTTER_ENABLE_JUPYTER, true) { equals(CUTTER_ENABLE_PYTHON, true) {
equals(CUTTER_ENABLE_QTWEBENGINE, true) CONFIG += CUTTER_ENABLE_QTWEBENGINE 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 !defined(CUTTER_ENABLE_JUPYTER, var) CUTTER_ENABLE_JUPYTER=true
equals(CUTTER_BUNDLE_R2_APPBUNDLE, true) CONFIG += CUTTER_BUNDLE_R2_APPBUNDLE equals(CUTTER_ENABLE_PYTHON, true) {
equals(CUTTER_ENABLE_JUPYTER, true) CONFIG += CUTTER_ENABLE_JUPYTER
}
!defined(CUTTER_APPVEYOR_R2DEC, var) CUTTER_APPVEYOR_R2DEC=false !defined(CUTTER_ENABLE_QTWEBENGINE, var) CUTTER_ENABLE_QTWEBENGINE=false
equals(CUTTER_APPVEYOR_R2DEC, true) CONFIG += CUTTER_APPVEYOR_R2DEC 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 { CUTTER_ENABLE_JUPYTER {
message("Jupyter support enabled.") message("Jupyter support enabled.")
DEFINES += CUTTER_ENABLE_JUPYTER DEFINES += CUTTER_ENABLE_JUPYTER
} else { } else {
message("Jupyter support disabled.") message("Jupyter support disabled. (requires CUTTER_ENABLE_PYTHON=true)")
} }
CUTTER_ENABLE_QTWEBENGINE { CUTTER_ENABLE_QTWEBENGINE {
@ -58,10 +87,10 @@ CUTTER_ENABLE_QTWEBENGINE {
DEFINES += CUTTER_ENABLE_QTWEBENGINE DEFINES += CUTTER_ENABLE_QTWEBENGINE
QT += webenginewidgets QT += webenginewidgets
} else { } else {
message("QtWebEngine support disabled.") message("QtWebEngine support disabled. (requires CUTTER_ENABLE_JUPYTER=true)")
} }
INCLUDEPATH *= . INCLUDEPATH *= . widgets dialogs common plugins
win32 { win32 {
# Generate debug symbols in release mode # Generate debug symbols in release mode
@ -88,30 +117,63 @@ unix {
# Libraries # Libraries
include(lib_radare2.pri) 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 { CUTTER_ENABLE_PYTHON {
defined(PYTHON_FRAMEWORK_DIR, var) { win32 {
message("Using Python.framework at $$PYTHON_FRAMEWORK_DIR") PYTHON_EXECUTABLE = $$quote($$system("where python"))
INCLUDEPATH += $$PYTHON_FRAMEWORK_DIR/Python.framework/Headers pythonpath = $$replace(PYTHON_EXECUTABLE, ".exe ", ".exe;")
LIBS += -F$$PYTHON_FRAMEWORK_DIR -framework Python pythonpath = $$section(pythonpath, ";", 0, 0)
DEFINES += MACOS_PYTHON_FRAMEWORK_BUNDLED pythonpath = $$clean_path($$dirname(pythonpath))
} else { LIBS += -L$${pythonpath} -L$${pythonpath}/libs -lpython3
CONFIG += link_pkgconfig INCLUDEPATH += $${pythonpath}/include
!packagesExist(python3) { BINDINGS_SRC_LIST_CMD = "${PYTHON_EXECUTABLE} bindings/src_list.py"
error("ERROR: Python 3 could not be found. Make sure it is available to pkg-config.") }
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 { macx:CUTTER_BUNDLE_R2_APPBUNDLE {
message("Using r2 rom AppBundle") message("Using r2 rom AppBundle")
DEFINES += MACOS_R2_BUNDLED DEFINES += MACOS_R2_BUNDLED
@ -443,7 +505,7 @@ unix {
# built-in no need for files atm # built-in no need for files atm
target.path = $$PREFIX/bin 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' # Triggered for example by 'qmake APPIMAGE=1'
!isEmpty(APPIMAGE){ !isEmpty(APPIMAGE){

View File

@ -2,14 +2,14 @@
generator-set = shiboken generator-set = shiboken
header-file = @CMAKE_CURRENT_SOURCE_DIR@/bindings/bindings.h header-file = $${BINDINGS_SRC_DIR}/bindings.h
typesystem-file = @CMAKE_CURRENT_SOURCE_DIR@/bindings/bindings.xml 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-parent-ctor-heuristic
enable-pyside-extensions 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 os
import xml.etree.ElementTree as et import xml.etree.ElementTree as et
@ -30,7 +31,7 @@ def cmd_cmake(args):
def cmd_qmake(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} cmds = {"cmake": cmd_cmake, "qmake": cmd_qmake}

View File

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

View File

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

View File

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