mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-24 07:08:38 -05:00
cmake-gui: Prefer local variable for Qt major version
QT_DEFAULT_MAJOR_VERSION was added in Qt 5.15 and CMake supports Qt versions >= 5.9
This commit is contained in:
committed by
Brad King
parent
50fcc94bc5
commit
684dcdbc5b
@@ -9,30 +9,34 @@ set (QT_COMPONENTS
|
||||
Gui
|
||||
)
|
||||
# Look for Qt6 first
|
||||
find_package(Qt6
|
||||
COMPONENTS ${QT_COMPONENTS}
|
||||
QUIET
|
||||
)
|
||||
if (NOT Qt6Widgets_FOUND)
|
||||
find_package(Qt5
|
||||
find_package(Qt6Widgets QUIET)
|
||||
set(INSTALLED_QT_VERSION 6)
|
||||
if(NOT Qt6Widgets_FOUND)
|
||||
find_package(Qt5Widgets QUIET)
|
||||
if(NOT Qt5Widgets_FOUND)
|
||||
message(FATAL_ERROR "Could not find a valid Qt installation.")
|
||||
endif()
|
||||
set(INSTALLED_QT_VERSION 5)
|
||||
endif()
|
||||
|
||||
find_package(Qt${INSTALLED_QT_VERSION}
|
||||
COMPONENTS ${QT_COMPONENTS}
|
||||
REQUIRED QUIET
|
||||
)
|
||||
endif()
|
||||
)
|
||||
|
||||
set(CMake_QT_EXTRA_LIBRARIES)
|
||||
|
||||
# Try to find the package WinExtras for the task bar progress
|
||||
if(WIN32)
|
||||
find_package(Qt${QT_DEFAULT_MAJOR_VERSION}WinExtras QUIET)
|
||||
if (Qt${QT_DEFAULT_MAJOR_VERSION}WinExtras_FOUND)
|
||||
find_package(Qt${INSTALLED_QT_VERSION}WinExtras QUIET)
|
||||
if (Qt${INSTALLED_QT_VERSION}WinExtras_FOUND)
|
||||
add_definitions(-DQT_WINEXTRAS)
|
||||
list(APPEND CMake_QT_EXTRA_LIBRARIES Qt${QT_DEFAULT_MAJOR_VERSION}::WinExtras)
|
||||
list(APPEND CMake_QT_EXTRA_LIBRARIES Qt${INSTALLED_QT_VERSION}::WinExtras)
|
||||
list(APPEND QT_COMPONENTS WinExtras)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt${QT_DEFAULT_MAJOR_VERSION}Widgets_EXECUTABLE_COMPILE_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt${INSTALLED_QT_VERSION}Widgets_EXECUTABLE_COMPILE_FLAGS}")
|
||||
|
||||
if(CMake_QT_STATIC_QXcbIntegrationPlugin_LIBRARIES)
|
||||
list(APPEND CMake_QT_EXTRA_LIBRARIES ${CMake_QT_STATIC_QXcbIntegrationPlugin_LIBRARIES})
|
||||
@@ -51,7 +55,7 @@ endif()
|
||||
# Qt5 support is missing there.
|
||||
if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
|
||||
function(_qt_get_plugin_name_with_version target out_var)
|
||||
string(REGEX REPLACE "^Qt::(.+)" "Qt${QT_DEFAULT_MAJOR_VERSION}::\\1"
|
||||
string(REGEX REPLACE "^Qt::(.+)" "Qt${INSTALLED_QT_VERSION}::\\1"
|
||||
qt_plugin_with_version "${target}")
|
||||
if(TARGET "${qt_plugin_with_version}")
|
||||
set("${out_var}" "${qt_plugin_with_version}" PARENT_SCOPE)
|
||||
@@ -87,16 +91,16 @@ if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
|
||||
endmacro()
|
||||
macro(install_qt_plugins _comps _plugins_var)
|
||||
foreach(_qt_comp ${${_comps}})
|
||||
if (QT_DEFAULT_MAJOR_VERSION VERSION_LESS 6)
|
||||
set(_qt_module_plugins ${Qt${QT_DEFAULT_MAJOR_VERSION}${_qt_comp}_PLUGINS})
|
||||
if (INSTALLED_QT_VERSION VERSION_LESS 6)
|
||||
set(_qt_module_plugins ${Qt${INSTALLED_QT_VERSION}${_qt_comp}_PLUGINS})
|
||||
else()
|
||||
get_target_property(_qt_module_plugins Qt${QT_DEFAULT_MAJOR_VERSION}::${_qt_comp} QT_PLUGINS)
|
||||
get_target_property(_qt_module_plugins Qt${INSTALLED_QT_VERSION}::${_qt_comp} QT_PLUGINS)
|
||||
endif()
|
||||
foreach(_qt_plugin ${_qt_module_plugins})
|
||||
if (QT_DEFAULT_MAJOR_VERSION VERSION_GREATER_EQUAL 6)
|
||||
if (INSTALLED_QT_VERSION VERSION_GREATER_EQUAL 6)
|
||||
# Qt6 provides the plugins as individual packages that need to be found.
|
||||
find_package(Qt${QT_DEFAULT_MAJOR_VERSION}${_qt_plugin} QUIET
|
||||
PATHS ${Qt${QT_DEFAULT_MAJOR_VERSION}${_qt_comp}_DIR})
|
||||
find_package(Qt${INSTALLED_QT_VERSION}${_qt_plugin} QUIET
|
||||
PATHS ${Qt${INSTALLED_QT_VERSION}${_qt_comp}_DIR})
|
||||
endif()
|
||||
install_qt_plugin(${_qt_plugin} _plugins_var)
|
||||
endforeach()
|
||||
@@ -118,7 +122,7 @@ if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
|
||||
endif()
|
||||
endif()
|
||||
|
||||
get_property(_Qt_Core_LOCATION TARGET Qt${QT_DEFAULT_MAJOR_VERSION}::Core PROPERTY LOCATION)
|
||||
get_property(_Qt_Core_LOCATION TARGET Qt${INSTALLED_QT_VERSION}::Core PROPERTY LOCATION)
|
||||
get_filename_component(Qt_BIN_DIR "${_Qt_Core_LOCATION}" PATH)
|
||||
if(APPLE)
|
||||
get_filename_component(Qt_BIN_DIR "${Qt_BIN_DIR}" PATH)
|
||||
@@ -176,7 +180,7 @@ set(MOC_SRCS
|
||||
)
|
||||
set(QRC_SRCS CMakeSetup.qrc)
|
||||
|
||||
if (QT_DEFAULT_MAJOR_VERSION VERSION_LESS 6)
|
||||
if (INSTALLED_QT_VERSION VERSION_LESS 6)
|
||||
qt5_wrap_ui(UI_BUILT_SRCS ${UI_SRCS})
|
||||
qt5_wrap_cpp(MOC_BUILT_SRCS ${MOC_SRCS})
|
||||
qt5_add_resources(QRC_BUILT_SRCS ${QRC_SRCS})
|
||||
@@ -210,13 +214,13 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
add_library(CMakeGUILib STATIC ${SRCS})
|
||||
# CMake_QT_EXTRA_LIBRARIES have to come before the main libraries on the link line
|
||||
target_link_libraries(CMakeGUILib PUBLIC CMakeLib ${CMake_QT_EXTRA_LIBRARIES}
|
||||
Qt${QT_DEFAULT_MAJOR_VERSION}::Core Qt${QT_DEFAULT_MAJOR_VERSION}::Widgets)
|
||||
Qt${INSTALLED_QT_VERSION}::Core Qt${INSTALLED_QT_VERSION}::Widgets)
|
||||
|
||||
add_library(CMakeGUIMainLib STATIC CMakeSetup.cxx)
|
||||
target_link_libraries(CMakeGUIMainLib PUBLIC CMakeGUILib)
|
||||
|
||||
add_executable(cmake-gui WIN32 MACOSX_BUNDLE CMakeGUIExec.cxx ${MANIFEST_FILE})
|
||||
target_link_libraries(cmake-gui CMakeGUIMainLib Qt${QT_DEFAULT_MAJOR_VERSION}::Core)
|
||||
target_link_libraries(cmake-gui CMakeGUIMainLib Qt${INSTALLED_QT_VERSION}::Core)
|
||||
|
||||
if(WIN32)
|
||||
target_sources(CMakeGUIMainLib INTERFACE $<TARGET_OBJECTS:CMakeVersion> CMakeSetup.rc)
|
||||
|
||||
Reference in New Issue
Block a user