From 2be8ec8456806045245e640ee47082e67bd0412b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Mon, 11 Feb 2019 21:26:11 +0100 Subject: [PATCH] Generate Bindings in QMake Fix typesystem-paths --- src/CMakeLists.txt | 16 ++--- src/Cutter.pro | 126 +++++++++++++++++++++++++--------- src/bindings/bindings.txt.in | 10 +-- src/bindings/src_list.py | 3 +- src/common/PythonManager.cpp | 4 ++ src/lib_radare2.pri | 17 +++-- src/plugins/PluginManager.cpp | 4 +- 7 files changed, 125 insertions(+), 55 deletions(-) mode change 100644 => 100755 src/bindings/src_list.py diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0fc95531..b9034bbf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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() diff --git a/src/Cutter.pro b/src/Cutter.pro index 4d9f47bf..fc373bdf 100644 --- a/src/Cutter.pro +++ b/src/Cutter.pro @@ -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){ diff --git a/src/bindings/bindings.txt.in b/src/bindings/bindings.txt.in index 465e2876..02c16814 100644 --- a/src/bindings/bindings.txt.in +++ b/src/bindings/bindings.txt.in @@ -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 diff --git a/src/bindings/src_list.py b/src/bindings/src_list.py old mode 100644 new mode 100755 index b37499b5..a660a838 --- a/src/bindings/src_list.py +++ b/src/bindings/src_list.py @@ -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} diff --git a/src/common/PythonManager.cpp b/src/common/PythonManager.cpp index 0f298abd..0bacef29 100644 --- a/src/common/PythonManager.cpp +++ b/src/common/PythonManager.cpp @@ -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 \ No newline at end of file diff --git a/src/lib_radare2.pri b/src/lib_radare2.pri index 10d6e946..a9e2ee9b 100644 --- a/src/lib_radare2.pri +++ b/src/lib_radare2.pri @@ -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 \ @@ -99,4 +102,4 @@ win32 { -lr_util \ -lr_crypto } -} +} \ No newline at end of file diff --git a/src/plugins/PluginManager.cpp b/src/plugins/PluginManager.cpp index d8b54a7d..5b612d3f 100644 --- a/src/plugins/PluginManager.cpp +++ b/src/plugins/PluginManager.cpp @@ -2,10 +2,10 @@ #ifdef CUTTER_ENABLE_PYTHON #include #include +#include "PythonManager.h" #endif #include "PluginManager.h" -#include "PythonManager.h" #include "CutterPlugin.h" #include @@ -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)."; }