From ede266ac2ef188e7f7f0781ff1d8e7e6747c8ba0 Mon Sep 17 00:00:00 2001
From: Anonymous <>
Date: Tue, 27 Jan 2026 00:00:00 +0000
Subject: [PATCH 8/9] Introduce `ggml-backend-impl` target representing the
 header files with implementations used sharedly by backends. Unfortunately
 they are mixed with `ggml-base`.

---
 ggml/src/CMakeLists.txt | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/ggml/src/CMakeLists.txt b/ggml/src/CMakeLists.txt
index 823afb86..0b33eea2 100644
--- a/ggml/src/CMakeLists.txt
+++ b/ggml/src/CMakeLists.txt
@@ -189,6 +189,10 @@ if (GGML_BACKEND_DL AND NOT BUILD_SHARED_LIBS)
     message(FATAL_ERROR "GGML_BACKEND_DL requires BUILD_SHARED_LIBS")
 endif()
 
+# header-only lib, so INTERFACE. Must be only PRIVATE-linked, because it is just shared code recompiled in each backend.
+add_library(ggml-backend-impl INTERFACE)
+target_include_directories(ggml-backend-impl INTERFACE .)
+
 add_library(ggml-base
             ggml.c
             ggml.cpp
@@ -206,8 +210,7 @@ set_target_properties(ggml-base PROPERTIES
     SOVERSION ${GGML_VERSION_MAJOR}
 )
 
-target_link_libraries(ggml-base PUBLIC ggml-interface)
-target_include_directories(ggml-base PRIVATE .)
+target_link_libraries(ggml-base PUBLIC ggml-interface PRIVATE ggml-backend-impl)
 if (GGML_BACKEND_DL)
     target_compile_definitions(ggml-base PUBLIC GGML_BACKEND_DL)
 endif()
@@ -265,7 +268,7 @@ function(ggml_add_backend_library backend)
         install(TARGETS ${backend} LIBRARY)
     endif()
 
-    target_link_libraries(${backend} PUBLIC ggml-interface PRIVATE ggml-base)
+    target_link_libraries(${backend} PUBLIC ggml-interface PRIVATE ggml-base ggml-backend-impl)
     target_include_directories(${backend} PRIVATE ..)
 
     if (${BUILD_SHARED_LIBS})
-- 
2.51.0

