From 8ca60f430417d0df84fbb1c8df43380271042c59 Mon Sep 17 00:00:00 2001
From: Jakob Bornecrantz <jakob@collabora.com>
Date: Sat, 22 Oct 2022 13:47:45 +0100
Subject: [PATCH] a/util: Split out sink functions into own library

---
 src/xrt/auxiliary/util/CMakeLists.txt        | 53 ++++++++++++++------
 src/xrt/drivers/CMakeLists.txt               |  1 +
 src/xrt/state_trackers/gui/CMakeLists.txt    |  1 +
 src/xrt/state_trackers/prober/CMakeLists.txt |  1 +
 src/xrt/targets/common/CMakeLists.txt        |  2 +-
 5 files changed, 41 insertions(+), 17 deletions(-)

diff --git a/src/xrt/auxiliary/util/CMakeLists.txt b/src/xrt/auxiliary/util/CMakeLists.txt
index 96c5b6b0f..d96fa6f0c 100644
--- a/src/xrt/auxiliary/util/CMakeLists.txt
+++ b/src/xrt/auxiliary/util/CMakeLists.txt
@@ -1,6 +1,10 @@
 # Copyright 2019-2022, Collabora, Ltd.
 # SPDX-License-Identifier: BSL-1.0
 
+####
+# Main util library
+#
+
 configure_file(
 	"${CMAKE_CURRENT_SOURCE_DIR}/u_git_tag.c.in" "${CMAKE_CURRENT_BINARY_DIR}/u_git_tag.c"
 	@ONLY
@@ -63,16 +67,6 @@ add_library(
 	u_pretty_print.h
 	u_prober.c
 	u_prober.h
-	u_sink.h
-	u_sink_combiner.c
-	u_sink_force_genlock.c
-	u_sink_converter.c
-	u_sink_deinterleaver.c
-	u_sink_queue.c
-	u_sink_simple_queue.c
-	u_sink_quirk.c
-	u_sink_split.c
-	u_sink_stereo_sbs_to_slam_sbs.c
 	u_string_list.cpp
 	u_string_list.h
 	u_string_list.hpp
@@ -102,12 +96,7 @@ add_library(
 	u_worker.hpp
 	"${CMAKE_CURRENT_BINARY_DIR}/u_git_tag.c"
 	)
-target_link_libraries(aux_util PUBLIC aux-includes xrt-pthreads aux_generated_bindings aux_math)
-
-if(XRT_HAVE_JPEG)
-	target_link_libraries(aux_util PRIVATE ${JPEG_LIBRARIES})
-	target_include_directories(aux_util PRIVATE ${JPEG_INCLUDE_DIRS})
-endif()
+target_link_libraries(aux_util PUBLIC aux-includes aux_generated_bindings aux_os aux_math)
 
 if(XRT_HAVE_SYSTEM_CJSON)
 	target_link_libraries(aux_util PUBLIC cJSON::cJSON)
@@ -130,3 +119,35 @@ if(ANDROID)
 endif()
 
 target_include_directories(aux_util PRIVATE ${EIGEN3_INCLUDE_DIR})
+
+####
+# Sink library
+#
+
+add_library(
+	aux_util_sink STATIC
+	u_sink.h
+	u_sink_combiner.c
+	u_sink_force_genlock.c
+	u_sink_converter.c
+	u_sink_deinterleaver.c
+	u_sink_queue.c
+	u_sink_simple_queue.c
+	u_sink_quirk.c
+	u_sink_split.c
+	u_sink_stereo_sbs_to_slam_sbs.c
+	)
+target_link_libraries(
+	aux_util_sink
+	PUBLIC
+		aux-includes
+		xrt-pthreads
+		aux_os
+		aux_math
+		aux_util
+	)
+
+if(XRT_HAVE_JPEG)
+	target_link_libraries(aux_util_sink PRIVATE ${JPEG_LIBRARIES})
+	target_include_directories(aux_util_sink PRIVATE ${JPEG_INCLUDE_DIRS})
+endif()
diff --git a/src/xrt/drivers/CMakeLists.txt b/src/xrt/drivers/CMakeLists.txt
index c9d83a212..820179ca7 100644
--- a/src/xrt/drivers/CMakeLists.txt
+++ b/src/xrt/drivers/CMakeLists.txt
@@ -373,6 +373,7 @@ if(XRT_BUILD_DRIVER_WMR)
 		PRIVATE
 			xrt-interfaces
 			aux_util
+			aux_util_sink # TODO remove this when converted to builders.
 			aux_math
 			aux_tracking
 			xrt-external-cjson
diff --git a/src/xrt/state_trackers/gui/CMakeLists.txt b/src/xrt/state_trackers/gui/CMakeLists.txt
index 47e96be3a..07a09c173 100644
--- a/src/xrt/state_trackers/gui/CMakeLists.txt
+++ b/src/xrt/state_trackers/gui/CMakeLists.txt
@@ -28,6 +28,7 @@ target_link_libraries(
 	PRIVATE
 		xrt-external-stb
 		aux_util
+		aux_util_sink
 		aux_os
 		aux_ogl
 		drv_includes
diff --git a/src/xrt/state_trackers/prober/CMakeLists.txt b/src/xrt/state_trackers/prober/CMakeLists.txt
index e5b843080..83cfda8f1 100644
--- a/src/xrt/state_trackers/prober/CMakeLists.txt
+++ b/src/xrt/state_trackers/prober/CMakeLists.txt
@@ -17,6 +17,7 @@ target_link_libraries(
 		drv_includes
 		drv_multi
 		aux_util
+		aux_util_sink
 		aux_os
 		aux_tracking
 	)
diff --git a/src/xrt/targets/common/CMakeLists.txt b/src/xrt/targets/common/CMakeLists.txt
index f951cd8e5..6b6e6363f 100644
--- a/src/xrt/targets/common/CMakeLists.txt
+++ b/src/xrt/targets/common/CMakeLists.txt
@@ -9,7 +9,7 @@ add_library(
 	target_lists STATIC target_builder_interface.h target_builder_legacy.c target_lists.c
 			    target_lists.h
 	)
-target_link_libraries(target_lists PRIVATE xrt-interfaces aux_util drv_includes)
+target_link_libraries(target_lists PRIVATE xrt-interfaces aux_util aux_util_sink drv_includes)
 target_include_directories(target_lists PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
 
 ###