@@ -14,14 +14,33 @@ project(PythonQt)
1414#----------------------------------------------------------------------------
1515# Qt version
1616
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+
1724# 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 ()
1936
2037# Requirements
38+ set (minimum_required_qt5_version "5.3.0" )
2139set (minimum_required_qt4_version "4.6.2" )
2240set (minimum_required_qt_version ${minimum_required_qt${PythonQt_QT_VERSION} _version})
2341
2442# Qt components
43+ set (qt5libs Core Widgets Network OpenGL Sql Svg UiTools WebKitWidgets Xml XmlPatterns)
2544set (qt4libs core gui network opengl sql svg uitools webkit xml xmlpatterns)
2645set (qtlibs ${qt${PythonQt_QT_VERSION} libs})
2746
@@ -54,15 +73,32 @@ if(NOT DEFINED PythonQt_INSTALL_INCLUDE_DIR)
5473 set (PythonQt_INSTALL_INCLUDE_DIR include /PythonQt)
5574endif ()
5675
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.
5779set (qt4_wrapped_libs ${qt4libs} )
80+ set (qt5_wrapped_libs ${qt4libs} )
5881set (qt_wrapped_libs ${qt${PythonQt_QT_VERSION} _wrapped_libs})
5982
83+ set (qt5_wrapped_lib_depends_gui Multimedia)
84+
85+ set (qtlib_to_wraplib_Widgets gui)
86+ set (qtlib_to_wraplib_WebKitWidgets webkit)
87+
6088# Define PythonQt_Wrap_Qt* options
6189option (PythonQt_Wrap_QtAll "Make all Qt components available in python" OFF )
6290foreach (qtlib ${qt_wrapped_libs} )
6391 OPTION (PythonQt_Wrap_Qt${qtlib} "Make all of Qt${qtlib} available in python" OFF )
6492endforeach ()
6593
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 ()
66102
67103# Force option if it applies
68104if (PythonQt_Wrap_QtAll)
@@ -89,46 +125,86 @@ endif()
89125#-----------------------------------------------------------------------------
90126# Setup Qt
91127
128+ if (PythonQt_QT_VERSION VERSION_GREATER "4" )
92129
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)
94142
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)
96145
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 ()
98152
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 ()
102159
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} ." )
108170 endif ()
109- set (QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib} })
110- endforeach ()
111171
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 ()
113180
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} )
118183
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 ()
122194
123195#-----------------------------------------------------------------------------
124196# The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers
125197# associated with the Qt version being used.
126198
127199set (generated_cpp_suffix_46 _47)
200+ set (generated_cpp_suffix_52 _50)
201+ set (generated_cpp_suffix_51 _50)
128202
129203set (generated_cpp_suffix "_${QT_VERSION_MAJOR}${QT_VERSION_MINOR} " )
130204if (DEFINED generated_cpp_suffix_${QT_VERSION_MAJOR}${QT_VERSION_MINOR} )
131205 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" )
132208endif ()
133209
134210#-----------------------------------------------------------------------------
@@ -216,7 +292,7 @@ foreach(qtlib ${qt_wrapped_libs})
216292
217293 set (file_prefix generated_cpp${generated_cpp_suffix} /com_trolltech_qt_${qtlib} /com_trolltech_qt_${qtlib} )
218294
219- foreach (index RANGE 0 11 )
295+ foreach (index RANGE 0 12 )
220296
221297 # Source files
222298 if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /${file_prefix}${index} .cpp)
0 commit comments