Skip to content

Commit a31f218

Browse files
committed
cmake: Enable building against system ggml
This facilitates package maintenance for Linux distributions, where the libggml library most likely will be shipped as an individual package upon which a llama.cpp package depends.
1 parent a02c50a commit a31f218

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ else()
2929
set(LLAMA_STANDALONE OFF)
3030
endif()
3131

32+
option(LLAMA_USE_SYSTEM_GGML "Use system libggml" OFF)
33+
3234
if (EMSCRIPTEN)
3335
set(BUILD_SHARED_LIBS_DEFAULT OFF)
3436

@@ -145,7 +147,15 @@ endif()
145147
# 3rd-party
146148
#
147149

148-
if (NOT TARGET ggml)
150+
if (LLAMA_USE_SYSTEM_GGML)
151+
message(STATUS "Using system-provided libggml, skipping ggml build")
152+
find_package(ggml REQUIRED)
153+
set(GGML_TARGET ggml::ggml)
154+
else()
155+
set(GGML_TARGET ggml)
156+
endif()
157+
158+
if (NOT TARGET ggml AND NOT LLAMA_USE_SYSTEM_GGML)
149159
add_subdirectory(ggml)
150160
# ... otherwise assume ggml is added by a parent CMakeLists.txt
151161
endif()

examples/gguf-hash/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ endif()
1818
add_library(sha256 OBJECT deps/sha256/sha256.c deps/sha256/sha256.h)
1919
target_link_libraries(${TARGET} PRIVATE sha256)
2020

21-
target_link_libraries(${TARGET} PRIVATE ggml ${CMAKE_THREAD_LIBS_INIT})
21+
target_link_libraries(${TARGET} PRIVATE ${GGML_TARGET} ${CMAKE_THREAD_LIBS_INIT})
2222
target_compile_features(${TARGET} PRIVATE cxx_std_17)

examples/gguf/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
set(TARGET llama-gguf)
22
add_executable(${TARGET} gguf.cpp)
33
install(TARGETS ${TARGET} RUNTIME)
4-
target_link_libraries(${TARGET} PRIVATE ggml ${CMAKE_THREAD_LIBS_INIT})
4+
target_link_libraries(${TARGET} PRIVATE ${GGML_TARGET} ${CMAKE_THREAD_LIBS_INIT})
55
target_compile_features(${TARGET} PRIVATE cxx_std_17)

examples/llava/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ add_library(llava OBJECT
55
clip.h
66
)
77

8-
target_link_libraries(llava PRIVATE ggml llama ${CMAKE_THREAD_LIBS_INIT})
8+
target_link_libraries(llava PRIVATE ${GGML_TARGET} llama ${CMAKE_THREAD_LIBS_INIT})
99

1010
target_include_directories(llava PUBLIC .)
1111
target_include_directories(llava PUBLIC ../..)
@@ -18,7 +18,7 @@ if (BUILD_SHARED_LIBS)
1818
set_target_properties(llava PROPERTIES POSITION_INDEPENDENT_CODE ON)
1919
target_compile_definitions(llava PRIVATE LLAMA_SHARED LLAMA_BUILD)
2020
add_library(llava_shared SHARED $<TARGET_OBJECTS:llava>)
21-
target_link_libraries(llava_shared PRIVATE ggml llama ${CMAKE_THREAD_LIBS_INIT})
21+
target_link_libraries(llava_shared PRIVATE ${GGML_TARGET} llama ${CMAKE_THREAD_LIBS_INIT})
2222
install(TARGETS llava_shared LIBRARY)
2323
endif()
2424

examples/rpc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
add_executable(rpc-server rpc-server.cpp)
2-
target_link_libraries(rpc-server PRIVATE ggml llama)
2+
target_link_libraries(rpc-server PRIVATE ${GGML_TARGET} llama)

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ add_library(llama
3232
target_include_directories(llama PUBLIC . ../include ../common)
3333
target_compile_features (llama PUBLIC cxx_std_17) # don't bump
3434

35-
target_link_libraries(llama PUBLIC ggml)
35+
target_link_libraries(llama PUBLIC ${GGML_TARGET})
3636

3737
if (BUILD_SHARED_LIBS)
3838
set_target_properties(llama PROPERTIES POSITION_INDEPENDENT_CODE ON)

0 commit comments

Comments
 (0)