@@ -14,14 +14,33 @@ project(PythonQt)
14
14
#----------------------------------------------------------------------------
15
15
# Qt version
16
16
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
+
17
24
# Set PythonQt_QT_VERSION
18
- set (PythonQt_QT_VERSION 4 )
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 ()
19
36
20
37
# Requirements
38
+ set (minimum_required_qt5_version "5.3.0" )
21
39
set (minimum_required_qt4_version "4.6.2" )
22
40
set (minimum_required_qt_version ${minimum_required_qt${PythonQt_QT_VERSION}_version} )
23
41
24
42
# Qt components
43
+ set (qt5libs Core Widgets Network OpenGL Sql Svg UiTools WebKitWidgets Xml XmlPatterns )
25
44
set (qt4libs core gui network opengl sql svg uitools webkit xml xmlpatterns )
26
45
set (qtlibs ${qt${PythonQt_QT_VERSION}libs} )
27
46
@@ -54,15 +73,32 @@ if(NOT DEFINED PythonQt_INSTALL_INCLUDE_DIR)
54
73
set (PythonQt_INSTALL_INCLUDE_DIR include /PythonQt )
55
74
endif ()
56
75
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.
57
79
set (qt4_wrapped_libs ${qt4libs} )
80
+ set (qt5_wrapped_libs ${qt4libs} )
58
81
set (qt_wrapped_libs ${qt${PythonQt_QT_VERSION}_wrapped_libs} )
59
82
83
+ set (qt5_wrapped_lib_depends_gui Multimedia )
84
+
85
+ set (qtlib_to_wraplib_Widgets gui )
86
+ set (qtlib_to_wraplib_WebKitWidgets webkit )
87
+
60
88
# Define PythonQt_Wrap_Qt* options
61
89
option (PythonQt_Wrap_QtAll "Make all Qt components available in python" OFF )
62
90
foreach (qtlib ${qt_wrapped_libs} )
63
91
OPTION (PythonQt_Wrap_Qt${qtlib} "Make all of Qt${qtlib} available in python" OFF )
64
92
endforeach ()
65
93
94
+ # Set qtlib_to_wraplib_* variables
95
+ foreach (qtlib ${qtlibs} )
96
+ string (TOLOWER ${qtlib} qtlib_lowercase )
97
+ if (DEFINED qtlib_to_wraplib_${qtlib} )
98
+ set (qtlib_lowercase ${qtlib_to_wraplib_${qtlib}} )
99
+ endif ()
100
+ set (qtlib_to_wraplib_${qtlib} ${qtlib_lowercase} )
101
+ endforeach ()
66
102
67
103
# Force option if it applies
68
104
if (PythonQt_Wrap_QtAll )
@@ -89,46 +125,86 @@ endif()
89
125
#-----------------------------------------------------------------------------
90
126
# Setup Qt
91
127
128
+ if (PythonQt_QT_VERSION VERSION_GREATER "4" )
92
129
93
- find_package (Qt4 )
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 )
140
+ endif ()
141
+ list (REMOVE_DUPLICATES qt_required_components )
94
142
95
- if (QT4_FOUND )
143
+ message (STATUS "${PROJECT_NAME} : Required Qt components [${qt_required_components} ]" )
144
+ find_package (Qt5 ${minimum_required_qt_version} COMPONENTS ${qt_required_components} REQUIRED )
96
145
97
- set (found_qt_version ${QT_VERSION_MAJOR} .${QT_VERSION_MINOR}.${QT_VERSION_PATCH} )
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 ()
98
152
99
- if (${found_qt_version} VERSION_LESS ${minimum_required_qt_version} )
100
- message (FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version} ." )
101
- endif ()
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 ()
102
159
103
- # Enable required qt module
104
- foreach (qtlib ${qt_wrapped_libs} )
105
- string (TOUPPER ${qtlib} qtlib_uppercase )
106
- if (NOT ${QT_QT${qtlib_uppercase}_FOUND} )
107
- message (FATAL_ERROR "QT_QT${qtlib_uppercase} *not* FOUND - Try to disable PythonQt_Wrap_Qt${qtlib} " )
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} ." )
108
170
endif ()
109
- set (QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}} )
110
- endforeach ()
111
171
112
- set (QT_USE_QTTEST ${BUILD_TESTING} )
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 ()
113
180
114
- include (${QT_USE_FILE} )
115
- else ()
116
- message (FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable" )
117
- endif ()
181
+ # Enable QtTest in Qt4 is the option BUILD_TESTING was activated
182
+ set (QT_USE_QTTEST ${BUILD_TESTING} )
118
183
119
- macro (pythonqt_wrap_cpp )
120
- qt4_wrap_cpp (${ARGV} )
121
- endmacro ()
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 ()
188
+
189
+ macro (pythonqt_wrap_cpp )
190
+ qt4_wrap_cpp (${ARGV} )
191
+ endmacro ()
192
+
193
+ endif ()
122
194
123
195
#-----------------------------------------------------------------------------
124
196
# The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers
125
197
# associated with the Qt version being used.
126
198
127
199
set (generated_cpp_suffix_46 _47 )
200
+ set (generated_cpp_suffix_52 _50 )
201
+ set (generated_cpp_suffix_51 _50 )
128
202
129
203
set (generated_cpp_suffix "_${QT_VERSION_MAJOR}${QT_VERSION_MINOR} " )
130
204
if (DEFINED generated_cpp_suffix_${QT_VERSION_MAJOR}${QT_VERSION_MINOR} )
131
205
set (generated_cpp_suffix "${generated_cpp_suffix_${QT_VERSION_MAJOR}${QT_VERSION_MINOR} }" )
206
+ elseif (${QT_VERSION_MAJOR} .${QT_VERSION_MINOR} VERSION_GREATER "5.4" )
207
+ set (generated_cpp_suffix "_54" )
132
208
endif ()
133
209
134
210
#-----------------------------------------------------------------------------
@@ -216,7 +292,7 @@ foreach(qtlib ${qt_wrapped_libs})
216
292
217
293
set (file_prefix generated_cpp${generated_cpp_suffix}/com_trolltech_qt_${qtlib}/com_trolltech_qt_${qtlib} )
218
294
219
- foreach (index RANGE 0 11 )
295
+ foreach (index RANGE 0 12 )
220
296
221
297
# Source files
222
298
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /${file_prefix}${index}.cpp )
0 commit comments