aports/community/llama.cpp/0002-Install-libraries-into-LLAMA_LIB_INSTALL_DIR.patch
2026-05-04 05:28:49 +00:00

118 lines
4.2 KiB
Diff

From aaadc29404731fc01d6bae1a5f25ad1d4fe42d7b Mon Sep 17 00:00:00 2001
From: Hugo Osvaldo Barrera <hugo@whynothugo.nl>
Date: Wed, 25 Mar 2026 01:24:08 +0100
Subject: [PATCH 2/3] Install libraries into LLAMA_LIB_INSTALL_DIR
Using the following:
-DGGML_LIB_INSTALL_DIR=/usr/lib/llama.cpp \
-DLLAMA_LIB_INSTALL_DIR=/usr/lib/llama.cpp \
Several libraries are still installed into /usr/lib:
/usr/lib/libggml-base.so.0
/usr/lib/libggml-base.so.0.9.8
/usr/lib/libggml.so.0
/usr/lib/libggml.so.0.9.8
/usr/lib/libllama.so.0
/usr/lib/libllama.so.0.0.8508
/usr/lib/libmtmd.so.0
/usr/lib/libmtmd.so.0.0.8508
Install all these libraries into LLAMA_LIB_INSTALL_DIR instead, so they
don't collide with non-vendored libraries provided by other packages.
Also set the rpath if LLAMA_LIB_INSTALL_DIR is set, so that libraries
are properly loaded.
---
CMakeLists.txt | 18 ++++++++++++++----
ggml/CMakeLists.txt | 8 ++++++--
tools/mtmd/CMakeLists.txt | 2 +-
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index caea48c50..9cd06a022 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -78,6 +78,16 @@ if (LLAMA_STANDALONE)
list(APPEND CMAKE_VS_GLOBALS EnforceProcessCountAcrossBuilds=true)
endif()
+# Must be set before defining any targets.
+set(LLAMA_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Location of library files")
+set(LLAMA_BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Location of binary files")
+set(LLAMA_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Location of header files")
+
+if (NOT LLAMA_LIB_INSTALL_DIR STREQUAL CMAKE_INSTALL_LIBDIR)
+ set(CMAKE_INSTALL_RPATH "${LLAMA_LIB_INSTALL_DIR}")
+ set(CMAKE_BUILD_RPATH "${CMAKE_BINARY_DIR}/bin")
+endif()
+
if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(LLAMA_TOOLS_INSTALL_DEFAULT OFF)
else()
@@ -235,9 +245,9 @@ endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
-set(LLAMA_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Location of header files")
-set(LLAMA_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Location of library files")
-set(LLAMA_BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Location of binary files")
+if (NOT LLAMA_LIB_INSTALL_DIR STREQUAL CMAKE_INSTALL_LIBDIR)
+ set(CMAKE_INSTALL_RPATH "${LLAMA_LIB_INSTALL_DIR}")
+endif()
set(LLAMA_PUBLIC_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/llama.h
@@ -247,7 +257,7 @@ set_target_properties(llama
PROPERTIES
PUBLIC_HEADER "${LLAMA_PUBLIC_HEADERS}")
-install(TARGETS llama LIBRARY PUBLIC_HEADER)
+install(TARGETS llama LIBRARY DESTINATION ${LLAMA_LIB_INSTALL_DIR} PUBLIC_HEADER)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/llama-config.cmake.in
diff --git a/ggml/CMakeLists.txt b/ggml/CMakeLists.txt
index 5834e544b..9a96c491b 100644
--- a/ggml/CMakeLists.txt
+++ b/ggml/CMakeLists.txt
@@ -310,6 +310,10 @@ endif ()
# install
#
+if (NOT DEFINED GGML_LIB_INSTALL_DIR)
+ set(GGML_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Location of library files")
+endif()
+
include(CMakePackageConfigHelpers)
# all public headers
@@ -337,8 +341,8 @@ set_target_properties(ggml PROPERTIES PUBLIC_HEADER "${GGML_PUBLIC_HEADERS}")
#if (GGML_METAL)
# set_target_properties(ggml PROPERTIES RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/ggml-metal.metal")
#endif()
-install(TARGETS ggml LIBRARY PUBLIC_HEADER)
-install(TARGETS ggml-base LIBRARY)
+install(TARGETS ggml LIBRARY DESTINATION ${GGML_LIB_INSTALL_DIR} PUBLIC_HEADER)
+install(TARGETS ggml-base LIBRARY DESTINATION ${GGML_LIB_INSTALL_DIR})
if (GGML_STANDALONE)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ggml.pc.in
diff --git a/tools/mtmd/CMakeLists.txt b/tools/mtmd/CMakeLists.txt
index 675464c6b..29e7a46af 100644
--- a/tools/mtmd/CMakeLists.txt
+++ b/tools/mtmd/CMakeLists.txt
@@ -69,7 +69,7 @@ set_target_properties(mtmd
PROPERTIES
PRIVATE_HEADER debug/mtmd-debug.h)
-install(TARGETS mtmd LIBRARY PUBLIC_HEADER)
+install(TARGETS mtmd LIBRARY DESTINATION ${LLAMA_LIB_INSTALL_DIR} PUBLIC_HEADER)
if (NOT MSVC)
# for stb_image.h and miniaudio.h
--
2.53.0