Get CMake to successfully work with Qt6

Of course it still fails in the compile phase, but only for some
of the ui/qt/ files.

Wireshark with Qt5 still compiles and runs.

To do the build invoke cmake with the following settings added:
export CMAKE_PREFIX_PATH=:${MY_QT6_PREFIX}/lib/cmake
cmake -DUSE_qt6=ON ...

Independently of this patch there is lots of Qt-stuff in
CMakeLists.txt that needs review/cleanup:
- Some of the stuff can probably be solved in a less hacky way:
  + There seemed to be a way for QT6 to provide the required c++-standard,
    but in the end I could not find it.
  + Once we have a working Qt6 codebase, we may get rid of the USE_qt6
    flag and just test for Qt6Core first and if not present check for
    Qt5Core.
- All comments that match /qt ?[4-6]/i need reviewing/cleaning up.
- The changes in this patch have been tested to work on all machines
  that are my mac (macos 12.0.1, XCode 13.1, Intel, GPL-Qt6.2.1 with only
  the macos package selected, cmake 3.21.4)

Add ui/qt/qt6-migration-links.txt for some possibly helpful links
This commit is contained in:
Joerg Mayer 2021-11-18 01:29:59 +01:00 committed by Jörg Mayer
parent 35ad2e85c8
commit 24a364f762
4 changed files with 63 additions and 17 deletions

View File

@ -1226,6 +1226,11 @@ ws_find_package(Systemd BUILD_sdjournal HAVE_SYSTEMD)
# Build the Qt GUI?
if(BUILD_wireshark)
if(USE_qt6)
set(qtver "6")
else()
set(qtver "5")
endif()
# Untested, may not work if CMAKE_PREFIX_PATH gets overwritten
# somewhere. The if WIN32 in this place is annoying as well.
if(WIN32)
@ -1243,17 +1248,29 @@ if(BUILD_wireshark)
list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /usr/local/opt/qt5)
endif()
set(QT_PACKAGELIST
Qt5Core
Qt5LinguistTools
Qt5Multimedia
Qt5PrintSupport
Qt5Widgets
Qt${qtver}Core
Qt${qtver}Gui
Qt${qtver}LinguistTools
Qt${qtver}Multimedia
Qt${qtver}PrintSupport
Qt${qtver}Widgets
)
if(APPLE)
ws_find_package(Sparkle ENABLE_SPARKLE HAVE_SOFTWARE_UPDATE)
endif()
if(WIN32)
list(APPEND QT_PACKAGELIST Qt5WinExtras)
if(USE_qt6)
set(CMAKE_CXX_STANDARD 17)
# Setting CMAKE_CXX_STANDARD is not sufficient with MSVC, see
# https://gitlab.kitware.com/cmake/cmake/-/issues/18837
# The below snippet can be found in Qt6, lib/cmake/Qt6/QtFeature.cmake
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1913)
list(APPEND CMAKE_REQUIRED_FLAGS "-Zc:__cplusplus")
endif()
list(APPEND QT_PACKAGELIST Qt6Core5Compat)
if(APPLE)
set(MIN_MACOS_VERSION 10.14)
endif()
else()
if(WIN32)
list(APPEND QT_PACKAGELIST Qt5WinExtras)
endif()
endif()
foreach(_qt_package IN LISTS QT_PACKAGELIST)
find_package(${_qt_package} REQUIRED ${QT_FIND_PACKAGE_OPTIONS})
@ -1271,6 +1288,9 @@ if(BUILD_wireshark)
list(APPEND QT_INCLUDE_DIRS /usr/local/opt/qt5/include)
endif()
set(QT_FOUND ON)
if(APPLE)
ws_find_package(Sparkle ENABLE_SPARKLE HAVE_SOFTWARE_UPDATE)
endif()
endif()
# MaxMind DB address resolution
@ -1395,10 +1415,11 @@ if(GNUTLS_FOUND AND NOT GNUTLS_VERSION VERSION_LESS "3.4.0")
endif()
if (QT_FOUND)
if (Qt5Widgets_VERSION VERSION_LESS 5.6)
if (Qt${qtver}Widgets_VERSION VERSION_LESS 5.6)
message(FATAL_ERROR "Qt 5.6 or later is required.")
endif()
if (Qt5Widgets_VERSION VERSION_GREATER 5.6
if (Qt${qtver}Widgets_VERSION VERSION_GREATER 5.6
AND qtver MATCHES "5"
AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang"))
# Qt 5.7 and later require C++ 11.
set(CMAKE_CXX_STANDARD 11)
@ -1413,7 +1434,7 @@ if (QT_FOUND)
# to find Qt5. This means that we can't assume that the qmake
# in our PATH is the correct one. We can fetch qmake's location
# from Qt5::qmake, which is is defined in Qt5CoreConfigExtras.cmake.
get_target_property(QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
get_target_property(QT_QMAKE_EXECUTABLE Qt${qtver}::qmake IMPORTED_LOCATION)
get_filename_component(_qt_bin_path "${QT_QMAKE_EXECUTABLE}" DIRECTORY)
set(QT_BIN_PATH "${_qt_bin_path}" CACHE INTERNAL
"Path to qmake, macdeployqt, windeployqt, and other Qt utilities."
@ -1438,7 +1459,7 @@ if (QT_FOUND)
# https://doc.qt.io/qt-5.15/supported-platforms.html
# https://doc-snapshots.qt.io/qt6-dev/supported-platforms.html
# CMake < 3.7 doesn't support VERSION_GREATER_EQUAL.
if(Qt5Widgets_VERSION VERSION_GREATER "5.999.999")
if(Qt${qtver}Widgets_VERSION VERSION_GREATER "5.999.999")
set(MIN_MACOS_VERSION 10.14)
elseif(Qt5Widgets_VERSION VERSION_GREATER "5.14.999")
set(MIN_MACOS_VERSION 10.13)
@ -1452,7 +1473,7 @@ if (QT_FOUND)
set(MIN_MACOS_VERSION 10.9)
endif()
if(CMAKE_OSX_DEPLOYMENT_TARGET AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS MIN_MACOS_VERSION)
message(FATAL_ERROR "Qt version ${Qt5Widgets_VERSION} requires CMAKE_OSX_DEPLOYMENT_TARGET (${CMAKE_OSX_DEPLOYMENT_TARGET}) >= ${MIN_MACOS_VERSION}")
message(FATAL_ERROR "Qt version ${Qt${qtver}Widgets_VERSION} requires CMAKE_OSX_DEPLOYMENT_TARGET (${CMAKE_OSX_DEPLOYMENT_TARGET}) >= ${MIN_MACOS_VERSION}")
endif()
endif()

View File

@ -1,6 +1,9 @@
# Build options for use by CMake
option(BUILD_wireshark "Build Wireshark" ON)
if(BUILD_wireshark)
option(USE_qt6 "Use Qt6 instead of Qt5 - WIP, GUI developers only!" OFF)
endif()
option(BUILD_tshark "Build tshark" ON)
option(BUILD_tfshark "Build tfshark" OFF)
option(BUILD_rawshark "Build rawshark" ON)

View File

@ -7,6 +7,12 @@
# SPDX-License-Identifier: GPL-2.0-or-later
#
if(USE_qt6)
set(qtver "6")
else()
set(qtver "5")
endif()
ADD_CUSTOM_CMAKE_INCLUDE()
set(WIRESHARK_WIDGET_HEADERS
@ -633,7 +639,7 @@ set(WIRESHARK_QT_QRC
${CMAKE_CURRENT_BINARY_DIR}/i18n.qrc
)
if(NOT Qt5Widgets_VERSION VERSION_LESS "5.9")
if(NOT Qt${qtver}Widgets_VERSION VERSION_LESS "5.9")
# Drop the file modification time of source files from generated files
# to help with reproducible builds. We do not use QFileInfo.lastModified
# so this has no unwanted side effects. This mtime started appearing in
@ -642,7 +648,11 @@ if(NOT Qt5Widgets_VERSION VERSION_LESS "5.9")
set(CMAKE_AUTORCC_OPTIONS --format-version 1)
endif()
QT5_ADD_TRANSLATION(WIRESHARK_QT_QM ${WIRESHARK_QT_TS})
if (USE_qt6)
QT6_ADD_TRANSLATION(WIRESHARK_QT_QM ${WIRESHARK_QT_TS})
else()
QT5_ADD_TRANSLATION(WIRESHARK_QT_QM ${WIRESHARK_QT_TS})
endif()
add_custom_target(
translations

View File

@ -0,0 +1,12 @@
https://doc.qt.io/qt-5/qtmac-obsolete.html
https://doc.qt.io/qt-6/extras-changes-qt6.html
https://doc.qt.io/qt-6/modulechanges.html
https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html
https://www.qt.io/blog/porting-from-qt-5-to-qt-6-using-qt5compat-library
https://dangelog.wordpress.com/2012/04/07/qregularexpression/
https://doc.qt.io/qt-6/qtcore-changes-qt6.html#regular-expression-classes
https://doc.qt.io/qt-6/qtmodules.html
https://doc.qt.io/qt-6/whatsnew60.html