Skip to content

Commit 58781ab

Browse files
committed
Update PythonQtGenerator CMake build-system to support Qt5 and Qt6
This removes Qt4 support and adds support for Qt5 and Qt6.
1 parent 0580304 commit 58781ab

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

generator/CMakeLists.txt

+25-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 2.8)
1+
cmake_minimum_required(VERSION 3.5)
22

33
#-----------------------------------------------------------------------------
44
project(PythonQtGenerator)
@@ -9,24 +9,28 @@ include(CTestUseLaunchers OPTIONAL)
99
#-----------------------------------------------------------------------------
1010
# Setup Qt
1111

12-
set(minimum_required_qt_version "4.6.2")
12+
if(NOT DEFINED PythonQtGenerator_QT_VERSION)
13+
if(DEFINED Qt5_DIR)
14+
set(PythonQtGenerator_QT_VERSION 5)
15+
else()
16+
set(PythonQtGenerator_QT_VERSION 6)
17+
endif()
18+
endif()
1319

14-
find_package(Qt4)
20+
set(minimum_required_qt5_version "5.15.0")
21+
set(minimum_required_qt6_version "6.2.0")
22+
set(minimum_required_qt_version ${minimum_required_qt${PythonQtGenerator_QT_VERSION}_version})
1523

16-
if(QT4_FOUND)
24+
set(qt_required_components Core Xml)
25+
if(PythonQtGenerator_QT_VERSION VERSION_EQUAL 6)
26+
list(APPEND qt_required_components Core5Compat)
27+
endif()
1728

18-
set(found_qt_version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})
29+
message(STATUS "${PROJECT_NAME}: Required Qt components [${qt_required_components}]")
30+
31+
find_package(Qt${PythonQtGenerator_QT_VERSION} ${minimum_required_qt_version}
32+
COMPONENTS ${qt_required_components} REQUIRED)
1933

20-
if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version})
21-
message(FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version}.")
22-
endif()
23-
24-
set(QT_USE_QTXML ON)
25-
26-
include(${QT_USE_FILE})
27-
else()
28-
message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
29-
endif()
3034

3135
#-----------------------------------------------------------------------------
3236
# Sources
@@ -93,11 +97,6 @@ set(moc_sources
9397
shellheadergenerator.h
9498
shellimplgenerator.h
9599
)
96-
97-
#-----------------------------------------------------------------------------
98-
# UI files
99-
100-
set(ui_sources )
101100

102101
#-----------------------------------------------------------------------------
103102
# Resources
@@ -108,9 +107,8 @@ set(qrc_sources
108107

109108
#-----------------------------------------------------------------------------
110109
# Do wrapping
111-
qt4_wrap_cpp(gen_moc_sources ${moc_sources})
112-
qt4_wrap_ui(gen_ui_sources ${ui_sources})
113-
qt4_add_resources(gen_qrc_sources ${qrc_sources})
110+
qt_wrap_cpp(gen_moc_sources ${moc_sources})
111+
qt_add_resources(gen_qrc_sources ${qrc_sources})
114112

115113
#-----------------------------------------------------------------------------
116114
# Copy file expected by the generator and specify install rules
@@ -132,7 +130,6 @@ endforeach()
132130

133131
SOURCE_GROUP("Resources" FILES
134132
${qrc_sources}
135-
${ui_sources}
136133
${files_to_copy}
137134
)
138135

@@ -147,11 +144,13 @@ add_definitions(-DRXX_ALLOCATOR_INIT_0)
147144
add_executable(${PROJECT_NAME}
148145
${sources}
149146
${gen_moc_sources}
150-
${gen_ui_sources}
151147
${gen_qrc_sources}
152148
)
153149

154-
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES})
150+
target_link_libraries(${PROJECT_NAME}
151+
Qt::Core
152+
Qt::Xml
153+
)
155154

156155
#-----------------------------------------------------------------------------
157156
# Install library (on windows, put the dll in 'bin' and the archive in 'lib')

0 commit comments

Comments
 (0)