From 22478ed14549c1b7ecb973993ecde8a53d8f3d1d Mon Sep 17 00:00:00 2001
From: Leon Styhre <leon@leonstyhre.com>
Date: Fri, 9 Aug 2024 17:24:08 +0200
Subject: [PATCH] (Windows) Added the ICU library as a dependency

---
 CMakeLists.txt                       |  4 ++++
 es-app/CMakeLists.txt                |  3 +++
 tools/Windows_dependencies_build.bat | 32 +++++++++++++++++++++++-----
 tools/Windows_dependencies_setup.bat | 27 ++++++++++++++++++++---
 4 files changed, 58 insertions(+), 8 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3371110d1..f342f468b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -488,6 +488,7 @@ elseif(WIN32)
                             ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype/include
                             ${CMAKE_CURRENT_SOURCE_DIR}/external/gettext/include
                             ${CMAKE_CURRENT_SOURCE_DIR}/external/harfbuzz/src
+                            ${CMAKE_CURRENT_SOURCE_DIR}/external/icu/icu4c/source/common
                             ${CMAKE_CURRENT_SOURCE_DIR}/external/libgit2/include
                             ${CMAKE_CURRENT_SOURCE_DIR}/external/pugixml/src
                             ${CMAKE_CURRENT_SOURCE_DIR}/external/SDL2)
@@ -572,6 +573,9 @@ elseif(WIN32)
                             ${PROJECT_SOURCE_DIR}/git2.lib
                             ${PROJECT_SOURCE_DIR}/glew32.lib
                             ${PROJECT_SOURCE_DIR}/harfbuzz.lib
+                            ${PROJECT_SOURCE_DIR}/icudt.lib
+                            ${PROJECT_SOURCE_DIR}/icuin.lib
+                            ${PROJECT_SOURCE_DIR}/icuuc.lib
                             ${PROJECT_SOURCE_DIR}/libcurl-x64.lib
                             ${PROJECT_SOURCE_DIR}/libintl-8.lib
                             ${PROJECT_SOURCE_DIR}/freetype.lib
diff --git a/es-app/CMakeLists.txt b/es-app/CMakeLists.txt
index 5f42c9b25..b70e70419 100644
--- a/es-app/CMakeLists.txt
+++ b/es-app/CMakeLists.txt
@@ -162,6 +162,9 @@ if(WIN32)
                   ../git2.dll
                   ../glew32.dll
                   ../harfbuzz.dll
+                  ../icudt75.dll
+                  ../icuin75.dll
+                  ../icuuc75.dll
                   ../libcrypto-3-x64.dll
                   ../libcurl-x64.dll
                   ../libiconv-2.dll
diff --git a/tools/Windows_dependencies_build.bat b/tools/Windows_dependencies_build.bat
index 0fc3f2c18..7f6a55c0d 100644
--- a/tools/Windows_dependencies_build.bat
+++ b/tools/Windows_dependencies_build.bat
@@ -4,7 +4,7 @@
 ::  Windows_dependencies_build.bat
 ::
 ::  Builds the external dependencies in-tree using MSVC.
-::  The Windows_dependencies_setup_MSVC.bat script must have been executed prior to this.
+::  The Windows_dependencies_setup.bat script must have been executed prior to this.
 ::  All libraries will be recompiled from scratch every time.
 ::
 ::  This script needs to run from the root of the repository.
@@ -17,15 +17,35 @@ if not exist .clang-format (
 )
 
 if not exist external\pugixml\ (
-  echo You need to first run tools\Windows_dependencies_setup_MSVC.bat to download and configure the dependencies.
+  echo You need to first run tools\Windows_dependencies_setup.bat to download and configure the dependencies.
   goto end
 )
 
-echo Building all dependencies in the .\external directory...
-echo:
-
 cd external
 
+echo Building all dependencies in the .\external directory...
+
+echo:
+echo Building ICU
+
+if not exist icu/icu4c\ (
+  echo icu/icu4c directory is missing, aborting.
+  cd ..
+  goto end
+)
+
+cd icu/icu4c
+msbuild source\allinone\allinone.sln /p:Configuration=Release /p:Platform=x64 /p:SkipUWP=true
+
+copy /Y bin64\icudt75.dll ..\..\..\
+copy /Y bin64\icuin75.dll ..\..\..\
+copy /Y bin64\icuuc75.dll ..\..\..\
+copy /Y lib64\icudt.lib ..\..\..\
+copy /Y lib64\icuin.lib ..\..\..\
+copy /Y lib64\icuuc.lib ..\..\..\
+cd ..\..
+
+echo:
 echo Building HarfBuzz
 
 if not exist harfbuzz\build\ (
@@ -46,6 +66,7 @@ copy /Y harfbuzz.dll ..\..\..\
 copy /Y harfbuzz.lib ..\..\..\
 cd ..\..
 
+echo:
 echo Building FreeType
 
 if not exist freetype\build\ (
@@ -66,6 +87,7 @@ copy /Y freetype.dll ..\..\..\
 copy /Y freetype.lib ..\..\..\
 cd ..\..
 
+echo:
 echo Building libgit2
 
 if not exist libgit2\build\ (
diff --git a/tools/Windows_dependencies_setup.bat b/tools/Windows_dependencies_setup.bat
index 017e8e5c9..87da89bb2 100644
--- a/tools/Windows_dependencies_setup.bat
+++ b/tools/Windows_dependencies_setup.bat
@@ -28,11 +28,11 @@ if %ERRORLEVEL% neq 0 (
   goto end
 )
 
-echo Setting up dependencies in the .\external directory...
-echo:
-
 cd external
 
+echo Setting up dependencies in the .\external directory...
+
+echo:
 echo Setting up gettext
 
 if exist gettext\ (
@@ -68,6 +68,27 @@ copy /Y libintl-8.lib ..\..\..
 copy /Y libiconv-2.dll ..\..\..
 cd ..\..
 
+echo:
+echo Setting up ICU
+
+if exist icu\ (
+  rmdir /S /Q icu
+)
+
+git clone -n --filter=tree:0 https://github.com/unicode-org/icu.git
+
+if not exist icu\ (
+  echo icu directory is missing, aborting.
+  cd ..
+  goto end
+)
+
+cd icu
+git sparse-checkout set --no-cone icu4c
+git checkout release-75-1
+cd ..
+
+echo:
 echo Setting up curl
 
 if exist curl-8.2.1_11-win64-mingw\ (