support qt5/6

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-01-14 18:32:54 +08:00
parent 98f891389a
commit cfb110c8b2

View File

@ -72,19 +72,61 @@ macro(init_qt)
set(CMAKE_AUTOUIC ON) # UI files set(CMAKE_AUTOUIC ON) # UI files
endmacro() endmacro()
IF(CM_BUILD_QT)
SET(CM_QT_MAJOR_VERSION "Auto" CACHE STRING "Choose a version of Qt")
SET(SUPPORTED_QT_VERSION "Auto" 5 6)
SET_PROPERTY(CACHE CM_QT_MAJOR_VERSION PROPERTY STRINGS ${SUPPORTED_QT_VERSION})
IF(NOT CM_QT_MAJOR_VERSION STREQUAL "Auto")
IF(NOT CM_QT_MAJOR_VERSION IN_LIST SUPPORTED_QT_VERSION)
message(FATAL_ERROR "Supported Qt versions are \"${SUPPORTED_QT_VERSIONS}\"."
" But CMake_QT_MAJOR_VERSION is set to ${CM_QT_MAJOR_VERSION}.")
endif()
ELSE()
find_package(Qt6Widgets QUIET)
if(NOT Qt6Widgets_FOUND)
find_package(Qt5Widgets QUIET)
if(NOT Qt5Widgets_FOUND)
message(FATAL_ERROR "Could not find a valid Qt installation.")
else()
set(CM_QT_MAJOR_VERSION 5)
endif()
else()
set(CM_QT_MAJOR_VERSION 6)
endif()
ENDIF()
add_definitions("-DHGL_QT=${CM_QT_MAJOR_VERSION}")
if(CM_QT_MAJOR_VERSION VERSION_EQUAL "6")
set(QT_MIN_VERSION "6.0.0")
include_directories(${Qt6Core_INCLUDES})
add_definitions(${Qt6Core_DEFINITIONS})
elseif(CM_QT_MAJOR_VERSION VERSION_EQUAL "5")
set(QT_MIN_VERSION "5.14.0")
include_directories(${Qt5Core_INCLUDES})
add_definitions(${Qt5Core_DEFINITIONS})
else()
SET(CM_QT_MAJOR_VERSION "0")
endif()
init_os_bundle() init_os_bundle()
init_qt() init_qt()
fix_win_compiler() fix_win_compiler()
set(QT_MIN_VERSION "5.14.0") find_package(Qt${CM_QT_MAJOR_VERSION} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Widgets)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Widgets)
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Set additional project information # Set additional project information
set(COMPANY "hyzgame.com") set(COMPANY "hyzgame.com")
set(COPYRIGHT "Copyright (c) 1997-2022 hyzgame.com. All rights reserved.") set(COPYRIGHT "Copyright (c) 1997-2022 hyzgame.com. All rights reserved.")
add_definitions(-D_USE_MATH_DEFINES) IF(CM_QT_EXTRA_STYLE)
add_definitions("-DUSE_EXTRA_QT_STYLE")
SET(CM_QT_EXTRA_STYLE_RC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/CMQT/src/style/bb10style/qbb10brightstyle.qrc SET(CM_QT_EXTRA_STYLE_RC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/CMQT/src/style/bb10style/qbb10brightstyle.qrc
${CMAKE_CURRENT_SOURCE_DIR}/CMQT/src/style/bb10style/qbb10darkstyle.qrc) ${CMAKE_CURRENT_SOURCE_DIR}/CMQT/src/style/bb10style/qbb10darkstyle.qrc)
ENDIF()
ENDIF(CM_BUILD_QT)