Skip to content

Add Qt5 support #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 85 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@ add_definitions(-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK)

option(PythonQt_Wrap_QtAll "Make all Qt components available in python" OFF)

set(qtlibs core gui network opengl sql svg uitools webkit xml xmlpatterns)
set(qtlibs Core Gui Widgets Network OpenGL PrintSupport Sql Svg UiTools WebKit WebKitWidgets Xml XmlPatterns)
if (PythonQt_QT_VERSION VERSION_LESS "5")
set(qtlibs_lower)
foreach(qtlib ${qtlibs})
string(TOLOWER ${qtlib} qtlib_lower)
list(APPEND qtlibs_lower ${qtlib_lower})
set(qtlibs ${qtlibs_lower})
endif()

foreach(qtlib ${qtlibs})
OPTION(PythonQt_Wrap_Qt${qtlib} "Make all of Qt${qtlib} available in python" OFF)
endforeach()

# TODO: xmlpatterns wrapper does *NOT* build at all :(
list(REMOVE_ITEM qtlibs XmlPatterns)
list(REMOVE_ITEM qtlibs xmlpatterns)

# Force option if it applies
if(PythonQt_Wrap_QtAll)
list(REMOVE_ITEM qtlibs xmlpatterns) # xmlpatterns wrapper does *NOT* build at all :(
foreach(qtlib ${qtlibs})
if(NOT ${PythonQt_Wrap_Qt${qtlib}})
set(PythonQt_Wrap_Qt${qtlib} ON CACHE BOOL "Make all of Qt${qtlib} available in python" FORCE)
Expand All @@ -46,34 +57,58 @@ endif()

set(minimum_required_qt_version "4.6.2")

find_package(Qt4)
if (PythonQt_QT_VERSION VERSION_GREATER "4")
set(QT_LIBRARIES)
foreach(qtlib ${qtlibs})
if (${PythonQt_Wrap_Qt${qtlib}})
find_package(Qt5${qtlib})
include_directories(${Qt5${qtlib}_INCLUDE_DIRS})
add_definitions(${Qt5${qtlib}_DEFINITIONS})
list(APPEND QT_LIBRARIES ${Qt5${qtlib}_LIBRARIES})
endif()
endforeach()
else()
find_package(Qt4)

if(QT4_FOUND)
if(QT4_FOUND)

set(found_qt_version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})
set(found_qt_version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})

if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version})
if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version})
message(FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version}.")
endif()

# Enable required qt module
foreach(qtlib network opengl sql svg uitools webkit xml xmlpatterns)
string(TOUPPER ${qtlib} qtlib_uppercase)
if (NOT ${QT_QT${qtlib_uppercase}_FOUND})
message(FATAL_ERROR "QT_QT${${qtlib_uppercase} *not* FOUND - Try to disable PythonQt_Wrap_Qt${qtlib}")
endif()
set(QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}})
endforeach()

include(${QT_USE_FILE})
else()
message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")

# Enable required qt module
set(qt4libs ${qtlibs})
list(REMOVE_ITEM qt4libs core gui widgets)
foreach(qtlib ${qt4libs})
string(TOUPPER ${qtlib} qtlib_uppercase)
if (NOT ${QT_QT${qtlib_uppercase}_FOUND})
message(FATAL_ERROR "QT_QT${${qtlib_uppercase} *not* FOUND - Try to disable PythonQt_Wrap_Qt${qtlib}")
endif()
set(QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}})
endforeach()

include(${QT_USE_FILE})
else()
message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
endif()

endif()

#-----------------------------------------------------------------------------
# The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers
# associated with the Qt version being used.
set(generated_cpp_suffix "_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}")
set(generated_cpp_suffix "")
if (PythonQt_QT_VERSION VERSION_GREATER "4")
set(generated_cpp_suffix "_${Qt5Core_VERSION_MAJOR}${Qt5Core_VERSION_MINOR}")
else()
set(generated_cpp_suffix "_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}")
endif()

if("${generated_cpp_suffix}" STREQUAL "_51")
set(generated_cpp_suffix "_50")
endif()
if("${generated_cpp_suffix}" STREQUAL "_48")
set(generated_cpp_suffix "")
endif()
Expand Down Expand Up @@ -155,29 +190,35 @@ set(moc_sources

#-----------------------------------------------------------------------------
# Add extra sources
foreach(qtlib core gui network opengl sql svg uitools webkit xml xmlpatterns)

foreach(qtlib ${qtlibs})
if (${PythonQt_Wrap_Qt${qtlib}})

ADD_DEFINITIONS(-DPYTHONQT_WRAP_Qt${qtlib})
string(TOLOWER ${qtlib} qtlib_lower)
# TODO: gui is currently including widgets and printsupport files
# TODO: WebKit is currently including WebKitWidgets files
if ((NOT "${qtlib_lower}" STREQUAL "widgets")
AND (NOT "${qtlib_lower}" STREQUAL "printsupport")
AND (NOT "${qtlib_lower}" STREQUAL "webkitwidgets")
)
set(file_prefix generated_cpp${generated_cpp_suffix}/com_trolltech_qt_${qtlib_lower}/com_trolltech_qt_${qtlib_lower})

set(file_prefix generated_cpp${generated_cpp_suffix}/com_trolltech_qt_${qtlib}/com_trolltech_qt_${qtlib})

foreach(index RANGE 0 11)
foreach(index RANGE 0 11)

# Source files
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file_prefix}${index}.cpp)
list(APPEND sources ${file_prefix}${index}.cpp)
endif()
# Source files
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file_prefix}${index}.cpp)
list(APPEND sources ${file_prefix}${index}.cpp)
endif()

# Headers that should run through moc
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file_prefix}${index}.h)
list(APPEND moc_sources ${file_prefix}${index}.h)
endif()
# Headers that should run through moc
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file_prefix}${index}.h)
list(APPEND moc_sources ${file_prefix}${index}.h)
endif()

endforeach()
endforeach()

list(APPEND sources ${file_prefix}_init.cpp)
list(APPEND sources ${file_prefix}_init.cpp)
endif()

endif()
endforeach()
Expand All @@ -192,9 +233,15 @@ set(qrc_sources )

#-----------------------------------------------------------------------------
# Do wrapping
qt4_wrap_cpp(gen_moc_sources ${moc_sources})
qt4_wrap_ui(gen_ui_sources ${ui_sources})
qt4_add_resources(gen_qrc_sources ${qrc_sources})
if (PythonQt_QT_VERSION VERSION_GREATER "4")
qt5_wrap_cpp(gen_moc_sources ${moc_sources})
qt5_wrap_ui(gen_ui_sources ${ui_sources})
qt5_add_resources(gen_qrc_sources ${qrc_sources})
else()
qt4_wrap_cpp(gen_moc_sources ${moc_sources})
qt4_wrap_ui(gen_ui_sources ${ui_sources})
qt4_add_resources(gen_qrc_sources ${qrc_sources})
endif()

#-----------------------------------------------------------------------------
# Build the library
Expand Down
63 changes: 63 additions & 0 deletions generated_cpp_50/PythonQt_QtBindings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

#include "PythonQt_QtBindings.h"

#include "PythonQt.h"

void PythonQt_init_QtGui(PyObject*);
void PythonQt_init_QtSvg(PyObject*);
void PythonQt_init_QtSql(PyObject*);
void PythonQt_init_QtNetwork(PyObject*);
void PythonQt_init_QtCore(PyObject*);
void PythonQt_init_QtWebKit(PyObject*);
void PythonQt_init_QtOpenGL(PyObject*);
void PythonQt_init_QtXml(PyObject*);
void PythonQt_init_QtXmlPatterns(PyObject*);
void PythonQt_init_QtUiTools(PyObject*);
void PythonQt_init_QtPhonon(PyObject*);

PYTHONQT_EXPORT void PythonQt_init_QtBindings()
{
#ifdef PYTHONQT_WRAP_QtCore
PythonQt_init_QtCore(0);
#endif

#ifdef PYTHONQT_WRAP_QtGui
PythonQt_init_QtGui(0);
#endif

#ifdef PYTHONQT_WRAP_QtNetwork
PythonQt_init_QtNetwork(0);
#endif

#ifdef PYTHONQT_WRAP_QtOpenGL
PythonQt_init_QtOpenGL(0);
#endif

#ifdef PYTHONQT_WRAP_QtSql
PythonQt_init_QtSql(0);
#endif

#ifdef PYTHONQT_WRAP_QtSvg
PythonQt_init_QtSvg(0);
#endif

#ifdef PYTHONQT_WRAP_QtUiTools
PythonQt_init_QtUiTools(0);
#endif

#ifdef PYTHONQT_WRAP_QtWebKit
PythonQt_init_QtWebKit(0);
#endif

#ifdef PYTHONQT_WRAP_QtXml
PythonQt_init_QtXml(0);
#endif

#ifdef PYTHONQT_WRAP_QtXmlPatterns
PythonQt_init_QtXmlPatterns(0);
#endif

#ifdef PYTHONQT_WRAP_QtPhonon
PythonQt_init_QtPhonon(0);
#endif
};
10 changes: 10 additions & 0 deletions generated_cpp_50/PythonQt_QtBindings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _PYTHONQT_QTBINDINGS_H
#define _PYTHONQT_QTBINDINGS_H

#include "PythonQtSystem.h"

/// Initialize Qt bindings enabled at configuration time
PYTHONQT_EXPORT void PythonQt_init_QtBindings();

#endif

10 changes: 10 additions & 0 deletions generated_cpp_50/com_trolltech_qt_core/com_trolltech_qt_core.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
HEADERS += \
$$PWD/com_trolltech_qt_core0.h \
$$PWD/com_trolltech_qt_core1.h \
$$PWD/com_trolltech_qt_core2.h \

SOURCES += \
$$PWD/com_trolltech_qt_core0.cpp \
$$PWD/com_trolltech_qt_core1.cpp \
$$PWD/com_trolltech_qt_core2.cpp \
$$PWD/com_trolltech_qt_core_init.cpp
Loading