Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[patched-9] Update PythonQtGenerator CMake build-system to support Qt5 and Qt6 #89

Open
wants to merge 1 commit into
base: patched-9
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,27 @@ 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.5.3")
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${PythonQtGenerator_QT_VERSION} components [${qt_required_components}]")

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

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

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

set(ui_sources )

#-----------------------------------------------------------------------------
# Resources
Expand All @@ -108,9 +106,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 +129,6 @@ endforeach()

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

Expand All @@ -147,11 +143,14 @@ 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
$<$<VERSION_EQUAL:${PythonQtGenerator_QT_VERSION},6>:Qt6::Core5Compat>
)

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