From fb5693375c82b2c35561bdfb55731e5f192e66cf Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 8 May 2022 08:36:39 +0300
Subject: [PATCH 21/23] Meson: Add Qt6-mode support

Default to it already.

See osdn #43364

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 doc/INSTALL.meson                         |  3 ++
 gen_headers/meson_fc_config.h.in          |  2 +-
 meson.build                               | 50 ++++++++++++++++-------
 meson_options.txt                         |  6 +++
 windows/installer_cross/meson-winbuild.sh |  7 +++-
 5 files changed, 51 insertions(+), 17 deletions(-)

diff --git a/doc/INSTALL.meson b/doc/INSTALL.meson
index 1c9c6631fc..1d1b4ce001 100644
--- a/doc/INSTALL.meson
+++ b/doc/INSTALL.meson
@@ -135,6 +135,9 @@ gitrev (boolean):
 freeciv-web (boolean):
   Build freeciv-web version instead of normal one.
 
+qtver ('qt5'/'qt6'):
+  Whether to build Qt5 or Qt6 versions of the binaries.
+
 
 run.sh
 ------
diff --git a/gen_headers/meson_fc_config.h.in b/gen_headers/meson_fc_config.h.in
index c8352c0fd4..e4e5753e5f 100644
--- a/gen_headers/meson_fc_config.h.in
+++ b/gen_headers/meson_fc_config.h.in
@@ -49,7 +49,7 @@
 #define HAVE_FCDB_SQLITE3 1
 
 /* Build in Qt5 mode */
-#define FC_QT5_MODE
+#mesondefine FC_QT5_MODE
 
 /* Release cycle information */
 #mesondefine IS_DEVEL_VERSION
diff --git a/meson.build b/meson.build
index 51e678de7c..160557cda3 100644
--- a/meson.build
+++ b/meson.build
@@ -398,6 +398,10 @@ if get_option('audio') or get_option('clients').contains('sdl2')
   endif
 endif
 
+if get_option('qtver') == 'qt5'
+  priv_conf_data.set('FC_QT5_MODE', 1)
+endif
+
 if get_option('audio')
   priv_conf_data.set('AUDIO_SDL', 1)
 
@@ -2495,17 +2499,27 @@ install_data('data/themes/gtk3.22/Freeciv/gtk-3.0/gtk.css',
 
 endif
 
-qt5_mod = import('qt5')
+if get_option('qtver') == 'qt6'
+  qt_mod = import('qt6')
+
+  qt_dep = dependency('Qt6', modules: ['Core', 'Gui', 'Widgets'], required: false)
+else
+  qt_mod = import('qt5')
 
-qt5_dep = dependency('Qt5', modules: ['Core', 'Gui', 'Widgets'], required: false)
+  qt_dep = dependency('Qt5', modules: ['Core', 'Gui', 'Widgets'], required: false)
+endif
 
 if get_option('clients').contains('qt')
 
-if not qt5_dep.found()
-  error('Qt5 >= 5.11 required for qt-client, but not found')
+if not qt_dep.found()
+  if get_option('qtver') == 'qt6'
+    error('Qt6 >= 6.0 required for qt-client in Qt6 mode, but not found')
+  else
+    error('Qt5 >= 5.11 required for qt-client in Qt5 mode, but not found')
+  endif
 endif
 
-mocced_client = qt5_mod.preprocess(
+mocced_client = qt_mod.preprocess(
   moc_headers: [
    'client/gui-qt/fc_client.h',
    'client/gui-qt/ratesdlg.h',
@@ -2571,7 +2585,7 @@ executable('freeciv-qt',
   'client/gui_interface.c',
   mocced_client, clienticon,
   include_directories: [client_inc, include_directories('client/gui-qt')],
-  dependencies: [qt5_dep, net_dep, gettext_dep],
+  dependencies: [qt_dep, net_dep, gettext_dep],
   link_with: client_common,
   install: true)
 
@@ -2893,11 +2907,15 @@ endif
 
 if get_option('fcmp').contains('qt')
 
-if not qt5_dep.found()
-  error('Qt5 >= 5.11 required for qt-modpack-installer, but not found')
+if not qt_dep.found()
+  if get_option('qtver') == 'qt6'
+    error('Qt6 >= 6.0 required for qt-modpack-installer in Qt6 mode, but not found')
+  else
+    error('Qt5 >= 5.11 required for qt-modpack-installer in Qt5 mode, but not found')
+  endif
 endif
 
-mocced_fcmp = qt5_mod.preprocess(
+mocced_fcmp = qt_mod.preprocess(
   moc_headers: [
    'tools/fcmp/mpgui_qt.h',
    'tools/fcmp/mpgui_qt_worker.h']
@@ -2908,7 +2926,7 @@ executable('freeciv-mp-qt',
   'tools/fcmp/mpgui_qt_worker.cpp',
   mocced_fcmp, mpicon,
   include_directories: tool_inc,
-  dependencies: [qt5_dep, sqlite3_dep, gettext_dep],
+  dependencies: [qt_dep, sqlite3_dep, gettext_dep],
   link_with: [common_lib, fcmp_common],
   install: true
   )
@@ -2946,11 +2964,15 @@ executable('freeciv-ruleup',
 
 if get_option('ruledit')
 
-if not qt5_dep.found()
-  error('Qt5 >= 5.11 required for ruledit, but not found')
+if not qt_dep.found()
+  if get_option('qtver') == 'qt6'
+    error('Qt6 >= 6.0 required for ruledit in Qt6 mode, but not found')
+  else
+    error('Qt5 >= 5.11 required for ruledit in Qt5 mode, but not found')
+  endif
 endif
 
-mocced_ruledit = qt5_mod.preprocess(
+mocced_ruledit = qt_mod.preprocess(
   moc_headers: [
    'tools/ruledit/conversion_log.h',
    'tools/ruledit/edit_impr.h',
@@ -2998,7 +3020,7 @@ executable('freeciv-ruledit',
   'tools/ruledit/validity.c',
   mocced_ruledit, rulediticon,
   include_directories: tool_inc,
-  dependencies: [qt5_dep, m_dep, net_dep, readline_dep, gettext_dep],
+  dependencies: [qt_dep, m_dep, net_dep, readline_dep, gettext_dep],
   link_with: [common_lib, server_lib, ais, tool_lib],
   install: true
   )
diff --git a/meson_options.txt b/meson_options.txt
index 204e86ce9e..34a7c523c9 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -54,3 +54,9 @@ option('freeciv-web',
        type: 'boolean',
        value: false,
        description: 'Make a freeciv-web server build instead of normal one')
+
+option('qtver',
+       type: 'combo',
+       choices: ['qt5', 'qt6'],
+       value: 'qt6',
+       description: 'Whether to build Qt5 or Qt6 versions of the binaries')
diff --git a/windows/installer_cross/meson-winbuild.sh b/windows/installer_cross/meson-winbuild.sh
index b8285fa8a6..b3752958d8 100755
--- a/windows/installer_cross/meson-winbuild.sh
+++ b/windows/installer_cross/meson-winbuild.sh
@@ -63,6 +63,8 @@ fi
 
 SETUP=$(grep "CrosserSetup=" $DLLSPATH/crosser.txt | sed -e 's/CrosserSetup="//' -e 's/"//')
 
+QTPARAMS=""
+
 case $GUI in
   gtk3.22) FCMP="gtk3"
            RULEDIT=false ;;
@@ -71,7 +73,8 @@ case $GUI in
   qt5) CLIENT="qt"
        FCMP="qt"
        NLS="-Dnls=false"
-       RULEDIT=true ;;
+       RULEDIT=true
+       QTPARAMS="-Dqtver=qt5" ;;
 esac
 
 if test "x$CLIENT" = "x" ; then
@@ -113,7 +116,7 @@ cd meson-build-${SETUP}-${GUI}
 export PKG_CONFIG_PATH=${DLLSPATH}/lib/pkgconfig
 
 if ! meson --cross-file=cross.txt -Dprefix=$MESON_INSTALL_DIR -Dclients=$CLIENT -Dfcmp=$FCMP \
-           ${NLS} -Dsyslua=false -Druledit=$RULEDIT \
+           ${NLS} -Dsyslua=false -Druledit=$RULEDIT $QTPARAMS \
            ../../.. $EXTRA_CONFIG ; then
   echo "Meson run failed!" >&2
   exit 1
-- 
2.35.1