From e611cfc56dcd73b450cc32c140b1b38680b4076f Mon Sep 17 00:00:00 2001 From: Andrei Betlen Date: Sat, 8 Apr 2023 02:39:17 -0400 Subject: [PATCH] Build shared library with make on unix platforms --- CMakeLists.txt | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39ec507..27e06ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,12 +2,26 @@ cmake_minimum_required(VERSION 3.4...3.22) project(llama_cpp) -set(BUILD_SHARED_LIBS "On") - -add_subdirectory(vendor/llama.cpp) - -install( - TARGETS llama - LIBRARY DESTINATION llama_cpp - RUNTIME DESTINATION llama_cpp -) \ No newline at end of file +if (UNIX) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/vendor/llama.cpp/libllama.so + COMMAND make libllama.so + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/vendor/llama.cpp + ) + add_custom_target( + run ALL + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/vendor/llama.cpp/libllama.so + ) + install( + FILES ${CMAKE_CURRENT_SOURCE_DIR}/vendor/llama.cpp/libllama.so + DESTINATION llama_cpp + ) +else() + set(BUILD_SHARED_LIBS "On") + add_subdirectory(vendor/llama.cpp) + install( + TARGETS llama + LIBRARY DESTINATION llama_cpp + RUNTIME DESTINATION llama_cpp + ) +endif(UNIX)