Skip to content

Commit e83065b

Browse files
committed
Modifications needed to get llama.xcframework to compile with libmtmd
1 parent 6a2bc8b commit e83065b

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ if (LLAMA_BUILD_COMMON AND LLAMA_BUILD_EXAMPLES)
188188
add_subdirectory(pocs)
189189
endif()
190190

191+
# Always build mtmd library
192+
add_subdirectory(tools/mtmd)
193+
191194
if (LLAMA_BUILD_COMMON AND LLAMA_BUILD_TOOLS)
192195
add_subdirectory(tools)
193196
endif()

build-xcframework.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ LLAMA_BUILD_EXAMPLES=OFF
1111
LLAMA_BUILD_TOOLS=OFF
1212
LLAMA_BUILD_TESTS=OFF
1313
LLAMA_BUILD_SERVER=OFF
14+
LLAMA_BUILD_COMMON=ON
1415
GGML_METAL=ON
1516
GGML_METAL_EMBED_LIBRARY=ON
1617
GGML_BLAS_DEFAULT=ON
@@ -35,6 +36,7 @@ COMMON_CMAKE_ARGS=(
3536
-DLLAMA_BUILD_TOOLS=${LLAMA_BUILD_TOOLS}
3637
-DLLAMA_BUILD_TESTS=${LLAMA_BUILD_TESTS}
3738
-DLLAMA_BUILD_SERVER=${LLAMA_BUILD_SERVER}
39+
-DLLAMA_BUILD_COMMON=${LLAMA_BUILD_COMMON}
3840
-DGGML_METAL_EMBED_LIBRARY=${GGML_METAL_EMBED_LIBRARY}
3941
-DGGML_BLAS_DEFAULT=${GGML_BLAS_DEFAULT}
4042
-DGGML_METAL=${GGML_METAL}
@@ -116,6 +118,7 @@ setup_framework_structure() {
116118

117119
# Copy all required headers (common for all platforms)
118120
cp include/llama.h ${header_path}
121+
cp include/llama-cpp.h ${header_path}
119122
cp ggml/include/ggml.h ${header_path}
120123
cp ggml/include/ggml-opt.h ${header_path}
121124
cp ggml/include/ggml-alloc.h ${header_path}
@@ -124,18 +127,29 @@ setup_framework_structure() {
124127
cp ggml/include/ggml-cpu.h ${header_path}
125128
cp ggml/include/ggml-blas.h ${header_path}
126129
cp ggml/include/gguf.h ${header_path}
130+
cp tools/mtmd/mtmd.h ${header_path}
131+
cp tools/mtmd/clip.h ${header_path}
132+
cp common/common.h ${header_path}
133+
cp common/chat.h ${header_path}
134+
cp common/sampling.h ${header_path}
127135

128136
# Create module map (common for all platforms)
129137
cat > ${module_path}module.modulemap << EOF
130138
framework module llama {
131139
header "llama.h"
140+
header "llama-cpp.h"
132141
header "ggml.h"
133142
header "ggml-alloc.h"
134143
header "ggml-backend.h"
135144
header "ggml-metal.h"
136145
header "ggml-cpu.h"
137146
header "ggml-blas.h"
138147
header "gguf.h"
148+
header "mtmd.h"
149+
header "clip.h"
150+
header "common.h"
151+
header "chat.h"
152+
header "sampling.h"
139153
140154
link "c++"
141155
link framework "Accelerate"
@@ -235,6 +249,9 @@ combine_static_libraries() {
235249
local base_dir="$(pwd)"
236250
local framework_name="llama"
237251

252+
echo "Debug: Building for ${platform} (simulator: ${is_simulator})"
253+
echo "Debug: Looking for libraries in ${build_dir}/${release_dir}"
254+
238255
# Determine output path based on platform
239256
local output_lib=""
240257
if [[ "$platform" == "macos" ]]; then
@@ -252,8 +269,21 @@ combine_static_libraries() {
252269
"${base_dir}/${build_dir}/ggml/src/${release_dir}/libggml-cpu.a"
253270
"${base_dir}/${build_dir}/ggml/src/ggml-metal/${release_dir}/libggml-metal.a"
254271
"${base_dir}/${build_dir}/ggml/src/ggml-blas/${release_dir}/libggml-blas.a"
272+
"${base_dir}/${build_dir}/build/mtmd.build/${release_dir}/libmtmd.a"
273+
"${base_dir}/${build_dir}/common/${release_dir}/libcommon.a"
255274
)
256275

276+
# Debug: Check if each library exists
277+
for lib in "${libs[@]}"; do
278+
if [ -f "$lib" ]; then
279+
echo "Debug: Found library: $lib"
280+
else
281+
echo "Debug: Missing library: $lib"
282+
echo "Debug: Directory contents:"
283+
dirname "$lib" | xargs ls -la 2>/dev/null || echo "Directory does not exist"
284+
fi
285+
done
286+
257287
# Create temporary directory for processing
258288
local temp_dir="${base_dir}/${build_dir}/temp"
259289
mkdir -p "${temp_dir}"
@@ -529,7 +559,7 @@ xcodebuild -create-xcframework \
529559
-framework $(pwd)/build-ios-device/framework/llama.framework \
530560
-debug-symbols $(pwd)/build-ios-device/dSYMs/llama.dSYM \
531561
-framework $(pwd)/build-macos/framework/llama.framework \
532-
-debug-symbols $(pwd)/build-macos/dSYMS/llama.dSYM \
562+
-debug-symbols $(pwd)/build-macos/dSYMs/llama.dSYM \
533563
-framework $(pwd)/build-visionos/framework/llama.framework \
534564
-debug-symbols $(pwd)/build-visionos/dSYMs/llama.dSYM \
535565
-framework $(pwd)/build-visionos-sim/framework/llama.framework \

tools/mtmd/CMakeLists.txt

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,28 @@ target_include_directories(mtmd PRIVATE ../../common) # for stb_image.h
1717

1818
target_compile_features(mtmd PRIVATE cxx_std_17)
1919

20+
# Create static library with proper output name
2021
add_library(mtmd_static STATIC $<TARGET_OBJECTS:mtmd>)
22+
set_target_properties(mtmd_static PROPERTIES
23+
OUTPUT_NAME "mtmd"
24+
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tools/mtmd/${CMAKE_CFG_INTDIR}"
25+
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tools/mtmd/${CMAKE_CFG_INTDIR}"
26+
XCODE_ATTRIBUTE_PRODUCT_NAME "mtmd"
27+
XCODE_ATTRIBUTE_SKIP_INSTALL NO
28+
XCODE_ATTRIBUTE_INSTALL_PATH "tools/mtmd/${CMAKE_CFG_INTDIR}"
29+
)
30+
target_link_libraries(mtmd_static PRIVATE ggml llama ${CMAKE_THREAD_LIBS_INIT})
31+
32+
# Install the static library
33+
install(TARGETS mtmd_static
34+
ARCHIVE DESTINATION lib
35+
LIBRARY DESTINATION lib
36+
RUNTIME DESTINATION bin)
37+
38+
# Install headers
39+
install(FILES mtmd.h clip.h
40+
DESTINATION include/mtmd)
41+
2142
if (BUILD_SHARED_LIBS)
2243
set_target_properties(mtmd PROPERTIES POSITION_INDEPENDENT_CODE ON)
2344
target_compile_definitions(mtmd PRIVATE LLAMA_SHARED LLAMA_BUILD)
@@ -34,14 +55,16 @@ if(TARGET BUILD_INFO)
3455
add_dependencies(mtmd BUILD_INFO)
3556
endif()
3657

37-
add_executable(llama-llava-cli deprecation-warning.cpp)
38-
add_executable(llama-gemma3-cli deprecation-warning.cpp)
39-
add_executable(llama-minicpmv-cli deprecation-warning.cpp)
40-
add_executable(llama-qwen2vl-cli deprecation-warning.cpp)
41-
42-
set(TARGET llama-mtmd-cli)
43-
add_executable(${TARGET} mtmd-cli.cpp)
44-
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME llama-mtmd-cli)
45-
install(TARGETS ${TARGET} RUNTIME)
46-
target_link_libraries(${TARGET} PRIVATE common mtmd ${CMAKE_THREAD_LIBS_INIT})
47-
target_compile_features(${TARGET} PRIVATE cxx_std_17)
58+
if (LLAMA_BUILD_TOOLS)
59+
add_executable(llama-llava-cli deprecation-warning.cpp)
60+
add_executable(llama-gemma3-cli deprecation-warning.cpp)
61+
add_executable(llama-minicpmv-cli deprecation-warning.cpp)
62+
add_executable(llama-qwen2vl-cli deprecation-warning.cpp)
63+
64+
set(TARGET llama-mtmd-cli)
65+
add_executable(${TARGET} mtmd-cli.cpp)
66+
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME llama-mtmd-cli)
67+
install(TARGETS ${TARGET} RUNTIME)
68+
target_link_libraries(${TARGET} PRIVATE common mtmd ${CMAKE_THREAD_LIBS_INIT})
69+
target_compile_features(${TARGET} PRIVATE cxx_std_17)
70+
endif()

0 commit comments

Comments
 (0)