From 7a21173b0eda59959b12d2e878e54f0b90d68b1d Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Mon, 13 Jun 2022 12:46:28 -0400
Subject: gitlab-ci: Add job to build Windows arm64 binaries

Base it on the approach from commit 4c7c66dcf5 (gitlab-ci: Add jobs to
make Windows x86_64 and i386 packages, 2022-05-19).  Leave out the
packaging and upload steps for now because they are only for the nightly
binaries, and will need a new release of CPack to pass the `arm64`
architecture to WiX.

Issue: #21902
---
 .gitlab-ci.yml                                   | 14 ++++++++++++++
 .gitlab/artifacts.yml                            |  1 +
 .gitlab/ci/configure_windows_arm64_package.cmake | 16 ++++++++++++++++
 .gitlab/ci/download_qt.cmake                     | 10 ++++++++++
 .gitlab/ci/download_qt_hashes.cmake              |  4 ++++
 .gitlab/os-windows.yml                           | 23 +++++++++++++++++++++++
 6 files changed, 68 insertions(+)
 create mode 100644 .gitlab/ci/configure_windows_arm64_package.cmake

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5258ab3..fc05626 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1100,3 +1100,17 @@ u:windows-i386-package:
         - k:windows-i386-package
     needs:
         - k:windows-i386-package
+
+b:windows-arm64-package:
+    extends:
+        - .windows_arm64_package
+        - .cmake_build_windows
+        - .cmake_build_package_artifacts
+        - .windows_tags_nonconcurrent_vs2022_arm64
+        - .run_only_for_package
+    dependencies:
+        - p:doc-package
+    needs:
+        - p:doc-package
+    variables:
+        CMAKE_CI_ARTIFACTS_NAME: "artifacts-windows-arm64-build"
diff --git a/.gitlab/artifacts.yml b/.gitlab/artifacts.yml
index e0c8252..1b5384f 100644
--- a/.gitlab/artifacts.yml
+++ b/.gitlab/artifacts.yml
@@ -105,6 +105,7 @@
             - build/cmake-*-macos*-universal.*
             - build/cmake-*-windows-x86_64.*
             - build/cmake-*-windows-i386.*
+            - build/cmake-*-windows-arm64.*
             # Any source packages made.
             - build/cmake-*.tar.gz
             - build/cmake-*.zip
diff --git a/.gitlab/ci/configure_windows_arm64_package.cmake b/.gitlab/ci/configure_windows_arm64_package.cmake
new file mode 100644
index 0000000..f3ce853
--- /dev/null
+++ b/.gitlab/ci/configure_windows_arm64_package.cmake
@@ -0,0 +1,16 @@
+# CPack package file name component for this platform.
+set(CPACK_SYSTEM_NAME "windows-arm64" CACHE STRING "")
+
+# Tell WiX to package for this architecture.
+set(CPACK_WIX_ARCHITECTURE "arm64" CACHE STRING "")
+
+# Use APIs from at most Windows 7
+set(CMAKE_C_FLAGS "-D_WIN32_WINNT=0x0A00 -DNTDDI_VERSION=0x0A000008" CACHE STRING "")
+set(CMAKE_CXX_FLAGS "-GR -EHsc -D_WIN32_WINNT=0x0A00 -DNTDDI_VERSION=0x0A000008" CACHE STRING "")
+set(CMAKE_EXE_LINKER_FLAGS "-machine:arm64 -subsystem:console,6.02" CACHE STRING "")
+
+set(qt "$ENV{CI_PROJECT_DIR}/.gitlab/qt")
+set(qt_host "$ENV{CI_PROJECT_DIR}/.gitlab/qt-host")
+set(CMAKE_PREFIX_PATH "${qt};${qt_host}" CACHE STRING "")
+
+include("${CMAKE_CURRENT_LIST_DIR}/configure_windows_package_common.cmake")
diff --git a/.gitlab/ci/download_qt.cmake b/.gitlab/ci/download_qt.cmake
index 3dba090..b02ceb0 100644
--- a/.gitlab/ci/download_qt.cmake
+++ b/.gitlab/ci/download_qt.cmake
@@ -20,6 +20,11 @@ if ("$ENV{CMAKE_CONFIGURATION}" MATCHES "windows.*package")
   elseif ("$ENV{CMAKE_CONFIGURATION}" MATCHES "windows_i386_package")
     list(APPEND qt_files "qt-5.12.1-win-i386-msvc_v142-1.zip")
     set(qt_subdir "qt-5.12.1-win-i386-msvc_v142-1")
+  elseif ("$ENV{CMAKE_CONFIGURATION}" MATCHES "windows_arm64_package")
+    list(APPEND qt_files "qt-6.3.0-win-arm64-msvc_v143-1.zip")
+    set(qt_subdir "qt-6.3.0-win-arm64-msvc_v143-1")
+    list(APPEND qt_files "qt-6.3.0-win-x86_64-msvc_v143-1.zip")
+    set(qt_host_subdir "qt-6.3.0-win-x86_64-msvc_v143-1")
   else ()
     message(FATAL_ERROR "Unknown arch to use for Qt")
   endif()
@@ -146,3 +151,8 @@ endif ()
 file(RENAME
   ".gitlab/${qt_subdir}"
   ".gitlab/qt")
+if(qt_host_subdir)
+  file(RENAME
+    ".gitlab/${qt_host_subdir}"
+    ".gitlab/qt-host")
+endif()
diff --git a/.gitlab/ci/download_qt_hashes.cmake b/.gitlab/ci/download_qt_hashes.cmake
index d19d284..c4b0bd1 100644
--- a/.gitlab/ci/download_qt_hashes.cmake
+++ b/.gitlab/ci/download_qt_hashes.cmake
@@ -15,3 +15,7 @@ set("qt-5.15.2-macosx10.13-x86_64-arm64.tar.xz_hash" 7b9463a01c8beeee5bf8d01c70d
 
 set("qt-5.12.1-win-i386-msvc_v142-1.zip_hash" aa78711fdaa5d9b146bf7ddcf15983f9fbb3f995462f2d043f8cca74b40ddd11)
 set("qt-5.12.1-win-x86_64-msvc_v142-1.zip_hash" c2fc068b9dac40bb420e28e1ee15ce4f2ccfc866d767f3b99b6bb435b7c4f44b)
+
+set("qt-6.3.0-win-arm64-msvc_v143-1.zip_hash" 0950db703b0d305ff2855c69d8553e10036ebe5c65f95c4a850cf1f703410798)
+set("qt-6.3.0-win-i386-msvc_v143-1.zip_hash" 52d68ff3b8a045222b59ebe12878b8597e97019c2ae930e846ec816ce6df18db)
+set("qt-6.3.0-win-x86_64-msvc_v143-1.zip_hash" 3764a3076cf2331ec28bd88d6bddcab1578b1bb1329157bfe33ea02c2c63c6e1)
diff --git a/.gitlab/os-windows.yml b/.gitlab/os-windows.yml
index d55035f..b9b91fb 100644
--- a/.gitlab/os-windows.yml
+++ b/.gitlab/os-windows.yml
@@ -43,6 +43,12 @@
         VCVARSPLATFORM: "x86"
         VCVARSVERSION: "14.32.31326"
 
+.windows_vcvarsall_vs2022_x64_arm64:
+    variables:
+        VCVARSALL: "${VS170COMNTOOLS}\\..\\..\\VC\\Auxiliary\\Build\\vcvarsall.bat"
+        VCVARSPLATFORM: "x64_arm64"
+        VCVARSVERSION: "14.32.31326"
+
 .windows_vs2022_x64_ninja:
     extends:
         - .windows_build_ninja
@@ -75,6 +81,14 @@
     variables:
         CMAKE_CONFIGURATION: windows_i386_package
 
+.windows_arm64_package:
+    extends:
+        - .windows_package
+        - .windows_vcvarsall_vs2022_x64_arm64
+
+    variables:
+        CMAKE_CONFIGURATION: windows_arm64_package
+
 ### External testing
 
 .windows_vs2022_x64:
@@ -221,6 +235,15 @@
         - msvc-19.32
         - nonconcurrent
 
+.windows_tags_nonconcurrent_vs2022_arm64:
+    tags:
+        - cmake # Since this is a bare runner, pin to a project.
+        - windows
+        - shell
+        - vs2022
+        - msvc-19.32-arm64
+        - nonconcurrent
+
 .windows_tags_concurrent_vs2022:
     tags:
         - cmake # Since this is a bare runner, pin to a project.
-- 
cgit v0.12