@@ -11,6 +11,39 @@ cmake_minimum_required(VERSION 2.8)
11
11
project (PythonQt )
12
12
#-----------------------------------------------------------------------------
13
13
14
+ #----------------------------------------------------------------------------
15
+ # Qt version
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
+
24
+ # 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 ()
36
+
37
+ # Requirements
38
+ set (minimum_required_qt5_version "5.3.0" )
39
+ set (minimum_required_qt4_version "4.6.2" )
40
+ set (minimum_required_qt_version ${minimum_required_qt${PythonQt_QT_VERSION}_version} )
41
+
42
+ # 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} )
46
+
14
47
#-----------------------------------------------------------------------------
15
48
# Python libraries
16
49
@@ -40,17 +73,41 @@ if(NOT DEFINED PythonQt_INSTALL_INCLUDE_DIR)
40
73
set (PythonQt_INSTALL_INCLUDE_DIR include /PythonQt )
41
74
endif ()
42
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.
79
+ set (qt4_wrapped_libs ${qt4libs} )
80
+ set (qt5_wrapped_libs ${qt4libs} )
81
+ set (qt_wrapped_libs ${qt${PythonQt_QT_VERSION}_wrapped_libs} )
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
+
88
+ # Define PythonQt_Wrap_Qt* options
43
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 ()
44
93
45
- set ( qtlibs core gui network opengl sql svg uitools webkit xml xmlpatterns )
94
+ # Set qtlib_to_wraplib_* variables
46
95
foreach (qtlib ${qtlibs} )
47
- OPTION (PythonQt_Wrap_Qt${qtlib} "Make all of Qt${qtlib} available in python" OFF )
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} )
48
101
endforeach ()
49
102
50
103
# Force option if it applies
51
104
if (PythonQt_Wrap_QtAll )
52
- list (REMOVE_ITEM qtlibs xmlpatterns ) # xmlpatterns wrapper does *NOT* build at all :(
53
- foreach (qtlib ${qtlibs} )
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} )
54
111
if (NOT ${PythonQt_Wrap_Qt${qtlib}} )
55
112
set (PythonQt_Wrap_Qt${qtlib} ON CACHE BOOL "Make all of Qt${qtlib} available in python" FORCE )
56
113
message (STATUS "Enabling [PythonQt_Wrap_Qt${qtlib} ] because of [PythonQt_Wrap_QtAll] evaluates to True" )
@@ -68,40 +125,86 @@ endif()
68
125
#-----------------------------------------------------------------------------
69
126
# Setup Qt
70
127
71
- set (minimum_required_qt_version "4.6.2" )
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 )
140
+ endif ()
141
+ list (REMOVE_DUPLICATES qt_required_components )
72
142
73
- find_package (Qt4 )
143
+ message (STATUS "${PROJECT_NAME} : Required Qt components [${qt_required_components} ]" )
144
+ find_package (Qt5 ${minimum_required_qt_version} COMPONENTS ${qt_required_components} REQUIRED )
74
145
75
- if (QT4_FOUND )
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 ()
76
152
77
- set (found_qt_version ${QT_VERSION_MAJOR} .${QT_VERSION_MINOR}.${QT_VERSION_PATCH} )
153
+ set (QT_VERSION_MAJOR ${Qt5Core_VERSION_MAJOR} )
154
+ set (QT_VERSION_MINOR ${Qt5Core_VERSION_MINOR} )
78
155
79
- if ( ${found_qt_version} VERSION_LESS ${minimum_required_qt_version} )
80
- message ( FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version} ." )
81
- endif ()
156
+ macro ( pythonqt_wrap_cpp )
157
+ qt5_wrap_cpp ( ${ARGV} )
158
+ endmacro ()
82
159
83
- # Enable required qt module
84
- foreach (qtlib network opengl sql svg uitools webkit xml xmlpatterns )
85
- string (TOUPPER ${qtlib} qtlib_uppercase )
86
- if (NOT ${QT_QT${qtlib_uppercase}_FOUND} )
87
- 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} ." )
88
170
endif ()
89
- set (QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}} )
90
- endforeach ()
91
171
92
- 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 ()
180
+
181
+ # Enable QtTest in Qt4 is the option BUILD_TESTING was activated
182
+ set (QT_USE_QTTEST ${BUILD_TESTING} )
183
+
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 ()
93
192
94
- include (${QT_USE_FILE} )
95
- else ()
96
- message (FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable" )
97
193
endif ()
98
194
99
195
#-----------------------------------------------------------------------------
100
196
# The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers
101
197
# associated with the Qt version being used.
198
+
199
+ set (generated_cpp_suffix_46 _47 )
200
+ set (generated_cpp_suffix_52 _50 )
201
+ set (generated_cpp_suffix_51 _50 )
202
+
102
203
set (generated_cpp_suffix "_${QT_VERSION_MAJOR}${QT_VERSION_MINOR} " )
103
- if ("${generated_cpp_suffix} " STREQUAL "_46" )
104
- set (generated_cpp_suffix "_47" ) # Also use 4.7 wrappers for 4.6.x version
204
+ if (DEFINED generated_cpp_suffix_${QT_VERSION_MAJOR}${QT_VERSION_MINOR} )
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" )
105
208
endif ()
106
209
107
210
#-----------------------------------------------------------------------------
@@ -181,15 +284,15 @@ set(moc_sources
181
284
182
285
#-----------------------------------------------------------------------------
183
286
# Add extra sources
184
- foreach (qtlib core gui network opengl sql svg uitools webkit xml xmlpatterns )
287
+ foreach (qtlib ${qt_wrapped_libs} )
185
288
186
289
if (${PythonQt_Wrap_Qt${qtlib}} )
187
290
188
291
ADD_DEFINITIONS (-DPYTHONQT_WRAP_Qt${qtlib} )
189
292
190
293
set (file_prefix generated_cpp${generated_cpp_suffix}/com_trolltech_qt_${qtlib}/com_trolltech_qt_${qtlib} )
191
294
192
- foreach (index RANGE 0 11 )
295
+ foreach (index RANGE 0 12 )
193
296
194
297
# Source files
195
298
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /${file_prefix}${index}.cpp )
@@ -208,19 +311,9 @@ foreach(qtlib core gui network opengl sql svg uitools webkit xml xmlpatterns)
208
311
endif ()
209
312
endforeach ()
210
313
211
- #-----------------------------------------------------------------------------
212
- # UI files
213
- set (ui_sources )
214
-
215
- #-----------------------------------------------------------------------------
216
- # Resources
217
- set (qrc_sources )
218
-
219
314
#-----------------------------------------------------------------------------
220
315
# Do wrapping
221
- qt4_wrap_cpp (gen_moc_sources ${moc_sources} )
222
- qt4_wrap_ui (gen_ui_sources ${ui_sources} )
223
- qt4_add_resources (gen_qrc_sources ${qrc_sources} )
316
+ pythonqt_wrap_cpp (gen_moc_sources ${moc_sources} )
224
317
225
318
#-----------------------------------------------------------------------------
226
319
# Build the library
@@ -232,8 +325,6 @@ include_directories(
232
325
add_library (PythonQt SHARED
233
326
${sources}
234
327
${gen_moc_sources}
235
- ${gen_ui_sources}
236
- ${gen_qrc_sources}
237
328
)
238
329
set_target_properties (PythonQt PROPERTIES DEFINE_SYMBOL PYTHONQT_EXPORTS )
239
330
@@ -270,12 +361,14 @@ if(BUILD_TESTING)
270
361
tests/PythonQtTestMain.cpp
271
362
)
272
363
364
+ set_property (SOURCE tests/PythonQtTestMain.cpp PROPERTY COMPILE_DEFINITIONS "main=tests_PythonQtTestMain" )
365
+
273
366
list (APPEND test_sources
274
367
tests/PythonQtTests.cpp
275
368
tests/PythonQtTests.h
276
369
)
277
370
278
- QT4_WRAP_CPP (test_sources
371
+ pythonqt_wrap_cpp (test_sources
279
372
tests/PythonQtTests.h
280
373
)
281
374
@@ -286,12 +379,12 @@ if(BUILD_TESTING)
286
379
tests/PythonQtTestCleanup.cpp
287
380
tests/PythonQtTestCleanup.h
288
381
)
289
- QT4_WRAP_CPP (test_sources
382
+ pythonqt_wrap_cpp (test_sources
290
383
tests/PythonQtTestCleanup.h
291
384
)
292
- endif ()
293
385
294
- set_property (SOURCE tests/PythonQtTestMain.cpp PROPERTY COMPILE_DEFINITIONS "main=tests_PythonQtTestMain" )
386
+ set_property (SOURCE tests/PythonQtTestMain.cpp APPEND PROPERTY COMPILE_DEFINITIONS "PythonQt_Wrap_Qtcore" )
387
+ endif ()
295
388
296
389
add_executable (PythonQtCppTests ${test_sources} )
297
390
target_link_libraries (PythonQtCppTests PythonQt )
0 commit comments