Skip to content

Commit

Permalink
Update PythonQtGenerator CMake build-system to support Qt5 and Qt6
Browse files Browse the repository at this point in the history
This removes Qt4 support and adds support for Qt5 and Qt6.
  • Loading branch information
jcfr committed Jan 31, 2024
1 parent 0580304 commit 58781ab
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.5)

#-----------------------------------------------------------------------------
project(PythonQtGenerator)
Expand All @@ -9,24 +9,28 @@ include(CTestUseLaunchers OPTIONAL)
#-----------------------------------------------------------------------------
# Setup Qt

set(minimum_required_qt_version "4.6.2")
if(NOT DEFINED PythonQtGenerator_QT_VERSION)
if(DEFINED Qt5_DIR)
set(PythonQtGenerator_QT_VERSION 5)
else()
set(PythonQtGenerator_QT_VERSION 6)
endif()
endif()

find_package(Qt4)
set(minimum_required_qt5_version "5.15.0")
set(minimum_required_qt6_version "6.2.0")
set(minimum_required_qt_version ${minimum_required_qt${PythonQtGenerator_QT_VERSION}_version})

if(QT4_FOUND)
set(qt_required_components Core Xml)
if(PythonQtGenerator_QT_VERSION VERSION_EQUAL 6)
list(APPEND qt_required_components Core5Compat)
endif()

set(found_qt_version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})
message(STATUS "${PROJECT_NAME}: Required Qt components [${qt_required_components}]")

find_package(Qt${PythonQtGenerator_QT_VERSION} ${minimum_required_qt_version}
COMPONENTS ${qt_required_components} REQUIRED)

if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version})
message(FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version}.")
endif()

set(QT_USE_QTXML ON)

include(${QT_USE_FILE})
else()
message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
endif()

#-----------------------------------------------------------------------------
# Sources
Expand Down Expand Up @@ -93,11 +97,6 @@ set(moc_sources
shellheadergenerator.h
shellimplgenerator.h
)

#-----------------------------------------------------------------------------
# UI files

set(ui_sources )

#-----------------------------------------------------------------------------
# Resources
Expand All @@ -108,9 +107,8 @@ set(qrc_sources

#-----------------------------------------------------------------------------
# Do wrapping
qt4_wrap_cpp(gen_moc_sources ${moc_sources})
qt4_wrap_ui(gen_ui_sources ${ui_sources})
qt4_add_resources(gen_qrc_sources ${qrc_sources})
qt_wrap_cpp(gen_moc_sources ${moc_sources})
qt_add_resources(gen_qrc_sources ${qrc_sources})

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

SOURCE_GROUP("Resources" FILES
${qrc_sources}
${ui_sources}
${files_to_copy}
)

Expand All @@ -147,11 +144,13 @@ add_definitions(-DRXX_ALLOCATOR_INIT_0)
add_executable(${PROJECT_NAME}
${sources}
${gen_moc_sources}
${gen_ui_sources}
${gen_qrc_sources}
)

target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES})
target_link_libraries(${PROJECT_NAME}
Qt::Core
Qt::Xml
)

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

0 comments on commit 58781ab

Please sign in to comment.