-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
028f988
commit 9539965
Showing
3 changed files
with
43 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,67 @@ | ||
# The Flutter tooling requires that developers have CMake 3.10 or later | ||
# installed. You should not increase this version, as doing so will cause | ||
# the plugin to fail to compile for some customers of the plugin. | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
# Project-level configuration. | ||
set(PROJECT_NAME "maid_llm") | ||
project(${PROJECT_NAME} LANGUAGES CXX) | ||
|
||
set(MAID_LLM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../src) | ||
set(MAID_LLM_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../src) | ||
set(LLAMA_CPP_DIR ${MAID_LLM_SRC_DIR}/llama_cpp) | ||
|
||
set(BUILD_SHARED_LIBS ON) | ||
set(CMAKE_INSTALL_LIBDIR lib CACHE PATH "library install dir" FORCE) | ||
|
||
# Set the linker flags for shared libraries | ||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--build-id=none") | ||
|
||
set(LLAMA_NATIVE OFF CACHE BOOL "llama: disable -march=native flag" FORCE) | ||
set(LLAMA_VULKAN ON CACHE BOOL "llama: enable vulkan" FORCE) | ||
|
||
add_subdirectory(${MAID_LLM_DIR}/llama_cpp ${CMAKE_CURRENT_BINARY_DIR}/shared) | ||
find_package(Vulkan) | ||
if (Vulkan_FOUND) | ||
add_compile_definitions(GGML_USE_VULKAN) | ||
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} Vulkan::Vulkan) | ||
set(GGML_HEADERS_VULKAN ${LLAMA_CPP_DIR}/ggml-vulkan.h) | ||
set(GGML_SOURCES_VULKAN ${LLAMA_CPP_DIR}/ggml-vulkan.cpp) | ||
else() | ||
message(WARNING "Vulkan not found, building without Vulkan support") | ||
endif() | ||
|
||
add_library(maid_llm SHARED | ||
${MAID_LLM_DIR}/maid_llm.cpp | ||
${MAID_LLM_SRC_DIR}/maid_llm.cpp | ||
${LLAMA_CPP_DIR}/ggml.c | ||
${LLAMA_CPP_DIR}/ggml-alloc.c | ||
${LLAMA_CPP_DIR}/ggml-backend.c | ||
${LLAMA_CPP_DIR}/ggml-quants.c | ||
${LLAMA_CPP_DIR}/llama.cpp | ||
${LLAMA_CPP_DIR}/sgemm.cpp | ||
${LLAMA_CPP_DIR}/unicode.cpp | ||
${LLAMA_CPP_DIR}/unicode-data.cpp | ||
${LLAMA_CPP_DIR}/common/common.cpp | ||
${LLAMA_CPP_DIR}/common/sampling.cpp | ||
${LLAMA_CPP_DIR}/common/grammar-parser.cpp | ||
${LLAMA_CPP_DIR}/common/json-schema-to-grammar.cpp | ||
${GGML_SOURCES_VULKAN} | ||
${GGML_HEADERS_VULKAN} | ||
) | ||
|
||
# Add this line to include the llama_cpp directory | ||
target_include_directories(maid_llm PRIVATE | ||
${MAID_LLM_DIR} | ||
${MAID_LLM_DIR}/llama_cpp | ||
${MAID_LLM_DIR}/llama_cpp/common | ||
target_include_directories(maid_llm PRIVATE | ||
${MAID_LLM_SRC_DIR} | ||
${LLAMA_CPP_DIR} | ||
${LLAMA_CPP_DIR}/common | ||
) | ||
|
||
target_link_libraries(maid_llm llama common) | ||
|
||
set_target_properties(maid_llm PROPERTIES | ||
PUBLIC_HEADER ${MAID_LLM_DIR}/maid_llm.h | ||
PUBLIC_HEADER ${MAID_LLM_SRC_DIR}/maid_llm.h | ||
OUTPUT_NAME "maid" | ||
BUILD_WITH_INSTALL_RPATH TRUE | ||
INSTALL_RPATH "$ORIGIN" | ||
) | ||
|
||
target_compile_definitions(maid_llm PUBLIC DART_SHARED_LIB) | ||
|
||
set(maid_llm_bundled_libraries | ||
# Defined in ../src/CMakeLists.txt. | ||
# This can be changed to accommodate different builds. | ||
$<TARGET_FILE:maid_llm> | ||
PARENT_SCOPE | ||
target_compile_options(maid_llm PRIVATE | ||
-O3 | ||
-DNDEBUG | ||
-ffunction-sections | ||
-fdata-sections | ||
) | ||
|
||
target_link_options(maid_llm PRIVATE | ||
-Wl,--gc-sections | ||
-flto | ||
) |