Skip to content

Commit aa976ba

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 aa976ba

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,27 @@ 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.5.3")
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${PythonQtGenerator_QT_VERSION} components [${qt_required_components}]")
1930

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()
31+
find_package(Qt${PythonQtGenerator_QT_VERSION} ${minimum_required_qt_version}
32+
COMPONENTS ${qt_required_components} REQUIRED)
3033

3134
#-----------------------------------------------------------------------------
3235
# Sources
@@ -93,11 +96,6 @@ set(moc_sources
9396
shellheadergenerator.h
9497
shellimplgenerator.h
9598
)
96-
97-
#-----------------------------------------------------------------------------
98-
# UI files
99-
100-
set(ui_sources )
10199

102100
#-----------------------------------------------------------------------------
103101
# Resources
@@ -108,9 +106,8 @@ set(qrc_sources
108106

109107
#-----------------------------------------------------------------------------
110108
# 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})
109+
qt_wrap_cpp(gen_moc_sources ${moc_sources})
110+
qt_add_resources(gen_qrc_sources ${qrc_sources})
114111

115112
#-----------------------------------------------------------------------------
116113
# Copy file expected by the generator and specify install rules
@@ -132,7 +129,6 @@ endforeach()
132129

133130
SOURCE_GROUP("Resources" FILES
134131
${qrc_sources}
135-
${ui_sources}
136132
${files_to_copy}
137133
)
138134

@@ -147,11 +143,14 @@ add_definitions(-DRXX_ALLOCATOR_INIT_0)
147143
add_executable(${PROJECT_NAME}
148144
${sources}
149145
${gen_moc_sources}
150-
${gen_ui_sources}
151146
${gen_qrc_sources}
152147
)
153148

154-
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES})
149+
target_link_libraries(${PROJECT_NAME}
150+
Qt::Core
151+
Qt::Xml
152+
$<$<VERSION_EQUAL:${PythonQtGenerator_QT_VERSION},6>:Qt6::Core5Compat>
153+
)
155154

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

0 commit comments

Comments
 (0)