@@ -6,6 +6,10 @@ option(LLAMA_BUILD "Build llama.cpp shared library and install alongside python
66option (LLAVA_BUILD "Build llava shared library and install alongside python package" ON )
77
88function (llama_cpp_python_install_target target )
9+ if (NOT TARGET ${target} )
10+ return ()
11+ endif ()
12+
913 install (
1014 TARGETS ${target}
1115 LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} /llama_cpp/lib
@@ -55,24 +59,59 @@ if (LLAMA_BUILD)
5559 set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
5660 set (CMAKE_SKIP_RPATH FALSE )
5761
58- # Building llama
59- if (APPLE AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" )
60- # Need to disable these llama.cpp flags on Apple x86_64,
61- # otherwise users may encounter invalid instruction errors
62- set (GGML_AVX "Off" CACHE BOOL "ggml: enable AVX" FORCE)
63- set (GGML_AVX2 "Off" CACHE BOOL "ggml: enable AVX2" FORCE)
64- set (GGML_FMA "Off" CACHE BOOL "gml: enable FMA" FORCE)
65- set (GGML_F16C "Off" CACHE BOOL "gml: enable F16C" FORCE)
66- endif ()
62+ # Enable building of the common library
63+ set (LLAMA_BUILD_COMMON ON CACHE BOOL "Build llama.cpp common library" FORCE)
6764
65+ # Architecture detection and settings for Apple platforms
6866 if (APPLE )
69- set (GGML_METAL_EMBED_LIBRARY "On" CACHE BOOL "llama: embed metal library" FORCE)
67+ # Get the target architecture
68+ execute_process (
69+ COMMAND uname -m
70+ OUTPUT_VARIABLE HOST_ARCH
71+ OUTPUT_STRIP_TRAILING_WHITESPACE
72+ )
73+
74+ # If CMAKE_OSX_ARCHITECTURES is not set, use the host architecture
75+ if (NOT CMAKE_OSX_ARCHITECTURES)
76+ set (CMAKE_OSX_ARCHITECTURES ${HOST_ARCH} CACHE STRING "Build architecture for macOS" FORCE)
77+ endif ()
78+
79+ message (STATUS "Host architecture: ${HOST_ARCH} " )
80+ message (STATUS "Target architecture: ${CMAKE_OSX_ARCHITECTURES} " )
81+
82+ # Configure based on target architecture
83+ if (CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64" )
84+ # Intel Mac settings
85+ set (GGML_AVX "OFF" CACHE BOOL "ggml: enable AVX" FORCE)
86+ set (GGML_AVX2 "OFF" CACHE BOOL "ggml: enable AVX2" FORCE)
87+ set (GGML_FMA "OFF" CACHE BOOL "ggml: enable FMA" FORCE)
88+ set (GGML_F16C "OFF" CACHE BOOL "ggml: enable F16C" FORCE)
89+ endif ()
90+
91+ # Metal settings (enable for both architectures)
92+ set (GGML_METAL "ON" CACHE BOOL "ggml: enable Metal" FORCE)
93+ set (GGML_METAL_EMBED_LIBRARY "ON" CACHE BOOL "ggml: embed metal library" FORCE)
7094 endif ()
7195
7296 add_subdirectory (vendor/llama.cpp)
7397 llama_cpp_python_install_target(llama)
7498 llama_cpp_python_install_target(ggml)
75-
99+
100+ llama_cpp_python_install_target(ggml-base)
101+
102+ llama_cpp_python_install_target(ggml-amx)
103+ llama_cpp_python_install_target(ggml-blas)
104+ llama_cpp_python_install_target(ggml-can)
105+ llama_cpp_python_install_target(ggml-cpu)
106+ llama_cpp_python_install_target(ggml-cuda)
107+ llama_cpp_python_install_target(ggml-hip)
108+ llama_cpp_python_install_target(ggml-kompute)
109+ llama_cpp_python_install_target(ggml-metal)
110+ llama_cpp_python_install_target(ggml-musa)
111+ llama_cpp_python_install_target(ggml-rpc)
112+ llama_cpp_python_install_target(ggml-sycl)
113+ llama_cpp_python_install_target(ggml-vulkan)
114+
76115 # Workaround for Windows + CUDA https://github.com/abetlen/llama-cpp-python/issues/563
77116 if (WIN32 )
78117 install (
@@ -106,7 +145,7 @@ if (LLAMA_BUILD)
106145 # Building llava
107146 add_subdirectory (vendor/llama.cpp/examples/llava)
108147 set_target_properties (llava_shared PROPERTIES OUTPUT_NAME "llava" )
109- # Set CUDA_ARCHITECTURES to OFF on windows
148+
110149 if (WIN32 )
111150 set_target_properties (llava_shared PROPERTIES CUDA_ARCHITECTURES OFF )
112151 endif ()
@@ -121,5 +160,18 @@ if (LLAMA_BUILD)
121160 DESTINATION ${SKBUILD_PLATLIB_DIR} /llama_cpp/lib
122161 )
123162 endif ()
163+
164+ # Fix for llava build: Add include directory for llama.h
165+ # Move these commands after the add_subdirectory call
166+ target_include_directories (llava PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /vendor/llama.cpp/include )
167+ target_include_directories (llava PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /vendor/llama.cpp/ggml/include )
168+
169+ if (BUILD_SHARED_LIBS )
170+ target_include_directories (llava_shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /vendor/llama.cpp/include )
171+ target_include_directories (llava_shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /vendor/llama.cpp/ggml/include )
172+ endif ()
173+
174+ target_include_directories (llama-llava-cli PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /vendor/llama.cpp/include )
175+ target_include_directories (llama-minicpmv-cli PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /vendor/llama.cpp/include )
124176 endif ()
125177endif ()
0 commit comments