From a92d266ceaba79af4b3110727274909f744edc17 Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Wed, 15 May 2024 18:12:32 -0400 Subject: [PATCH] cmake: fix Metal build after #2310 (#2350) I don't understand why this is needed, but it works. Signed-off-by: Jared Van Bortel --- gpt4all-backend/llama.cpp.cmake | 6 ++++-- gpt4all-chat/CMakeLists.txt | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gpt4all-backend/llama.cpp.cmake b/gpt4all-backend/llama.cpp.cmake index 4bb3d28313d7..b9cf4597842b 100644 --- a/gpt4all-backend/llama.cpp.cmake +++ b/gpt4all-backend/llama.cpp.cmake @@ -793,16 +793,18 @@ function(include_ggml SUFFIX) list(APPEND XC_FLAGS -std=${LLAMA_METAL_STD}) endif() + set(GGML_METALLIB ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib) add_custom_command( - OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib + OUTPUT ${GGML_METALLIB} COMMAND xcrun -sdk macosx metal ${XC_FLAGS} -c ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air - COMMAND xcrun -sdk macosx metallib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib + COMMAND xcrun -sdk macosx metallib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air -o ${GGML_METALLIB} COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-common.h COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal DEPENDS ${DIRECTORY}/ggml-metal.metal ${DIRECTORY}/ggml-common.h COMMENT "Compiling Metal kernels" ) + set_source_files_properties(${GGML_METALLIB} DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTIES GENERATED ON) add_custom_target( ggml-metal ALL diff --git a/gpt4all-chat/CMakeLists.txt b/gpt4all-chat/CMakeLists.txt index cb3519d27cb9..470ca2863fb0 100644 --- a/gpt4all-chat/CMakeLists.txt +++ b/gpt4all-chat/CMakeLists.txt @@ -185,6 +185,7 @@ if(METAL_SHADER_FILE) set_target_properties(chat PROPERTIES RESOURCE ${METAL_SHADER_FILE} ) + add_dependencies(chat ggml-metal) endif() target_compile_definitions(chat