From f1de6f6682bedc10a9133ed2128f418d58fe1e19 Mon Sep 17 00:00:00 2001 From: Sankhesh Jhaveri Date: Thu, 17 Dec 2020 18:05:53 -0500 Subject: cmake-gui: Support building against Qt6 --- Source/QtDialog/CMakeLists.txt | 90 +++++++++++++++++++++++++++-------- Source/QtDialog/EnvironmentDialog.cxx | 4 ++ Source/QtDialog/QCMakeCacheView.cxx | 4 ++ 3 files changed, 77 insertions(+), 21 deletions(-) diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index 452a303..5d1ddf5 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -3,20 +3,37 @@ project(QtDialog) CMake_OPTIONAL_COMPONENT(cmake-gui) -find_package(Qt5Widgets REQUIRED) +set (QT_COMPONENTS + Core + Widgets + Gui +) +# Look for Qt6 first +find_package(Qt6Widgets QUIET) +if (Qt6Widgets_FOUND) + set(INSTALLED_QT_VERSION 6) +else() + set(INSTALLED_QT_VERSION 5) +endif() + +find_package (Qt${INSTALLED_QT_VERSION} + COMPONENTS ${QT_COMPONENTS} + REQUIRED +) set(CMake_QT_EXTRA_LIBRARIES) # Try to find the package WinExtras for the task bar progress if(WIN32) - find_package(Qt5WinExtras QUIET) - if (Qt5WinExtras_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 Qt5::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} ${Qt5Widgets_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}) @@ -34,8 +51,21 @@ endif() # FIXME: This should be part of Qt5 CMake scripts, but unfortunately # Qt5 support is missing there. if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32)) - macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var) - get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION) + function(_qt_get_plugin_name_with_version target out_var) + string(REGEX REPLACE "^Qt::(.+)" "Qt${QT_DEFAULT_MAJOR_VERSION}::\\1" + qt_plugin_with_version "${target}") + if(TARGET "${qt_plugin_with_version}") + set("${out_var}" "${qt_plugin_with_version}" PARENT_SCOPE) + else() + set("${out_var}" "" PARENT_SCOPE) + endif() + endfunction() + macro(install_qt_plugin _qt_plugin_name _qt_plugins_var) + _qt_get_plugin_name_with_version("Qt::${_qt_plugin_name}" _qt_plugin_with_version_name) + #get_target_property(_qt_plugin_path "${_qt_plugin_with_version_name}" LOCATION) + if(TARGET "${_qt_plugin_with_version_name}") + get_target_property(_qt_plugin_path "${_qt_plugin_with_version_name}" LOCATION) + endif() if(EXISTS "${_qt_plugin_path}") get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME) get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH) @@ -51,19 +81,26 @@ if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32)) ${COMPONENT}) set(${_qt_plugins_var} "${${_qt_plugins_var}};\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${_qt_plugin_dest}/${_qt_plugin_file}") - else() - message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found") endif() endmacro() + macro(install_qt_plugins _comps _plugins_var) + foreach(_qt_comp ${${_comps}}) + get_target_property(_qt_module_plugins Qt${INSTALLED_QT_VERSION}::${_qt_comp} QT_PLUGINS) + foreach(_qt_plugin ${_qt_module_plugins}) + find_package(Qt${INSTALLED_QT_VERSION}${_qt_plugin} QUIET + PATHS ${Qt${INSTALLED_QT_VERSION}${_qt_comp}_DIR}) + install_qt_plugin(${_qt_plugin} _plugins_var) + endforeach() + endforeach() + endmacro() + install_qt_plugins(QT_COMPONENTS QT_PLUGINS) if(APPLE) - install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" "[Paths]\nPlugins = ${_qt_plugin_dir}\n") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" DESTINATION "${CMAKE_INSTALL_PREFIX}/Resources" ${COMPONENT}) elseif(WIN32 AND NOT CMake_QT_STATIC_QWindowsIntegrationPlugin_LIBRARIES) - install_qt5_plugin("Qt5::QWindowsIntegrationPlugin" QT_PLUGINS) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" "[Paths]\nPlugins = ../${_qt_plugin_dir}\n") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" @@ -72,8 +109,8 @@ if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32)) endif() endif() -get_property(_Qt5_Core_LOCATION TARGET Qt5::Core PROPERTY LOCATION) -get_filename_component(Qt_BIN_DIR "${_Qt5_Core_LOCATION}" PATH) +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) endif() @@ -105,7 +142,7 @@ set(SRCS WarningMessagesDialog.cxx WarningMessagesDialog.h ) -qt5_wrap_ui(UI_SRCS +set(UI_SRCS CMakeSetupDialog.ui Compilers.ui CrossCompiler.ui @@ -114,7 +151,7 @@ qt5_wrap_ui(UI_SRCS RegexExplorer.ui WarningMessagesDialog.ui ) -qt5_wrap_cpp(MOC_SRCS +set(MOC_SRCS AddCacheEntry.h Compilers.h CMakeSetupDialog.h @@ -128,7 +165,17 @@ qt5_wrap_cpp(MOC_SRCS RegexExplorer.h WarningMessagesDialog.h ) -qt5_add_resources(RC_SRCS CMakeSetup.qrc) +set(QRC_SRCS CMakeSetup.qrc) + +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}) +else() + qt_wrap_ui(UI_BUILT_SRCS ${UI_SRCS}) + qt_wrap_cpp(MOC_BUILT_SRCS ${MOC_SRCS}) + qt_add_resources(QRC_BUILT_SRCS ${QRC_SRCS}) +endif() if (FALSE) # CMake's bootstrap binary does not support automoc set(CMAKE_AUTOMOC 1) @@ -136,9 +183,9 @@ if (FALSE) # CMake's bootstrap binary does not support automoc set(CMAKE_AUTOUIC 1) else () list(APPEND SRCS - ${UI_SRCS} - ${MOC_SRCS} - ${RC_SRCS}) + ${UI_BUILT_SRCS} + ${MOC_BUILT_SRCS} + ${QRC_BUILT_SRCS}) endif () if(USE_LGPL) @@ -153,13 +200,14 @@ 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} Qt5::Core Qt5::Widgets) +target_link_libraries(CMakeGUILib PUBLIC CMakeLib ${CMake_QT_EXTRA_LIBRARIES} + 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 Qt5::Core) +target_link_libraries(cmake-gui CMakeGUIMainLib Qt${INSTALLED_QT_VERSION}::Core) if(WIN32) target_sources(CMakeGUIMainLib INTERFACE $ CMakeSetup.rc) diff --git a/Source/QtDialog/EnvironmentDialog.cxx b/Source/QtDialog/EnvironmentDialog.cxx index 846456c..d4f978c 100644 --- a/Source/QtDialog/EnvironmentDialog.cxx +++ b/Source/QtDialog/EnvironmentDialog.cxx @@ -81,7 +81,11 @@ bool EnvironmentSearchFilter::filterAcceptsRow(int row, auto* model = this->sourceModel(); auto key = model->data(model->index(row, 0, parent), Qt::DisplayRole).toString(); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) + return key.contains(this->filterRegularExpression()); +#else return key.contains(this->filterRegExp()); +#endif } EnvironmentDialog::EnvironmentDialog(const QProcessEnvironment& environment, diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx index 22f5be1..7c9032e 100644 --- a/Source/QtDialog/QCMakeCacheView.cxx +++ b/Source/QtDialog/QCMakeCacheView.cxx @@ -47,7 +47,11 @@ protected: // check all strings for a match foreach (QString const& str, strs) { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) + if (str.contains(this->filterRegularExpression())) { +#else if (str.contains(this->filterRegExp())) { +#endif return true; } } -- cgit v0.12 From 035078d847e70f9aa8dbe9794c79cf76d6b65434 Mon Sep 17 00:00:00 2001 From: Sankhesh Jhaveri Date: Thu, 17 Dec 2020 18:07:41 -0500 Subject: cmake-gui: Remove explicit locale setup Qt uses utf-8 encoding by default for versions >= Qt5. --- Source/QtDialog/CMakeSetup.cxx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx index 861c6e3..5debdb8 100644 --- a/Source/QtDialog/CMakeSetup.cxx +++ b/Source/QtDialog/CMakeSetup.cxx @@ -7,7 +7,6 @@ #include #include #include -#include #include #include @@ -122,9 +121,6 @@ int main(int argc, char** argv) setlocale(LC_NUMERIC, "C"); - QTextCodec* utf8_codec = QTextCodec::codecForName("UTF-8"); - QTextCodec::setCodecForLocale(utf8_codec); - // tell the cmake library where cmake is QDir cmExecDir(QApplication::applicationDirPath()); #if defined(Q_OS_MAC) -- cgit v0.12 From 2a2942a42e5066086d16049c3eb92d63ab1fa1d6 Mon Sep 17 00:00:00 2001 From: Sankhesh Jhaveri Date: Wed, 16 Dec 2020 01:59:22 -0500 Subject: cmake-gui: Use a consistent Qt major version variable name --- Source/QtDialog/CMakeLists.txt | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index 5d1ddf5..8093ca8 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -9,31 +9,30 @@ set (QT_COMPONENTS Gui ) # Look for Qt6 first -find_package(Qt6Widgets QUIET) -if (Qt6Widgets_FOUND) - set(INSTALLED_QT_VERSION 6) -else() - set(INSTALLED_QT_VERSION 5) -endif() - -find_package (Qt${INSTALLED_QT_VERSION} +find_package(Qt6 COMPONENTS ${QT_COMPONENTS} - REQUIRED + QUIET ) +if (NOT Qt6Widgets_FOUND) + find_package(Qt5 + 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${INSTALLED_QT_VERSION}WinExtras QUIET) - if (Qt${INSTALLED_QT_VERSION}WinExtras_FOUND) + find_package(Qt${QT_DEFAULT_MAJOR_VERSION}WinExtras QUIET) + if (Qt${QT_DEFAULT_MAJOR_VERSION}WinExtras_FOUND) add_definitions(-DQT_WINEXTRAS) - list(APPEND CMake_QT_EXTRA_LIBRARIES Qt${INSTALLED_QT_VERSION}::WinExtras) + list(APPEND CMake_QT_EXTRA_LIBRARIES Qt${QT_DEFAULT_MAJOR_VERSION}::WinExtras) list(APPEND QT_COMPONENTS WinExtras) endif() endif() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt${INSTALLED_QT_VERSION}Widgets_EXECUTABLE_COMPILE_FLAGS}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt${QT_DEFAULT_MAJOR_VERSION}Widgets_EXECUTABLE_COMPILE_FLAGS}") if(CMake_QT_STATIC_QXcbIntegrationPlugin_LIBRARIES) list(APPEND CMake_QT_EXTRA_LIBRARIES ${CMake_QT_STATIC_QXcbIntegrationPlugin_LIBRARIES}) @@ -85,10 +84,10 @@ if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32)) endmacro() macro(install_qt_plugins _comps _plugins_var) foreach(_qt_comp ${${_comps}}) - get_target_property(_qt_module_plugins Qt${INSTALLED_QT_VERSION}::${_qt_comp} QT_PLUGINS) + get_target_property(_qt_module_plugins Qt${QT_DEFAULT_MAJOR_VERSION}::${_qt_comp} QT_PLUGINS) foreach(_qt_plugin ${_qt_module_plugins}) - find_package(Qt${INSTALLED_QT_VERSION}${_qt_plugin} QUIET - PATHS ${Qt${INSTALLED_QT_VERSION}${_qt_comp}_DIR}) + find_package(Qt${QT_DEFAULT_MAJOR_VERSION}${_qt_plugin} QUIET + PATHS ${Qt${QT_DEFAULT_MAJOR_VERSION}${_qt_comp}_DIR}) install_qt_plugin(${_qt_plugin} _plugins_var) endforeach() endforeach() @@ -109,7 +108,7 @@ if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32)) endif() endif() -get_property(_Qt_Core_LOCATION TARGET Qt${INSTALLED_QT_VERSION}::Core PROPERTY LOCATION) +get_property(_Qt_Core_LOCATION TARGET Qt${QT_DEFAULT_MAJOR_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) @@ -167,7 +166,7 @@ set(MOC_SRCS ) set(QRC_SRCS CMakeSetup.qrc) -if (INSTALLED_QT_VERSION VERSION_LESS 6) +if (QT_DEFAULT_MAJOR_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}) @@ -201,13 +200,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${INSTALLED_QT_VERSION}::Core Qt${INSTALLED_QT_VERSION}::Widgets) + Qt${QT_DEFAULT_MAJOR_VERSION}::Core Qt${QT_DEFAULT_MAJOR_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${INSTALLED_QT_VERSION}::Core) +target_link_libraries(cmake-gui CMakeGUIMainLib Qt${QT_DEFAULT_MAJOR_VERSION}::Core) if(WIN32) target_sources(CMakeGUIMainLib INTERFACE $ CMakeSetup.rc) -- cgit v0.12 From 50fcc94bc5f906d7a3427435e8afb3decbbe4cae Mon Sep 17 00:00:00 2001 From: Sankhesh Jhaveri Date: Wed, 16 Dec 2020 02:17:45 -0500 Subject: cmake-gui: Support installation for both Qt5 and Qt6 plugins --- Source/QtDialog/CMakeLists.txt | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index 8093ca8..81f9e70 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -60,10 +60,13 @@ if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32)) endif() endfunction() macro(install_qt_plugin _qt_plugin_name _qt_plugins_var) - _qt_get_plugin_name_with_version("Qt::${_qt_plugin_name}" _qt_plugin_with_version_name) - #get_target_property(_qt_plugin_path "${_qt_plugin_with_version_name}" LOCATION) - if(TARGET "${_qt_plugin_with_version_name}") - get_target_property(_qt_plugin_path "${_qt_plugin_with_version_name}" LOCATION) + if(TARGET "${_qt_plugin_name}") + get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION) + else() + _qt_get_plugin_name_with_version("Qt::${_qt_plugin_name}" _qt_plugin_with_version_name) + if(TARGET "${_qt_plugin_with_version_name}") + get_target_property(_qt_plugin_path "${_qt_plugin_with_version_name}" LOCATION) + endif() endif() if(EXISTS "${_qt_plugin_path}") get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME) @@ -84,10 +87,17 @@ if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32)) endmacro() macro(install_qt_plugins _comps _plugins_var) foreach(_qt_comp ${${_comps}}) - get_target_property(_qt_module_plugins Qt${QT_DEFAULT_MAJOR_VERSION}::${_qt_comp} QT_PLUGINS) + if (QT_DEFAULT_MAJOR_VERSION VERSION_LESS 6) + set(_qt_module_plugins ${Qt${QT_DEFAULT_MAJOR_VERSION}${_qt_comp}_PLUGINS}) + else() + get_target_property(_qt_module_plugins Qt${QT_DEFAULT_MAJOR_VERSION}::${_qt_comp} QT_PLUGINS) + endif() foreach(_qt_plugin ${_qt_module_plugins}) - find_package(Qt${QT_DEFAULT_MAJOR_VERSION}${_qt_plugin} QUIET - PATHS ${Qt${QT_DEFAULT_MAJOR_VERSION}${_qt_comp}_DIR}) + if (QT_DEFAULT_MAJOR_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}) + endif() install_qt_plugin(${_qt_plugin} _plugins_var) endforeach() endforeach() -- cgit v0.12 From 684dcdbc5bb6998606bdb8631cbab5e1905b762c Mon Sep 17 00:00:00 2001 From: Sankhesh Jhaveri Date: Thu, 17 Dec 2020 18:22:42 -0500 Subject: 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 --- Source/QtDialog/CMakeLists.txt | 50 +++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index 81f9e70..ce55f51 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -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 $ CMakeSetup.rc) -- cgit v0.12 From 020b2766f31c19f6a5953e3365641aeba06c3552 Mon Sep 17 00:00:00 2001 From: Sankhesh Jhaveri Date: Thu, 17 Dec 2020 18:28:24 -0500 Subject: cmake-gui: Replace obsolete QDirModel with QFileSystemModel --- Source/QtDialog/QCMakeWidgets.cxx | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Source/QtDialog/QCMakeWidgets.cxx b/Source/QtDialog/QCMakeWidgets.cxx index e68faba..45fd425 100644 --- a/Source/QtDialog/QCMakeWidgets.cxx +++ b/Source/QtDialog/QCMakeWidgets.cxx @@ -1,17 +1,13 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ -// FIXME: Port to QFileSystemModel from the deprecated QDirModel. -// Be sure completion works when incrementally editing existing paths. -#define QT_DEPRECATED_WARNINGS_SINCE QT_VERSION_CHECK(5, 14, 0) - #include "QCMakeWidgets.h" #include -#include #include #include +#include #include #include @@ -93,20 +89,20 @@ void QCMakePathEditor::chooseFile() } } -// use same QDirModel for all completers -static QDirModel* fileDirModel() +// use same QFileSystemModel for all completers +static QFileSystemModel* fileDirModel() { - static QDirModel* m = nullptr; + static QFileSystemModel* m = nullptr; if (!m) { - m = new QDirModel(); + m = new QFileSystemModel(); } return m; } -static QDirModel* pathDirModel() +static QFileSystemModel* pathDirModel() { - static QDirModel* m = nullptr; + static QFileSystemModel* m = nullptr; if (!m) { - m = new QDirModel(); + m = new QFileSystemModel(); m->setFilter(QDir::AllDirs | QDir::Drives | QDir::NoDotAndDotDot); } return m; @@ -115,8 +111,9 @@ static QDirModel* pathDirModel() QCMakeFileCompleter::QCMakeFileCompleter(QObject* o, bool dirs) : QCompleter(o) { - QDirModel* m = dirs ? pathDirModel() : fileDirModel(); + QFileSystemModel* m = dirs ? pathDirModel() : fileDirModel(); this->setModel(m); + m->setRootPath(QString()); } QString QCMakeFileCompleter::pathFromIndex(const QModelIndex& idx) const -- cgit v0.12 From b3ee09290bcc6f660aeafbe3490a6016867ef2ae Mon Sep 17 00:00:00 2001 From: Sankhesh Jhaveri Date: Wed, 23 Dec 2020 10:28:15 -0500 Subject: cmake-gui: Conditionally switch between QDirModel and QFileSystemModel Uses QT_VERSION_CHECK to determine Qt version. The code switches to QFileSystemModel for Qt versions >= 6 --- Source/QtDialog/QCMakeWidgets.cxx | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Source/QtDialog/QCMakeWidgets.cxx b/Source/QtDialog/QCMakeWidgets.cxx index 45fd425..ca65d13 100644 --- a/Source/QtDialog/QCMakeWidgets.cxx +++ b/Source/QtDialog/QCMakeWidgets.cxx @@ -1,16 +1,23 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ +#define QT_DEPRECATED_WARNINGS_SINCE QT_VERSION_CHECK(5, 14, 0) + #include "QCMakeWidgets.h" #include #include #include -#include #include #include +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +# include +#else +# include +#endif + QCMakeFileEditor::QCMakeFileEditor(QWidget* p, QString var) : QLineEdit(p) , Variable(std::move(var)) @@ -89,8 +96,10 @@ void QCMakePathEditor::chooseFile() } } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) // use same QFileSystemModel for all completers static QFileSystemModel* fileDirModel() + { static QFileSystemModel* m = nullptr; if (!m) { @@ -107,13 +116,39 @@ static QFileSystemModel* pathDirModel() } return m; } +#else +// use same QDirModel for all completers +static QDirModel* fileDirModel() + +{ + static QDirModel* m = nullptr; + if (!m) { + m = new QDirModel(); + } + return m; +} +static QDirModel* pathDirModel() +{ + static QDirModel* m = nullptr; + if (!m) { + m = new QDirModel(); + m->setFilter(QDir::AllDirs | QDir::Drives | QDir::NoDotAndDotDot); + } + return m; +} +#endif QCMakeFileCompleter::QCMakeFileCompleter(QObject* o, bool dirs) : QCompleter(o) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) QFileSystemModel* m = dirs ? pathDirModel() : fileDirModel(); this->setModel(m); m->setRootPath(QString()); +#else + QDirModel* m = dirs ? pathDirModel() : fileDirModel(); + this->setModel(m); +#endif } QString QCMakeFileCompleter::pathFromIndex(const QModelIndex& idx) const -- cgit v0.12 From 2e4cbaa521ee36b05422469e6569cd85943d79fd Mon Sep 17 00:00:00 2001 From: Sankhesh Jhaveri Date: Mon, 28 Dec 2020 14:38:13 -0500 Subject: cmake-gui: Add a Qt version control variable --- Source/QtDialog/CMakeLists.txt | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index ce55f51..1d3c66e 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -8,15 +8,27 @@ set (QT_COMPONENTS Widgets Gui ) -# Look for Qt6 first -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.") + +set(CMake_QT_MAJOR_VERSION "A" CACHE + STRING "Expected Qt major version. Valid values are A (auto-select), 5, 6.") +set(SUPPORTED_QT_VERSIONS "A" 5 6) +set_property(CACHE CMake_QT_MAJOR_VERSION PROPERTY STRINGS ${SUPPORTED_QT_VERSIONS}) +if(NOT CMake_QT_MAJOR_VERSION VERSION_EQUAL "A") + if(NOT CMake_QT_MAJOR_VERSION IN_LIST SUPPORTED_QT_VERSIONS) + message(FATAL_ERROR "Supported Qt versions are \"${SUPPORTED_QT_VERSIONS}\"." + " But CMake_QT_MAJOR_VERSION is set to ${CMake_QT_MAJOR_VERSION}.") + endif() + set(INSTALLED_QT_VERSION ${CMake_QT_MAJOR_VERSION}) +else() + 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() - set(INSTALLED_QT_VERSION 5) endif() find_package(Qt${INSTALLED_QT_VERSION} -- cgit v0.12