diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b9034bbf..3a4de756 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -103,6 +103,8 @@ or, if you don't want to build with Python at all, use -DCUTTER_ENABLE_PYTHON=OF include_directories(${SHIBOKEN_INCLUDE_DIR}) include_directories(${PYSIDE_INCLUDE_DIR} ${PYSIDE_INCLUDE_DIR}/QtCore ${PYSIDE_INCLUDE_DIR}/QtGui ${PYSIDE_INCLUDE_DIR}/QtWidgets) + + add_definitions(-DCUTTER_ENABLE_PYTHON) endif() endif() diff --git a/src/common/PythonManager.cpp b/src/common/PythonManager.cpp index 0bacef29..0e3ca38c 100644 --- a/src/common/PythonManager.cpp +++ b/src/common/PythonManager.cpp @@ -54,7 +54,9 @@ void PythonManager::initPythonHome() } } +#ifdef CUTTER_ENABLE_PYTHON_BINDINGS extern "C" PyObject *PyInit_CutterBindings(); +#endif void PythonManager::initialize() { @@ -65,7 +67,9 @@ void PythonManager::initialize() PyImport_AppendInittab("cutter_internal", &PyInit_api_internal); #endif PyImport_AppendInittab("_qtres", &PyInit_qtres); +#ifdef CUTTER_ENABLE_PYTHON_BINDINGS PyImport_AppendInittab("CutterBindings", &PyInit_CutterBindings); +#endif Py_Initialize(); PyEval_InitThreads(); pyThreadStateCounter = 1; // we have the thread now => 1 diff --git a/src/meson.build b/src/meson.build index a91325fd..824b5209 100644 --- a/src/meson.build +++ b/src/meson.build @@ -5,18 +5,22 @@ py3_exe = import('python').find_installation('python3') qt_modules = [] feature_define_args = [] -if get_option('enable_jupyter') - message('Jupyter support enabled') - add_project_arguments('-DCUTTER_ENABLE_JUPYTER', language: 'cpp') - feature_define_args += ['-DCUTTER_ENABLE_JUPYTER'] - if get_option('enable_webengine') - message('QtWebEngine support enabled') - add_project_arguments('-DCUTTER_ENABLE_QTWEBENGINE', language: 'cpp') - feature_define_args += ['-DCUTTER_ENABLE_QTWEBENGINE'] - qt_modules += 'WebEngineWidgets' +if get_option('enable_python') + message('Python is enabled') + feature_define_args += ['-DCUTTER_ENABLE_PYTHON'] + if get_option('enable_jupyter') + message('Jupyter support enabled') + feature_define_args += ['-DCUTTER_ENABLE_JUPYTER'] + if get_option('enable_webengine') + message('QtWebEngine support enabled') + feature_define_args += ['-DCUTTER_ENABLE_QTWEBENGINE'] + qt_modules += 'WebEngineWidgets' + endif endif endif +add_project_arguments(feature_define_args, language: 'cpp') + parse_cmd = [py3_exe, join_paths(meson.current_source_dir(), '../scripts/meson_parse_qmake.py')] qt_modules += run_command(parse_cmd + ['QT'], check: true).stdout().split(';') @@ -59,7 +63,7 @@ libr2_dep = r2.get_variable('libr2_dep') qt5dep = dependency('qt5', modules: qt_modules) deps = [libr2_dep, qt5dep] -if get_option('enable_jupyter') +if get_option('enable_python') deps += [dependency('python3')] endif diff --git a/src/meson_options.txt b/src/meson_options.txt index 6bf9abbc..2287ed0f 100644 --- a/src/meson_options.txt +++ b/src/meson_options.txt @@ -1,2 +1,3 @@ +option('enable_python', type: 'boolean', value: true) option('enable_jupyter', type: 'boolean', value: false) option('enable_webengine', type: 'boolean', value: false) diff --git a/src/plugins/PluginManager.cpp b/src/plugins/PluginManager.cpp index 5b612d3f..d366793b 100644 --- a/src/plugins/PluginManager.cpp +++ b/src/plugins/PluginManager.cpp @@ -1,5 +1,5 @@ -#ifdef CUTTER_ENABLE_PYTHON +#ifdef CUTTER_ENABLE_PYTHON_BINDINGS #include #include #include "PythonManager.h" @@ -51,7 +51,7 @@ void PluginManager::loadPlugins() loadNativePlugins(nativePluginsDir); } -#ifdef CUTTER_ENABLE_PYTHON +#ifdef CUTTER_ENABLE_PYTHON_BINDINGS QDir pythonPluginsDir = pluginsDir; pythonPluginsDir.mkdir("python"); if (pythonPluginsDir.cd("python")) { @@ -87,7 +87,7 @@ void PluginManager::loadNativePlugins(const QDir &directory) } } -#ifdef CUTTER_ENABLE_PYTHON +#ifdef CUTTER_ENABLE_PYTHON_BINDINGS void PluginManager::loadPythonPlugins(const QDir &directory) { diff --git a/src/plugins/PluginManager.h b/src/plugins/PluginManager.h index e02a529b..dcab409c 100644 --- a/src/plugins/PluginManager.h +++ b/src/plugins/PluginManager.h @@ -34,7 +34,7 @@ private: void loadNativePlugins(const QDir &directory); -#ifdef CUTTER_ENABLE_PYTHON +#ifdef CUTTER_ENABLE_PYTHON_BINDINGS void loadPythonPlugins(const QDir &directory); CutterPlugin *loadPythonPlugin(const char *moduleName); #endif