Skip to content

Commit 0401ec7

Browse files
jcfrcwillingkislinsk
committed
Remove support for Qt4 and fix Qt5 support
This commit fixes CMake support for Qt 5.3 to Qt 5.9 and allows to build using VS2015 and VS2017 Co-authored-by: Christoph Willing <[email protected]> Co-authored-by: Stefan Dinkelacker <[email protected]>
1 parent 83935b3 commit 0401ec7

File tree

4 files changed

+166
-112
lines changed

4 files changed

+166
-112
lines changed

CMakeLists.txt

Lines changed: 83 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,49 @@
55
# If you are not a CMake expert, you should better use the provided qmake profiles.
66
#-----------------------------------------------------------------------------
77

8-
cmake_minimum_required(VERSION 2.8)
8+
cmake_minimum_required(VERSION 3.5)
99

10-
#-----------------------------------------------------------------------------
1110
project(PythonQt)
12-
#-----------------------------------------------------------------------------
1311

1412
#----------------------------------------------------------------------------
1513
# Qt version
1614

17-
# Sanity checks
18-
if(DEFINED Qt5_DIR AND DEFINED QT_QMAKE_EXECUTABLE)
19-
message(FATAL_ERROR
20-
"${PROJECT_NAME} shoult NOT be configured setting both Qt5_DIR and QT_QMAKE_EXECUTABLE options.
21-
To build with Qt4, specify QT_QMAKE_EXECUTABLE. To build with Qt5, specify Qt5_DIR.")
22-
endif()
23-
2415
# Set PythonQt_QT_VERSION
25-
if(DEFINED Qt5_DIR)
26-
message(STATUS "${PROJECT_NAME}: Setting PythonQt_QT_VERSION to 5 because Qt5_DIR is defined.")
27-
set(PythonQt_QT_VERSION 5)
28-
elseif(DEFINED QT_QMAKE_EXECUTABLE)
29-
message(STATUS "${PROJECT_NAME}: Setting PythonQt_QT_VERSION to 4 because QT_QMAKE_EXECUTABLE is defined.")
30-
set(PythonQt_QT_VERSION 4)
31-
else()
32-
set(PythonQt_QT_VERSION 4 CACHE STRING "Pick a version of Qt to use: 4 or 5")
33-
# Set the possible values of Qt version for cmake-gui
34-
set_property(CACHE PythonQt_QT_VERSION PROPERTY STRINGS "4" "5")
35-
endif()
16+
set(PythonQt_QT_VERSION 5)
3617

3718
# Requirements
3819
set(minimum_required_qt5_version "5.3.0")
39-
set(minimum_required_qt4_version "4.6.2")
4020
set(minimum_required_qt_version ${minimum_required_qt${PythonQt_QT_VERSION}_version})
4121

22+
find_package(Qt5 ${minimum_required_qt_version} QUIET)
23+
set(QT_VERSION_MAJOR ${Qt5_VERSION_MAJOR})
24+
set(QT_VERSION_MINOR ${Qt5_VERSION_MINOR})
25+
26+
#----------------------------------------------------------------------------
4227
# Qt components
43-
set(qt5libs Core Widgets Network OpenGL Sql Svg UiTools WebKitWidgets Xml XmlPatterns)
44-
set(qt4libs core gui network opengl sql svg uitools webkit xml xmlpatterns)
45-
set(qtlibs ${qt${PythonQt_QT_VERSION}libs})
28+
set(qtlibs
29+
Core
30+
Widgets
31+
Network
32+
OpenGL
33+
Sql
34+
Svg
35+
UiTools
36+
Xml
37+
XmlPatterns
38+
)
39+
# Webkit has been removed in Qt >= 5.6
40+
if("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_LESS "5.7")
41+
list(APPEND qtlibs
42+
WebKitWidgets
43+
)
44+
endif()
45+
if("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_GREATER "5.5")
46+
list(APPEND qtlibs
47+
Qml
48+
Quick
49+
)
50+
endif()
4651

4752
#-----------------------------------------------------------------------------
4853
# Python libraries
@@ -73,25 +78,14 @@ if(NOT DEFINED PythonQt_INSTALL_INCLUDE_DIR)
7378
set(PythonQt_INSTALL_INCLUDE_DIR include/PythonQt)
7479
endif()
7580

76-
# Since the Qt bindings sources used for both Qt4 and Qt5 are
77-
# grouped using Qt4 naming convention, qt_wrapped_libs variables are the
78-
# same for the two Qt versions.
79-
set(qt4_wrapped_libs ${qt4libs})
80-
set(qt5_wrapped_libs ${qt4libs})
81-
set(qt_wrapped_libs ${qt${PythonQt_QT_VERSION}_wrapped_libs})
82-
8381
set(qt5_wrapped_lib_depends_gui Multimedia)
8482

83+
#-----------------------------------------------------------------------------
84+
# Set qtlib_to_wraplib_* variables
85+
8586
set(qtlib_to_wraplib_Widgets gui)
8687
set(qtlib_to_wraplib_WebKitWidgets webkit)
8788

88-
# Define PythonQt_Wrap_Qt* options
89-
option(PythonQt_Wrap_QtAll "Make all Qt components available in python" OFF)
90-
foreach(qtlib ${qt_wrapped_libs})
91-
OPTION(PythonQt_Wrap_Qt${qtlib} "Make all of Qt${qtlib} available in python" OFF)
92-
endforeach()
93-
94-
# Set qtlib_to_wraplib_* variables
9589
foreach(qtlib ${qtlibs})
9690
string(TOLOWER ${qtlib} qtlib_lowercase)
9791
if(DEFINED qtlib_to_wraplib_${qtlib})
@@ -100,17 +94,25 @@ foreach(qtlib ${qtlibs})
10094
set(qtlib_to_wraplib_${qtlib} ${qtlib_lowercase})
10195
endforeach()
10296

97+
#-----------------------------------------------------------------------------
98+
# Define PythonQt_Wrap_Qt* options
99+
option(PythonQt_Wrap_QtAll "Make all Qt components available in python" OFF)
100+
foreach(qtlib ${qtlibs})
101+
OPTION(PythonQt_Wrap_Qt${qtlib_to_wraplib_${qtlib}} "Make all of Qt${qtlib} available in python" OFF)
102+
endforeach()
103+
104+
#-----------------------------------------------------------------------------
103105
# Force option if it applies
104106
if(PythonQt_Wrap_QtAll)
105-
set(_qt_wrapped_libs ${qt_wrapped_libs})
106-
107-
# XXX xmlpatterns wrapper does *NOT* build at all :(
108-
list(REMOVE_ITEM _qt_wrapped_libs xmlpatterns)
109-
110-
foreach(qtlib ${_qt_wrapped_libs})
111-
if(NOT ${PythonQt_Wrap_Qt${qtlib}})
112-
set(PythonQt_Wrap_Qt${qtlib} ON CACHE BOOL "Make all of Qt${qtlib} available in python" FORCE)
113-
message(STATUS "Enabling [PythonQt_Wrap_Qt${qtlib}] because of [PythonQt_Wrap_QtAll] evaluates to True")
107+
foreach(qtlib ${qtlibs})
108+
# XXX xmlpatterns wrapper does *NOT* build at all :(
109+
if(${qtlib} STREQUAL "XmlPatterns")
110+
continue()
111+
endif()
112+
set(qt_wrapped_lib ${qtlib_to_wraplib_${qtlib}})
113+
if(NOT ${PythonQt_Wrap_Qt${qt_wrapped_lib}})
114+
set(PythonQt_Wrap_Qt${qt_wrapped_lib} ON CACHE BOOL "Make all of Qt${qt_wrapped_lib} available in python" FORCE)
115+
message(STATUS "Enabling [PythonQt_Wrap_Qt${qt_wrapped_lib}] because of [PythonQt_Wrap_QtAll] evaluates to True")
114116
endif()
115117
endforeach()
116118
endif()
@@ -125,91 +127,56 @@ endif()
125127
#-----------------------------------------------------------------------------
126128
# Setup Qt
127129

128-
if(PythonQt_QT_VERSION VERSION_GREATER "4")
129-
130-
# Required components
131-
set(qt_required_components Core Widgets)
132-
foreach(qtlib ${qtlibs})
133-
set(qt_wrapped_lib ${qtlib_to_wraplib_${qtlib}})
134-
if(${PythonQt_Wrap_Qt${qt_wrapped_lib}})
135-
list(APPEND qt_required_components ${qtlib} ${qt${PythonQt_QT_VERSION}_wrapped_lib_depends_${qt_wrapped_lib}})
136-
endif()
137-
endforeach()
138-
if(BUILD_TESTING)
139-
list(APPEND qt_required_components Test)
130+
# Required components
131+
set(qt_required_components Core Widgets)
132+
foreach(qtlib ${qtlibs})
133+
set(qt_wrapped_lib ${qtlib_to_wraplib_${qtlib}})
134+
if(${PythonQt_Wrap_Qt${qt_wrapped_lib}})
135+
list(APPEND qt_required_components ${qtlib} ${qt${PythonQt_QT_VERSION}_wrapped_lib_depends_${qt_wrapped_lib}})
140136
endif()
141-
list(REMOVE_DUPLICATES qt_required_components)
142-
143-
message(STATUS "${PROJECT_NAME}: Required Qt components [${qt_required_components}]")
144-
find_package(Qt5 ${minimum_required_qt_version} COMPONENTS ${qt_required_components} REQUIRED)
145-
146-
set(QT_LIBRARIES )
147-
foreach(qtlib ${qt_required_components})
148-
include_directories(${Qt5${qtlib}_INCLUDE_DIRS})
149-
add_definitions(${Qt5${qtlib}_DEFINITIONS})
150-
list(APPEND QT_LIBRARIES ${Qt5${qtlib}_LIBRARIES})
151-
endforeach()
152-
153-
set(QT_VERSION_MAJOR ${Qt5Core_VERSION_MAJOR})
154-
set(QT_VERSION_MINOR ${Qt5Core_VERSION_MINOR})
155-
156-
macro(pythonqt_wrap_cpp)
157-
qt5_wrap_cpp(${ARGV})
158-
endmacro()
159-
160-
else()
161-
162-
find_package(Qt4)
163-
164-
if(QT4_FOUND)
165-
166-
set(found_qt_version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})
167-
168-
if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version})
169-
message(FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version}.")
170-
endif()
171-
172-
# Enable required qt module
173-
foreach(qtlib ${qt_wrapped_libs})
174-
string(TOUPPER ${qtlib} qtlib_uppercase)
175-
if (NOT ${QT_QT${qtlib_uppercase}_FOUND})
176-
message(FATAL_ERROR "QT_QT${qtlib_uppercase} *not* FOUND - Try to disable PythonQt_Wrap_Qt${qtlib}")
177-
endif()
178-
set(QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}})
179-
endforeach()
137+
endforeach()
138+
if(BUILD_TESTING)
139+
list(APPEND qt_required_components Test)
140+
endif()
141+
list(REMOVE_DUPLICATES qt_required_components)
180142

181-
# Enable QtTest in Qt4 is the option BUILD_TESTING was activated
182-
set(QT_USE_QTTEST ${BUILD_TESTING})
143+
message(STATUS "${PROJECT_NAME}: Required Qt components [${qt_required_components}]")
144+
find_package(Qt5 ${minimum_required_qt_version} COMPONENTS ${qt_required_components} REQUIRED)
183145

184-
include(${QT_USE_FILE})
185-
else()
186-
message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
187-
endif()
146+
set(QT_LIBRARIES )
147+
foreach(qtlib ${qt_required_components})
148+
include_directories(${Qt5${qtlib}_INCLUDE_DIRS})
149+
add_definitions(${Qt5${qtlib}_DEFINITIONS})
150+
list(APPEND QT_LIBRARIES ${Qt5${qtlib}_LIBRARIES})
151+
endforeach()
188152

189-
macro(pythonqt_wrap_cpp)
190-
qt4_wrap_cpp(${ARGV})
191-
endmacro()
153+
# Required for use of "QtCore/private/qmetaobjectbuilder_p.h" in "PythonQt.cpp"
154+
include_directories(${Qt5Core_PRIVATE_INCLUDE_DIRS})
192155

193-
endif()
156+
macro(pythonqt_wrap_cpp)
157+
qt5_wrap_cpp(${ARGV})
158+
endmacro()
194159

195160
if(UNIX)
196161
find_package(OpenGL)
197162
if(OPENGL_FOUND)
198163
list(APPEND QT_LIBRARIES ${OPENGL_LIBRARIES})
199164
endif()
200165
endif()
166+
201167
#-----------------------------------------------------------------------------
202168
# The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers
203169
# associated with the Qt version being used.
204170

205-
set(generated_cpp_suffix_46 _47)
206171
set(generated_cpp_suffix_52 _50)
207172
set(generated_cpp_suffix_51 _50)
208173

209174
set(generated_cpp_suffix "_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}")
210175
if(DEFINED generated_cpp_suffix_${QT_VERSION_MAJOR}${QT_VERSION_MINOR})
211176
set(generated_cpp_suffix "${generated_cpp_suffix_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}}")
212-
elseif(${QT_VERSION_MAJOR}.${QT_VERSION_MINOR} VERSION_GREATER "5.4")
177+
elseif("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_GREATER "5.5")
178+
set(generated_cpp_suffix "_56")
179+
elseif("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_GREATER "5.3")
213180
set(generated_cpp_suffix "_54")
214181
endif()
215182

@@ -227,9 +194,11 @@ set(sources
227194
src/PythonQtMethodInfo.cpp
228195
src/PythonQtMisc.cpp
229196
src/PythonQtObjectPtr.cpp
197+
src/PythonQtProperty.cpp
230198
src/PythonQtQFileImporter.cpp
231199
src/PythonQtSignalReceiver.cpp
232200
src/PythonQtSlot.cpp
201+
src/PythonQtSlotDecorator.cpp
233202
src/PythonQtSignal.cpp
234203
src/PythonQtStdDecorators.cpp
235204
src/PythonQtStdIn.cpp
@@ -261,9 +230,11 @@ set(headers
261230
src/PythonQtMethodInfo.h
262231
src/PythonQtMisc.h
263232
src/PythonQtObjectPtr.h
233+
src/PythonQtProperty.h
264234
src/PythonQtQFileImporter.h
265235
src/PythonQtSignalReceiver.h
266236
src/PythonQtSlot.h
237+
src/PythonQtSlotDecorator.h
267238
src/PythonQtSignal.h
268239
src/PythonQtStdDecorators.h
269240
src/PythonQtStdIn.h
@@ -290,6 +261,7 @@ set(moc_sources
290261

291262
#-----------------------------------------------------------------------------
292263
# Add extra sources
264+
293265
foreach(qtlib ${qt_wrapped_libs})
294266

295267
if (${PythonQt_Wrap_Qt${qtlib}})
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
#include "PythonQt_QtBindings.h"
3+
4+
#include "PythonQt.h"
5+
6+
void PythonQt_init_QtGui(PyObject*);
7+
void PythonQt_init_QtSvg(PyObject*);
8+
void PythonQt_init_QtSql(PyObject*);
9+
void PythonQt_init_QtNetwork(PyObject*);
10+
void PythonQt_init_QtCore(PyObject*);
11+
void PythonQt_init_QtWebKit(PyObject*);
12+
void PythonQt_init_QtOpenGL(PyObject*);
13+
void PythonQt_init_QtQml(PyObject*);
14+
void PythonQt_init_QtQuick(PyObject*);
15+
void PythonQt_init_QtXml(PyObject*);
16+
void PythonQt_init_QtXmlPatterns(PyObject*);
17+
void PythonQt_init_QtUiTools(PyObject*);
18+
19+
PYTHONQT_EXPORT void PythonQt_init_QtBindings()
20+
{
21+
#ifdef PYTHONQT_WRAP_Qtcore
22+
PythonQt_init_QtCore(0);
23+
#endif
24+
25+
#ifdef PYTHONQT_WRAP_Qtgui
26+
PythonQt_init_QtGui(0);
27+
#endif
28+
29+
#ifdef PYTHONQT_WRAP_Qtnetwork
30+
PythonQt_init_QtNetwork(0);
31+
#endif
32+
33+
#ifdef PYTHONQT_WRAP_Qtopengl
34+
PythonQt_init_QtOpenGL(0);
35+
#endif
36+
37+
#ifdef PYTHONQT_WRAP_Qtqml
38+
PythonQt_init_QtQml(0);
39+
#endif
40+
41+
#ifdef PYTHONQT_WRAP_Qtquick
42+
PythonQt_init_QtQuick(0);
43+
#endif
44+
45+
#ifdef PYTHONQT_WRAP_Qtsql
46+
PythonQt_init_QtSql(0);
47+
#endif
48+
49+
#ifdef PYTHONQT_WRAP_Qtsvg
50+
PythonQt_init_QtSvg(0);
51+
#endif
52+
53+
#ifdef PYTHONQT_WRAP_Qtuitools
54+
PythonQt_init_QtUiTools(0);
55+
#endif
56+
57+
#ifdef PYTHONQT_WRAP_Qtwebkit
58+
PythonQt_init_QtWebKit(0);
59+
#endif
60+
61+
#ifdef PYTHONQT_WRAP_Qtxml
62+
PythonQt_init_QtXml(0);
63+
#endif
64+
65+
#ifdef PYTHONQT_WRAP_Qtxmlpatterns
66+
PythonQt_init_QtXmlPatterns(0);
67+
#endif
68+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef _PYTHONQT_QTBINDINGS_H
2+
#define _PYTHONQT_QTBINDINGS_H
3+
4+
#include "PythonQtSystem.h"
5+
6+
/// Initialize Qt bindings enabled at configuration time
7+
PYTHONQT_EXPORT void PythonQt_init_QtBindings();
8+
9+
#endif
10+

generated_cpp_56/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin0.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,11 @@ enum WindowModality{
12721272
enum WindowState{
12731273
WindowNoState = Qt::WindowNoState, WindowMinimized = Qt::WindowMinimized, WindowMaximized = Qt::WindowMaximized, WindowFullScreen = Qt::WindowFullScreen, WindowActive = Qt::WindowActive};
12741274
enum WindowType{
1275-
Widget = Qt::Widget, Window = Qt::Window, Dialog = Qt::Dialog, Sheet = Qt::Sheet, Drawer = Qt::Drawer, Popup = Qt::Popup, Tool = Qt::Tool, ToolTip = Qt::ToolTip, SplashScreen = Qt::SplashScreen, Desktop = Qt::Desktop, SubWindow = Qt::SubWindow, ForeignWindow = Qt::ForeignWindow, CoverWindow = Qt::CoverWindow, WindowType_Mask = Qt::WindowType_Mask, MSWindowsFixedSizeDialogHint = Qt::MSWindowsFixedSizeDialogHint, MSWindowsOwnDC = Qt::MSWindowsOwnDC, BypassWindowManagerHint = Qt::BypassWindowManagerHint, X11BypassWindowManagerHint = Qt::X11BypassWindowManagerHint, FramelessWindowHint = Qt::FramelessWindowHint, WindowTitleHint = Qt::WindowTitleHint, WindowSystemMenuHint = Qt::WindowSystemMenuHint, WindowMinimizeButtonHint = Qt::WindowMinimizeButtonHint, WindowMaximizeButtonHint = Qt::WindowMaximizeButtonHint, WindowMinMaxButtonsHint = Qt::WindowMinMaxButtonsHint, WindowContextHelpButtonHint = Qt::WindowContextHelpButtonHint, WindowShadeButtonHint = Qt::WindowShadeButtonHint, WindowStaysOnTopHint = Qt::WindowStaysOnTopHint, WindowTransparentForInput = Qt::WindowTransparentForInput, WindowOverridesSystemGestures = Qt::WindowOverridesSystemGestures, WindowDoesNotAcceptFocus = Qt::WindowDoesNotAcceptFocus, MaximizeUsingFullscreenGeometryHint = Qt::MaximizeUsingFullscreenGeometryHint, CustomizeWindowHint = Qt::CustomizeWindowHint, WindowStaysOnBottomHint = Qt::WindowStaysOnBottomHint, WindowCloseButtonHint = Qt::WindowCloseButtonHint, MacWindowToolBarButtonHint = Qt::MacWindowToolBarButtonHint, BypassGraphicsProxyWidget = Qt::BypassGraphicsProxyWidget, NoDropShadowWindowHint = Qt::NoDropShadowWindowHint, WindowFullscreenButtonHint = Qt::WindowFullscreenButtonHint, WindowOkButtonHint = Qt::WindowOkButtonHint, WindowCancelButtonHint = Qt::WindowCancelButtonHint};
1275+
Widget = Qt::Widget, Window = Qt::Window, Dialog = Qt::Dialog, Sheet = Qt::Sheet, Drawer = Qt::Drawer, Popup = Qt::Popup, Tool = Qt::Tool, ToolTip = Qt::ToolTip, SplashScreen = Qt::SplashScreen, Desktop = Qt::Desktop, SubWindow = Qt::SubWindow, ForeignWindow = Qt::ForeignWindow, CoverWindow = Qt::CoverWindow, WindowType_Mask = Qt::WindowType_Mask, MSWindowsFixedSizeDialogHint = Qt::MSWindowsFixedSizeDialogHint, MSWindowsOwnDC = Qt::MSWindowsOwnDC, BypassWindowManagerHint = Qt::BypassWindowManagerHint, X11BypassWindowManagerHint = Qt::X11BypassWindowManagerHint, FramelessWindowHint = Qt::FramelessWindowHint, WindowTitleHint = Qt::WindowTitleHint, WindowSystemMenuHint = Qt::WindowSystemMenuHint, WindowMinimizeButtonHint = Qt::WindowMinimizeButtonHint, WindowMaximizeButtonHint = Qt::WindowMaximizeButtonHint, WindowMinMaxButtonsHint = Qt::WindowMinMaxButtonsHint, WindowContextHelpButtonHint = Qt::WindowContextHelpButtonHint, WindowShadeButtonHint = Qt::WindowShadeButtonHint, WindowStaysOnTopHint = Qt::WindowStaysOnTopHint, WindowTransparentForInput = Qt::WindowTransparentForInput, WindowOverridesSystemGestures = Qt::WindowOverridesSystemGestures, WindowDoesNotAcceptFocus = Qt::WindowDoesNotAcceptFocus, CustomizeWindowHint = Qt::CustomizeWindowHint, WindowStaysOnBottomHint = Qt::WindowStaysOnBottomHint, WindowCloseButtonHint = Qt::WindowCloseButtonHint, MacWindowToolBarButtonHint = Qt::MacWindowToolBarButtonHint, BypassGraphicsProxyWidget = Qt::BypassGraphicsProxyWidget, NoDropShadowWindowHint = Qt::NoDropShadowWindowHint, WindowFullscreenButtonHint = Qt::WindowFullscreenButtonHint
1276+
#if QT_VERSION < 0x50800
1277+
, WindowOkButtonHint = Qt::WindowOkButtonHint, WindowCancelButtonHint = Qt::WindowCancelButtonHint
1278+
#endif
1279+
};
12761280
Q_DECLARE_FLAGS(Alignment, AlignmentFlag)
12771281
Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea)
12781282
Q_DECLARE_FLAGS(DropActions, DropAction)

0 commit comments

Comments
 (0)