<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From 66740900522f42564a2b0bd4e8a435ed24a61725 Mon Sep 17 00:00:00 2001
From: James Le Cuirot &lt;chewi@gentoo.org&gt;
Date: Sun, 12 May 2024 17:26:14 +0100
Subject: [PATCH] Unify asset building and use find_program to find NPM (#2522)

---
 cmake/targets/common.cmake  | 33 +++++++++++++++++++++------------
 cmake/targets/unix.cmake    |  6 ------
 cmake/targets/windows.cmake |  6 ------
 3 files changed, 21 insertions(+), 24 deletions(-)

diff --git a/cmake/targets/common.cmake b/cmake/targets/common.cmake
index ee79528c..941ef0b7 100644
--- a/cmake/targets/common.cmake
+++ b/cmake/targets/common.cmake
@@ -3,18 +3,6 @@
 
 add_executable(sunshine ${SUNSHINE_TARGET_FILES})
 
-# Homebrew build fails the vite build if we set these environment variables
-# this block must be before the platform specific code
-if(${SUNSHINE_BUILD_HOMEBREW})
-    set(NPM_SOURCE_ASSETS_DIR "")
-    set(NPM_ASSETS_DIR "")
-    set(NPM_BUILD_HOMEBREW "true")
-else()
-    set(NPM_SOURCE_ASSETS_DIR ${SUNSHINE_SOURCE_ASSETS_DIR})
-    set(NPM_ASSETS_DIR ${CMAKE_BINARY_DIR})
-    set(NPM_BUILD_HOMEBREW "")
-endif()
-
 # platform specific target definitions
 if(WIN32)
     include(${CMAKE_MODULE_PATH}/targets/windows.cmake)
@@ -49,6 +37,27 @@ endif()
 
 target_compile_options(sunshine PRIVATE $&lt;$&lt;COMPILE_LANGUAGE:CXX&gt;:${SUNSHINE_COMPILE_OPTIONS}&gt;;$&lt;$&lt;COMPILE_LANGUAGE:CUDA&gt;:${SUNSHINE_COMPILE_OPTIONS_CUDA};-std=c++17&gt;)  # cmake-lint: disable=C0301
 
+# Homebrew build fails the vite build if we set these environment variables
+if(${SUNSHINE_BUILD_HOMEBREW})
+    set(NPM_SOURCE_ASSETS_DIR "")
+    set(NPM_ASSETS_DIR "")
+    set(NPM_BUILD_HOMEBREW "true")
+else()
+    set(NPM_SOURCE_ASSETS_DIR ${SUNSHINE_SOURCE_ASSETS_DIR})
+    set(NPM_ASSETS_DIR ${CMAKE_BINARY_DIR})
+    set(NPM_BUILD_HOMEBREW "")
+endif()
+
+#WebUI build
+find_program(NPM npm REQUIRED)
+add_custom_target(web-ui ALL
+        WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+        COMMENT "Installing NPM Dependencies and Building the Web UI"
+        COMMAND "$&lt;$&lt;BOOL:${WIN32}&gt;:cmd;/C&gt;" "${NPM}" install
+        COMMAND "${CMAKE_COMMAND}" -E env "SUNSHINE_BUILD_HOMEBREW=${NPM_BUILD_HOMEBREW}" "SUNSHINE_SOURCE_ASSETS_DIR=${NPM_SOURCE_ASSETS_DIR}" "SUNSHINE_ASSETS_DIR=${NPM_ASSETS_DIR}" "$&lt;$&lt;BOOL:${WIN32}&gt;:cmd;/C&gt;" "${NPM}" run build  # cmake-lint: disable=C0301
+        COMMAND_EXPAND_LISTS
+        VERBATIM)
+
 # tests
 if(BUILD_TESTS)
     add_subdirectory(tests)
diff --git a/cmake/targets/unix.cmake b/cmake/targets/unix.cmake
index 5527a987..047a0b3d 100644
--- a/cmake/targets/unix.cmake
+++ b/cmake/targets/unix.cmake
@@ -1,8 +1,2 @@
 # unix specific target definitions
 # put anything here that applies to both linux and macos
-
-#WebUI build
-add_custom_target(web-ui ALL
-        WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
-        COMMENT "Installing NPM Dependencies and Building the Web UI"
-        COMMAND sh -c \"npm install &amp;&amp; SUNSHINE_BUILD_HOMEBREW=${NPM_BUILD_HOMEBREW} SUNSHINE_SOURCE_ASSETS_DIR=${NPM_SOURCE_ASSETS_DIR} SUNSHINE_ASSETS_DIR=${NPM_ASSETS_DIR} npm run build\")  # cmake-lint: disable=C0301
diff --git a/cmake/targets/windows.cmake b/cmake/targets/windows.cmake
index e429feaa..341d7c2e 100644
--- a/cmake/targets/windows.cmake
+++ b/cmake/targets/windows.cmake
@@ -4,9 +4,3 @@ set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll")
 find_library(ZLIB ZLIB1)
 list(APPEND SUNSHINE_EXTERNAL_LIBRARIES
         Wtsapi32.lib)
-
-#WebUI build
-add_custom_target(web-ui ALL
-        WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
-        COMMENT "Installing NPM Dependencies and Building the Web UI"
-        COMMAND cmd /C "npm install &amp;&amp; set \"SUNSHINE_SOURCE_ASSETS_DIR=${NPM_SOURCE_ASSETS_DIR}\" &amp;&amp; set \"SUNSHINE_ASSETS_DIR=${NPM_ASSETS_DIR}\" &amp;&amp; npm run build")   # cmake-lint: disable=C0301
-- 
2.44.0

</pre></body></html>