From 92be4fa7dceba0017a7605fdd4a118c51098ead4 Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Fri, 27 Oct 2023 18:39:31 -0400
Subject: [PATCH] build: windows: optionally use pywinmake

Change-Id: Ib0b41428f00945c9bcab2f7d68355c2128c0e68f
---
 CMakeLists.txt                               |  3 +--
 build.py                                     | 17 +++++++++++++----
 daemon                                       |  2 +-
 extras/build/cmake/modules/FindLibJami.cmake |  4 ++++
 extras/scripts/build-windows.py              |  5 ++---
 5 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 02b372fb6..dd255a220 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -376,7 +376,6 @@ if(MSVC)
 
   # daemon
   set(JAMID_SRC_PATH ${DAEMON_DIR}/contrib/msvc/include)
-  set(JAMID_LIB ${DAEMON_DIR}/build/x64/ReleaseLib_win32/bin/libjami.lib)
   set(GNUTLS_LIB ${DAEMON_DIR}/contrib/msvc/lib/x64/libgnutls.lib)
 
   # Beta config
@@ -572,7 +571,7 @@ if(MSVC)
     WIN32_EXECUTABLE TRUE)
 
   list(APPEND CLIENT_LIBS
-    ${JAMID_LIB}
+    ${LIBJAMI_LIB}
     ${GNUTLS_LIB}
     ${LIBCLIENT_NAME}
     ${QT_LIBS}
diff --git a/build.py b/build.py
index 708be85e8..1942af217 100755
--- a/build.py
+++ b/build.py
@@ -363,10 +363,16 @@ def cwd(path):
 def run_install(args):
     # Platforms with special compilation scripts
     if args.distribution == WIN32_DISTRIBUTION_NAME:
-        with cwd('daemon/compat/msvc'):
-            execute_script(
-                ['python winmake.py -iv '
-                 f'-s {args.sdk} -b daemon'])
+        if args.pywinmake:
+            with cwd('daemon'):
+                execute_script(['git submodule update --init'])
+                execute_script(['python -m pip install extras/scripts/pywinmake'])
+                execute_script(['python extras/scripts/winmake.py'])
+                execute_script(['python extras/scripts/winmake.py --base-dir compat/msvc'])
+        else:
+            with cwd('daemon/compat/msvc'):
+                execute_script([f'python winmake.py -iv -s {args.sdk} -b daemon'])
+
         build_windows = 'extras/scripts/build-windows.py'
         execute_script([f'python {build_windows} --init'])
         execute_script([f'python {build_windows} --qt={args.qt}'])
@@ -730,6 +736,9 @@ def parse_args():
     ap.add_argument('--clean-contribs', nargs='+',
                     help='Clean the specified contribs (space separated) or \
                           "all" to clean all contribs before building.')
+    ap.add_argument('--pywinmake', dest='pywinmake',
+                    default=False, action='store_true',
+                    help='Build Jami for Windows using pywinmake')
 
     dist = choose_distribution()
 
diff --git a/daemon b/daemon
index a5a46c038..eab986321 160000
--- a/daemon
+++ b/daemon
@@ -1 +1 @@
-Subproject commit a5a46c0385a224f27456c9b0d271cede9622ea72
+Subproject commit eab986321590a5812fea67d3a2baacd95e26173c
diff --git a/extras/build/cmake/modules/FindLibJami.cmake b/extras/build/cmake/modules/FindLibJami.cmake
index 4490d3ae3..355af0717 100644
--- a/extras/build/cmake/modules/FindLibJami.cmake
+++ b/extras/build/cmake/modules/FindLibJami.cmake
@@ -65,6 +65,7 @@ if(WITH_DAEMON_SUBMODULE)
     PATHS ${CMAKE_INSTALL_PREFIX}/daemon/lib
     PATHS ${CMAKE_INSTALL_PREFIX}/libexec
     PATHS ${CMAKE_INSTALL_PREFIX}/bin
+    PATHS ${CMAKE_INSTALL_PREFIX}/daemon/build/bin
     NO_DEFAULT_PATH)
 else()
   # Search only in these given PATHS.
@@ -75,6 +76,7 @@ else()
     PATHS ${CMAKE_INSTALL_PREFIX}/daemon/lib
     PATHS ${CMAKE_INSTALL_PREFIX}/libexec
     PATHS ${CMAKE_INSTALL_PREFIX}/bin
+    PATHS ${CMAKE_INSTALL_PREFIX}/daemon/build/bin
     NO_DEFAULT_PATH)
 
   # Search elsewhere as well (e.g. system-wide).
@@ -94,6 +96,7 @@ if(NOT LIBJAMI_LIB)
       PATHS ${CMAKE_INSTALL_PREFIX}/lib
       PATHS ${CMAKE_INSTALL_PREFIX}/daemon/lib
       PATHS ${CMAKE_INSTALL_PREFIX}/libexec
+      PATHS ${CMAKE_INSTALL_PREFIX}/daemon/build/lib
       NO_DEFAULT_PATH)
   else()
     # Search only in these given PATHS.
@@ -104,6 +107,7 @@ if(NOT LIBJAMI_LIB)
       PATHS ${CMAKE_INSTALL_PREFIX}/lib
       PATHS ${CMAKE_INSTALL_PREFIX}/daemon/lib
       PATHS ${CMAKE_INSTALL_PREFIX}/libexec
+      PATHS ${CMAKE_INSTALL_PREFIX}/daemon/build/lib
       NO_DEFAULT_PATH)
 
     # Search elsewhere as well (e.g. system-wide).
diff --git a/extras/scripts/build-windows.py b/extras/scripts/build-windows.py
index 40e1caf82..818ab2eab 100644
--- a/extras/scripts/build-windows.py
+++ b/extras/scripts/build-windows.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python3
-
+# -*- coding: utf-8 -*-
 """
 Build, test, and package the project.
 
@@ -264,8 +264,7 @@ def build(config_str, qt_dir, tests):
 
     # Get the daemon bin/include directories.
     daemon_dir = os.path.join(repo_root_dir, "daemon")
-    daemon_bin_dir = os.path.join(
-        daemon_dir, "build", "x64", "ReleaseLib_win32", "bin")
+    daemon_bin_dir = os.path.join(daemon_dir, "build", "lib")
 
     # We need to update the minimum SDK version to be able to
     # build with system theme support
-- 
GitLab