Skip to content

Commit

Permalink
Shiboken generation in QMake
Browse files Browse the repository at this point in the history
  • Loading branch information
YakoYakoYokuYoku committed Jun 28, 2022
1 parent 2226f38 commit 3d5c6a9
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 180 deletions.
93 changes: 40 additions & 53 deletions Engine/Engine.pro
Expand Up @@ -210,7 +210,6 @@ SOURCES += \
../Global/PythonUtils.cpp \
../Global/StrUtils.cpp \
../libs/SequenceParsing/SequenceParsing.cpp \
$${ENGINE_WRAPPER_DIR}/natronengine_module_wrapper.cpp \

HEADERS += \
AbortableRenderInfo.h \
Expand Down Expand Up @@ -427,7 +426,9 @@ HEADERS += \
../libs/OpenFX/include/nuke/fnPublicOfxExtensions.h \
../libs/OpenFX/include/tuttle/ofxReadWrite.h \
../libs/OpenFX_extensions/ofxhParametricParam.h \
$${ENGINE_WRAPPER_DIR}/natronengine_python.h \

GENERATED_SOURCES += $${ENGINE_WRAPPER_DIR}/natronengine_module_wrapper.cpp
GENERATED_HEADERS += $${ENGINE_WRAPPER_DIR}/natronengine_python.h

ENGINE_GENERATED_SOURCES = \
animatedparam_wrapper \
Expand Down Expand Up @@ -480,67 +481,53 @@ ENGINE_GENERATED_SOURCES = \
userparamholder_wrapper \

for(name, ENGINE_GENERATED_SOURCES) {
SOURCES += $${ENGINE_WRAPPER_DIR}/$${name}.cpp
HEADERS += $${ENGINE_WRAPPER_DIR}/$${name}.h
GENERATED_SOURCES += $${ENGINE_WRAPPER_DIR}/$${name}.cpp
GENERATED_HEADERS += $${ENGINE_WRAPPER_DIR}/$${name}.h
}


OTHER_FILES += \
typesystem_engine.xml

# GENERATED_SOURCES = \
# NatronEngine/animatedparam_wrapper.cpp \
# NatronEngine/app_wrapper.cpp \
# NatronEngine/beziercurve_wrapper.cpp \
# NatronEngine/booleanparam_wrapper.cpp \
# NatronEngine/buttonparam_wrapper.cpp \
# NatronEngine/choiceparam_wrapper.cpp \
# NatronEngine/colorparam_wrapper.cpp \
# NatronEngine/colortuple_wrapper.cpp \
# NatronEngine/double2dparam_wrapper.cpp \
# NatronEngine/double2dtuple_wrapper.cpp \
# NatronEngine/double3dparam_wrapper.cpp \
# NatronEngine/double3dtuple_wrapper.cpp \
# NatronEngine/doubleparam_wrapper.cpp \
# NatronEngine/effect_wrapper.cpp \
# NatronEngine/fileparam_wrapper.cpp \
# NatronEngine/group_wrapper.cpp \
# NatronEngine/groupparam_wrapper.cpp \
# NatronEngine/int2dparam_wrapper.cpp \
# NatronEngine/int2dtuple_wrapper.cpp \
# NatronEngine/int3dparam_wrapper.cpp \
# NatronEngine/int3dtuple_wrapper.cpp \
# NatronEngine/intparam_wrapper.cpp \
# NatronEngine/itembase_wrapper.cpp \
# NatronEngine/layer_wrapper.cpp \
# NatronEngine/natron_wrapper.cpp \
# NatronEngine/natronengine_module_wrapper.cpp \
# NatronEngine/outputfileparam_wrapper.cpp \
# NatronEngine/pageparam_wrapper.cpp \
# NatronEngine/param_wrapper.cpp \
# NatronEngine/parametricparam_wrapper.cpp \
# NatronEngine/pathparam_wrapper.cpp \
# NatronEngine/roto_wrapper.cpp \
# NatronEngine/stringparam_wrapper.cpp \
# NatronEngine/stringparambase_wrapper.cpp
defineReplace(shibokenEngine) {
SOURCES += $$GENERATED_SOURCES
HEADERS += $$GENERATED_HEADERS
return("%_wrapper.cpp")
}

# defineReplace(shibokenWorkaround) {
# SOURCES += $$GENERATED_SOURCES
# return("%_wrapper.cpp")
# }
QT_INCLUDEPATH = $$PYTHON_INCLUDEPATH $$PYSIDE_INCLUDEDIR
for(dep, QT) {
QT_INCLUDEPATH += $$eval(QT.$${dep}.includes)
QT_INCLUDEPATH += $$absolute_path($$eval(QT.$${dep}.name), $$PYSIDE_INCLUDEDIR)
}

equals(QT_MAJOR_VERSION, 5) {
PYENGINE_HEADER = PySide2_Engine_Python.h
POST_SHIBOKEN = bash $$shell_path(../tools/utils/runPostShiboken2.sh)
} else:equals(QT_MAJOR_VERSION, 4) {
PYENGINE_HEADER = Pyside_Engine_Python.h
POST_SHIBOKEN = bash $$shell_path(../tools/utils/runPostShiboken.sh)
}

# isEmpty(SHIBOKEN) {
# SHIBOKEN = shiboken
# }
SRC_PATH = $$relative_path($$PWD, $$OUT_PWD)/
DEP_GROUP = $$PYENGINE_HEADER typesystem_engine.xml $$HEADERS
enginesbk.input = $$PYENGINE_HEADER typesystem_engine.xml
enginesbk.depends = $$eval($$list($$join(DEP_GROUP, " "$$SRC_PATH, $$SRC_PATH)))
enginesbk.target = enginesbk
enginesbk.commands = cd $$PWD && $$SHIBOKEN \
--enable-parent-ctor-heuristic --use-isnull-as-nb_nonzero \
--avoid-protected-hack --enable-pyside-extensions \
-I.:..:../Global:../libs/OpenFX/include $$join(QT_INCLUDEPATH, ":", "-I") \
-T$$TYPESYSTEMPATH --output-directory=$$OUT_PWD/Qt$$QT_MAJOR_VERSION \
$$PYENGINE_HEADER typesystem_engine.xml && \
$$POST_SHIBOKEN $$OUT_PWD/Qt$$QT_MAJOR_VERSION/NatronEngine natronengine
pyengine.depends = enginesbk
pyengine.target = $$shell_path($$ENGINE_WRAPPER_DIR/%_wrapper.cpp)
pyengine.output_function = shibokenEngine
pyengine.commands = bash -c 'true'

# SHIBOKEN_FILE = . # Need to give some bogus input
# SHIBOKEN.input = SHIBOKEN_FILE
# SHIBOKEN.output_function = shibokenWorkaround
# SHIBOKEN.commands = $$SHIBOKEN --include-paths=..:$$system(pkg-config --variable=includedir pyside) --typesystem-paths=$$system(pkg-config --variable=typesystemdir pyside) Pyside_Engine_Python.h typesystem_engine.xml
# SHIBOKEN.CONFIG = no_link # don't add the .cpp target file to OBJECTS
# SHIBOKEN.clean = dummy # don't remove the %_wrapper.cpp file by "make clean"
QMAKE_EXTRA_TARGETS += enginesbk pyengine

# QMAKE_EXTRA_COMPILERS += SHIBOKEN
macx {

OBJECTIVE_SOURCES += \
Expand Down
49 changes: 45 additions & 4 deletions Gui/Gui.pro
Expand Up @@ -227,7 +227,6 @@ SOURCES += \
ViewerTabPrivate.cpp \
ViewerToolButton.cpp \
ticks.cpp \
$${GUI_WRAPPER_DIR}/natrongui_module_wrapper.cpp \

HEADERS += \
AboutWindow.h \
Expand Down Expand Up @@ -384,7 +383,9 @@ HEADERS += \
../libs/OpenFX/include/nuke/fnPublicOfxExtensions.h \
../libs/OpenFX/include/tuttle/ofxReadWrite.h \
../libs/OpenFX_extensions/ofxhParametricParam.h \
$${GUI_WRAPPER_DIR}/natrongui_python.h \

GENERATED_SOURCES += $${GUI_WRAPPER_DIR}/natrongui_module_wrapper.cpp
GENERATED_HEADERS += $${GUI_WRAPPER_DIR}/natrongui_python.h

GUI_GENERATED_SOURCES = \
guiapp_wrapper \
Expand All @@ -395,8 +396,8 @@ GUI_GENERATED_SOURCES = \
pyviewer_wrapper

for(name, GUI_GENERATED_SOURCES) {
SOURCES += $${GUI_WRAPPER_DIR}/$${name}.cpp
HEADERS += $${GUI_WRAPPER_DIR}/$${name}.h
GENERATED_SOURCES += $${GUI_WRAPPER_DIR}/$${name}.cpp
GENERATED_HEADERS += $${GUI_WRAPPER_DIR}/$${name}.h
}

RESOURCES += \
Expand All @@ -420,6 +421,46 @@ OTHER_FILES += \
Resources/Images/searchSize.png \
Resources/Images/splashscreen.svg

defineReplace(shibokenGui) {
SOURCES += $$GENERATED_SOURCES
HEADERS += $$GENERATED_HEADERS
return("%_wrapper.cpp")
}

QT_INCLUDEPATH = $$PYTHON_INCLUDEPATH $$PYSIDE_INCLUDEDIR
for(dep, QT) {
QT_INCLUDEPATH += $$eval(QT.$${dep}.includes)
QT_INCLUDEPATH += $$absolute_path($$eval(QT.$${dep}.name), $$PYSIDE_INCLUDEDIR)
}

equals(QT_MAJOR_VERSION, 5) {
PYGUI_HEADER = PySide2_Gui_Python.h
POST_SHIBOKEN = bash $$shell_path($$PWD/../tools/utils/runPostShiboken2.sh)
} else:equals(QT_MAJOR_VERSION, 4) {
PYGUI_HEADER = Pyside_Gui_Python.h
POST_SHIBOKEN = bash $$shell_path($$PWD/../tools/utils/runPostShiboken.sh)
}


SRC_PATH = $$relative_path($$PWD, $$OUT_PWD)/
DEP_GROUP = $$PYGUI_HEADER typesystem_natronGui.xml $$HEADERS
guisbk.input = $$PYGUI_HEADER typesystem_natronGui.xml
guisbk.depends = $$eval($$list($$join(DEP_GROUP, " "$$SRC_PATH, $$SRC_PATH)))
guisbk.target = guisbk
guisbk.commands = cd $$PWD && $$SHIBOKEN \
--enable-parent-ctor-heuristic --use-isnull-as-nb_nonzero \
--avoid-protected-hack --enable-pyside-extensions \
-I.:..:../Global:../Engine:../libs/OpenFX/include $$join(QT_INCLUDEPATH, ":", "-I") \
-T../Engine:$$TYPESYSTEMPATH --output-directory=$$OUT_PWD/Qt$$QT_MAJOR_VERSION \
$$PYGUI_HEADER typesystem_natronGui.xml && \
$$POST_SHIBOKEN $$OUT_PWD/Qt$$QT_MAJOR_VERSION/NatronGui natrongui
pygui.depends = guisbk
pygui.target = $$shell_path($$GUI_WRAPPER_DIR/%_wrapper.cpp)
pygui.output_function = shibokenGui
pygui.commands = bash -c 'true'

QMAKE_EXTRA_TARGETS += guisbk pygui

macx {
HEADERS += TaskBarMac.h
OBJECTIVE_SOURCES += \
Expand Down
25 changes: 4 additions & 21 deletions INSTALL_LINUX.md
Expand Up @@ -482,25 +482,9 @@ shiboken {

# Generating Python bindings

This is not required as generated files are already in the repository. You would need to run it if you were to extend or modify the Python bindings via the
This is not required as file generation occurs during build with Qt5 and generated files are already in the repository for Qt4. You would need to run it if you were both under Qt4 and either extend or modify the Python bindings via the
typesystem.xml file. See the documentation of shiboken for an explanation of the command line arguments.

```sh
SDK_PREFIX=/usr # /opt/Natron-sdk if using the Natron SDK
PYSIDE_PREFIX=/usr # /opt/Natron-sdk if using the Natron SDK
PYV=3.10
QT=5
rm Engine/NatronEngine/* Gui/NatronGui/*

shiboken2 --enable-parent-ctor-heuristic --use-isnull-as-nb_nonzero --avoid-protected-hack --enable-pyside-extensions --include-paths=.:Engine:Global:$SDK_PREFIX/include:$PYSIDE_PREFIX/include/PySide2 --typesystem-paths=$PYSIDE_PREFIX/lib/python${PYV}/site-packages/PySide2/typesystems --output-directory=Engine/Qt${QT} Engine/Pyside2_Engine_Python.h Engine/typesystem_engine.xml

shiboken2 --enable-parent-ctor-heuristic --use-isnull-as-nb_nonzero --avoid-protected-hack --enable-pyside-extensions --include-paths=.:Engine:Gui:Global:$SDK_PREFIX/include:$PYSIDE_PREFIX/include/PySide2 --typesystem-paths=$PYSIDE_PREFIX/lib/python${PYV}/site-packages/PySide2/typesystems:Engine:Shiboken --output-directory=Gui/Qt${QT} Gui/Pyside2_Gui_Python.h Gui/typesystem_natronGui.xml

tools/utils/runPostShiboken2.sh
#tools/utils/runPostShiboken2.sh Engine/Qt${QT}/NatronEngine natronengine
#tools/utils/runPostShiboken2.sh Gui/Qt${QT}/NatronGui natrongui
```

If using PySide for Qt4, the command-line would be:

```sh
Expand All @@ -513,10 +497,9 @@ shiboken --avoid-protected-hack --enable-pyside-extensions --include-paths=../En

shiboken --avoid-protected-hack --enable-pyside-extensions --include-paths=../Engine:../Gui:../Global:$SDK_PREFIX/include:$PYSIDE_PREFIX/include/PySide --typesystem-paths=$PYSIDE_PREFIX/share/PySide/typesystems:Engine:Shiboken --output-directory=Gui/Qt${QT} Gui/Pyside_Gui_Python.h Gui/typesystem_natronGui.xml

tools/utils/runPostShiboken.sh
#tools/utils/runPostShiboken.sh Engine/Qt${QT}/NatronEngine natronengine
#tools/utils/runPostShiboken.sh Gui/Qt${QT}/NatronGui natrongui
tools/utils/runPostShiboken.sh Engine/Qt${QT}/NatronEngine natronengine
tools/utils/runPostShiboken.sh Gui/Qt${QT}/NatronGui natrongui
```

**Note**
Shiboken has a few glitches which needs fixing with some sed commands, run `tools/utils/runPostShiboken2.sh` for Qt5 or `tools/utils/runPostShiboken.sh` for Qt4 once shiboken is called.
Shiboken has a few glitches which needs fixing with some sed commands, run `tools/utils/runPostShiboken.sh` for Qt4 once shiboken is called.
42 changes: 3 additions & 39 deletions INSTALL_MACOS.md
Expand Up @@ -610,7 +610,7 @@ launchctl setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sb
## Generating Python bindings
This is not required as generated files are already in the repository. You would need to run it if you were to extend or modify the Python bindings via the
This is not required as file generation occurs during build with Qt5 and generated files are already in the repository for Qt4. You would need to run it if you were both under Qt4 and either extend or modify the Python bindings via the
typesystem.xml file. See the documentation of shiboken-2.7 for an explanation of the command line arguments.
On MacPorts with qt4-mac, py310-pyside, py310-shiboken:
Expand All @@ -623,44 +623,8 @@ shiboken-${PYV} --avoid-protected-hack --enable-pyside-extensions --include-path
shiboken-${PYV} --avoid-protected-hack --enable-pyside-extensions --include-paths=../Engine:../Gui:../Global:/opt/local/include:/opt/local/include/PySide-${PYV} --typesystem-paths=/opt/local/share/PySide-${PYV}/typesystems:Engine:Shiboken --output-directory=Gui/Qt${QT} Gui/Pyside_Gui_Python.h Gui/typesystem_natronGui.xml
tools/utils/runPostShiboken.sh
#tools/utils/runPostShiboken.sh Engine/Qt${QT}/NatronEngine natronengine
#tools/utils/runPostShiboken.sh Gui/Qt${QT}/NatronGui natrongui
```
On MacPorts with qt5, py310-pyside2:
```Shell
PYV=3.10 # Set to the python version
PYTHON_PREFIX=$(python${PYV}-config --prefix)
QT=5
# Fix a missing link in the MacPorts package
[ ! -f ${PYTHON_PREFIX}/lib/python${PYV}/site-packages/shiboken2_generator/shiboken2-${PYV} ] && sudo ln -s shiboken2 ${PYTHON_PREFIX}/lib/python${PYV}/site-packages/shiboken2_generator/shiboken2-${PYV}
rm Engine/Qt5/NatronEngine/* Gui/Qt5/NatronGui/*
# ${PYTHON_PREFIX}/lib/python${PYV}/site-packages/PySide2/include
shiboken2-${PYV} --avoid-protected-hack --enable-pyside-extensions --include-paths=.:Engine:Global:libs/OpenFX/include:/opt/local/include:/opt/local/libexec/qt${QT}/include:${PYTHON_PREFIX}/include/python${PYV}:${PYTHON_PREFIX}/lib/python${PYV}/site-packages/PySide2/include --typesystem-paths=${PYTHON_PREFIX}/lib/python${PYV}/site-packages/PySide2/typesystems --output-directory=Engine/Qt${QT} Engine/Pyside2_Engine_Python.h Engine/typesystem_engine.xml
shiboken2-${PYV} --avoid-protected-hack --enable-pyside-extensions --include-paths=.:Engine:Global:libs/OpenFX/include:/opt/local/include:/opt/local/libexec/qt${QT}/include:/opt/local/libexec/qt${QT}/include/QtWidgets:${PYTHON_PREFIX}/include/python${PYV}:${PYTHON_PREFIX}/lib/python${PYV}/site-packages/PySide2/include --typesystem-paths=${PYTHON_PREFIX}/lib/python${PYV}/site-packages/PySide2/typesystems:Engine:Shiboken --output-directory=Gui/Qt${QT} Gui/Pyside2_Gui_Python.h Gui/typesystem_natronGui.xml
tools/utils/runPostShiboken2.sh
#tools/utils/runPostShiboken2.sh Engine/Qt${QT}/NatronEngine natronengine
#tools/utils/runPostShiboken2.sh Gui/Qt${QT}/NatronGui natrongui
```
on HomeBrew with Qt5/PySide2/Shiboken2:
```Shell
PYV=3.10 # Set to the python version
export PATH="/usr/local/opt/pyside@2/bin:$PATH"
QT=5
rm Engine/Qt${QT}/NatronEngine/* Gui/Qt5/NatronGui/*
shiboken2 --enable-parent-ctor-heuristic --use-isnull-as-nb_nonzero --avoid-protected-hack --enable-pyside-extensions --include-paths=.:Global:Engine:libs/OpenFX/include:/usr/local/Frameworks/Python.framework/Versions/${PYV}/include/python${PYV}:/usr/local/include:/usr/local/opt/pyside@2/include/PySide2:/usr/local/opt/qt@${QT}/include --typesystem-paths=/usr/local/opt/pyside@2/share/PySide2/typesystems --output-directory=Engine/Qt${QT} Engine/PySide2_Engine_Python.h Engine/typesystem_engine.xml
shiboken2 --enable-parent-ctor-heuristic --use-isnull-as-nb_nonzero --avoid-protected-hack --enable-pyside-extensions --include-paths=.:Global:Engine:Gui:libs/OpenFX/include:/usr/local/Frameworks/Python.framework/Versions/${PYV}/include/python${PYV}:/usr/local/include:/usr/local/opt/pyside@2/include/PySide2:/usr/local/opt/qt@${QT}/include:/usr/local/opt/qt@5/include/QtWidgets --typesystem-paths=/usr/local/opt/pyside@2/share/PySide2/typesystems:Engine --output-directory=Gui/Qt${QT} Gui/PySide2_Gui_Python.h Gui/typesystem_natronGui.xml
tools/utils/runPostShiboken2.sh
#tools/utils/runPostShiboken2.sh Engine/Qt${QT}/NatronEngine natronengine
#tools/utils/runPostShiboken2.sh Gui/Qt${QT}/NatronGui natrongui
tools/utils/runPostShiboken.sh Engine/Qt${QT}/NatronEngine natronengine
tools/utils/runPostShiboken.sh Gui/Qt${QT}/NatronGui natrongui
```
**Note**
Expand Down
10 changes: 10 additions & 0 deletions global.pri
Expand Up @@ -33,6 +33,8 @@ DEFINES += OFX_SUPPORTS_DIALOG
#for QString(const char*) assumes ASCII strings, we may run into troubles
DEFINES += QT_NO_CAST_FROM_ASCII

greaterThan(QT_MAJOR_VERSION, 4): CONFIG += python3

# To run Natron without Python functionnalities (for debug purposes)
run-without-python {
message("Natron will run (not build) without Python")
Expand Down Expand Up @@ -402,17 +404,21 @@ win32-g++ {
cairo: PKGCONFIG += cairo fontconfig
equals(QT_MAJOR_VERSION, 5) {
shiboken: INCLUDEPATH += $$PYTHON_SITE_PACKAGES/PySide2/include/shiboken2
shiboken: SHIBOKEN = $$system(pkg-config --variable=generator_location shiboken2)
pyside: INCLUDEPATH += $$PYTHON_SITE_PACKAGES/PySide2/include/PySide2
pyside: INCLUDEPATH += $$PYTHON_SITE_PACKAGES/PySide2/include/PySide2/QtCore
pyside: INCLUDEPATH += $$PYTHON_SITE_PACKAGES/PySide2/include/PySide2/QtGui
pyside: INCLUDEPATH += $$PYTHON_SITE_PACKAGES/PySide2/include/PySide2/QtWidgets
pyside: TYPESYSTEMPATH *= $$system(pkg-config --variable=typesystemdir pyside2)
}
equals(QT_MAJOR_VERSION, 4) {
shiboken: PKGCONFIG += shiboken-py$$PYV
shiboken: SHIBOKEN = $$system(pkg-config --variable=generator_location shiboken)
pyside: PKGCONFIG += pyside-py$$PYV
PYSIDE_INCLUDEDIR = $$system(pkg-config --variable=includedir pyside-py$$PYV)
pyside: INCLUDEPATH += $$PYSIDE_INCLUDEDIR/QtCore
pyside: INCLUDEPATH += $$PYSIDE_INCLUDEDIR/QtGui
pyside: TYPESYSTEMPATH *= $$system(pkg-config --variable=typesystemdir pyside)
}
python: PKGCONFIG += python-$$PYVER$$PY_PKG_SUFFIX
boost: LIBS += -lboost_serialization-mt
Expand Down Expand Up @@ -454,12 +460,14 @@ unix {
equals(QT_MAJOR_VERSION, 5) {
system(pkg-config --exists pyside2) {
shiboken: PKGCONFIG += shiboken2
shiboken: SHIBOKEN = $$system(pkg-config --variable=generator_location shiboken2)
pyside: PKGCONFIG += pyside2
# add QtCore to includes
PYSIDE_INCLUDEDIR = $$system(pkg-config --variable=includedir pyside2)
pyside: INCLUDEPATH += $$PYSIDE_INCLUDEDIR/QtCore
pyside: INCLUDEPATH += $$PYSIDE_INCLUDEDIR/QtGui
pyside: INCLUDEPATH += $$PYSIDE_INCLUDEDIR/QtWidgets
pyside: TYPESYSTEMPATH *= $$system(pkg-config --variable=typesystemdir pyside2)
}
}

Expand All @@ -469,7 +477,9 @@ unix {
# See for example tools/travis/install_dependencies.sh for a solution that works on Linux,
# using a custom config.pri
shiboken: PKGCONFIG += shiboken
shiboken: SHIBOKEN = $$system(pkg-config --variable=generator_location shiboken)
pyside: PKGCONFIG += pyside
pyside: TYPESYSTEMPATH *= $$system(pkg-config --variable=typesystemdir pyside)
# The following hack also works with Homebrew if pyside is installed with option --with-python3
macx {
QMAKE_LFLAGS += '-Wl,-rpath,\'@loader_path/../Frameworks\''
Expand Down

0 comments on commit 3d5c6a9

Please sign in to comment.