Add support for building with Qt6 (#865)

Co-authored-by: WaluigiWare64 <68647953+WaluigiWare64@users.noreply.github.com>
This commit is contained in:
Nadia Holmquist Pedersen
2021-04-24 15:30:10 +02:00
committed by GitHub
parent def272fac4
commit 0834fc1533
3 changed files with 40 additions and 12 deletions

View File

@ -32,20 +32,36 @@ SET(SOURCES_QT_SDL
../../../melon.qrc
)
option(USE_QT6 "Build using Qt 6 instead of 5" OFF)
if (WIN32)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -i <SOURCE> -o <OBJECT>")
endif()
if (BUILD_STATIC AND QT5_STATIC_DIR)
set(QT5_STATIC_BASE ${QT5_STATIC_DIR}/lib/cmake/Qt5)
set(Qt5_DIR ${QT5_STATIC_BASE})
set(Qt5Core_DIR ${QT5_STATIC_BASE}Core)
set(Qt5Gui_DIR ${QT5_STATIC_BASE}Gui)
set(Qt5Widgets_DIR ${QT5_STATIC_BASE}Widgets)
if (USE_QT6)
if (BUILD_STATIC AND QT6_STATIC_DIR)
set(QT6_STATIC_BASE ${QT6_STATIC_DIR}/lib/cmake/Qt6)
set(Qt6_DIR ${QT6_STATIC_BASE})
set(Qt6Core_DIR ${QT6_STATIC_BASE}Core)
set(Qt6Gui_DIR ${QT6_STATIC_BASE}Gui)
set(Qt6Widgets_DIR ${QT6_STATIC_BASE}Widgets)
set(Qt6OpenGL_DIR ${QT6_STATIC_BASE}OpenGL)
set(Qt6OpenGLWidgets_DIR ${QT6_STATIC_BASE}OpenGLWidgets)
endif()
find_package(Qt6 COMPONENTS Core Gui Widgets OpenGL OpenGLWidgets REQUIRED)
set(QT_LINK_LIBS Qt6::Core Qt6::Gui Qt6::Widgets Qt6::OpenGL Qt6::OpenGLWidgets)
else()
if (BUILD_STATIC AND QT5_STATIC_DIR)
set(QT5_STATIC_BASE ${QT5_STATIC_DIR}/lib/cmake/Qt5)
set(Qt5_DIR ${QT5_STATIC_BASE})
set(Qt5Core_DIR ${QT5_STATIC_BASE}Core)
set(Qt5Gui_DIR ${QT5_STATIC_BASE}Gui)
set(Qt5Widgets_DIR ${QT5_STATIC_BASE}Widgets)
endif()
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
set(QT_LINK_LIBS Qt5::Core Qt5::Gui Qt5::Widgets)
endif()
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
@ -87,7 +103,7 @@ endif()
if (UNIX)
option(PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF)
target_link_libraries(melonDS Qt5::Core Qt5::Gui Qt5::Widgets)
target_link_libraries(melonDS ${QT_LINK_LIBS})
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(melonDS dl)
endif()
@ -98,9 +114,9 @@ elseif (WIN32)
target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32)
if (BUILD_STATIC)
target_link_libraries(melonDS imm32 winmm version setupapi -static Qt5::Core Qt5::Gui Qt5::Widgets zstd)
target_link_libraries(melonDS imm32 winmm version setupapi -static z zstd ${QT_LINK_LIBS})
else()
target_link_libraries(melonDS Qt5::Core Qt5::Gui Qt5::Widgets)
target_link_libraries(melonDS ${QT_LINK_LIBS})
endif()
endif()
@ -119,6 +135,13 @@ if (APPLE)
target_sources(melonDS PRIVATE "${CMAKE_SOURCE_DIR}/melon.icns")
set_source_files_properties("${CMAKE_SOURCE_DIR}/melon.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
# Qt 6 requires macOS 10.15 if building on 10.15 or greater
if(CMAKE_SYSTEM_VERSION VERSION_GREATER "10.14")
if (USE_QT6)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version" FORCE)
endif()
endif()
option(MACOS_BUNDLE_LIBS "Bundle libraries with the app on macOS" OFF)
option(MACOS_BUILD_DMG "Build DMG image of the macOS application bundle" OFF)