https://github.com/qgis/QGIS/commit/a20c909c1b2bd0dfcae281fb6e55226d3d3dc423

relax flex requirement as QGIS builds and runs fine with our flex.

revert https://github.com/qgis/QGIS/commit/fd20e69dae49765b7f5419d7a3f934ebfa792168

last chunk: fix build with qt 6.10, from https://github.com/qgis/QGIS/pull/64056

Index: CMakeLists.txt
--- CMakeLists.txt.orig
+++ CMakeLists.txt
@@ -417,7 +417,7 @@ if(WITH_CORE)
     set (USING_NINJA TRUE)
   endif()
 
-  find_package(FLEX 2.6 REQUIRED)
+  find_package(FLEX 2.5.39 REQUIRED)
   find_package(BISON 2.4 REQUIRED)
 
   #############################################################
@@ -456,9 +456,6 @@ if(WITH_CORE)
     set(SPATIALINDEX_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/external/spatialindex/include)
   else()
     find_package(Spatialindex REQUIRED)
-    if(SPATIALINDEX_VERSION VERSION_GREATER_EQUAL "2.1")
-      message(FATAL_ERROR "Cannot build QGIS using libspatialindex >= 2.1, see https://github.com/libspatialindex/libspatialindex/issues/276")
-    endif()
   endif()
   find_package(LibZip REQUIRED)
   set (WITH_INTERNAL_NLOHMANN_JSON ${PREFER_INTERNAL_LIBS} CACHE BOOL "Determines whether the vendored copy of nlohmann-json should be used")
@@ -596,7 +593,7 @@ if(WITH_CORE)
 
   find_package(${QT_VERSION_BASE} COMPONENTS Core Gui Widgets Network Xml Svg Concurrent Test Sql Positioning REQUIRED)
   if (BUILD_WITH_QT6)
-    find_package(${QT_VERSION_BASE} COMPONENTS Core5Compat REQUIRED)
+    find_package(${QT_VERSION_BASE} COMPONENTS Core5Compat SqlPrivate REQUIRED)
   endif()
 
   if (NOT IOS)
