CMakeLists.txt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. cmake_minimum_required(VERSION 3.14) # 3.11 or later for FetchContent, but some features might require newer versions
  2. project(llama_cpp)
  3. include(FetchContent)
  4. FetchContent_Declare(
  5. llama_cpp_gguf
  6. GIT_REPOSITORY https://github.com/ggerganov/llama.cpp.git
  7. GIT_TAG 6381d4e
  8. )
  9. FetchContent_Declare(
  10. llama_cpp_ggml
  11. GIT_REPOSITORY https://github.com/ggerganov/llama.cpp.git
  12. GIT_TAG dadbed9
  13. )
  14. FetchContent_MakeAvailable(llama_cpp_ggml)
  15. add_subdirectory(${llama_cpp_ggml_SOURCE_DIR}/examples EXCLUDE_FROM_ALL)
  16. add_executable(llama_cpp ${llama_cpp_ggml_SOURCE_DIR}/examples/server/server.cpp)
  17. include_directories(${llama_cpp_ggml_SOURCE_DIR})
  18. include_directories(${llama_cpp_ggml_SOURCE_DIR}/examples)
  19. target_compile_features(llama_cpp PRIVATE cxx_std_11)
  20. target_link_libraries(llama_cpp PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
  21. if (APPLE)
  22. add_executable(llama_cpp_metal ${llama_cpp_ggml_SOURCE_DIR}/examples/server/server.cpp)
  23. target_compile_options(llama_cpp_metal PRIVATE -DLLAMA_STATIC=ON -DLLAMA_METAL=ON -DGGML_USE_METAL=1)
  24. target_compile_features(llama_cpp_metal PRIVATE cxx_std_11)
  25. target_link_libraries(llama_cpp_metal PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
  26. configure_file(${llama_cpp_SOURCE_DIR}/ggml-metal.metal ${CMAKE_BINARY_DIR}/ggml-metal.metal COPYONLY)
  27. else()
  28. add_executable(llama_cpp_cublas ${llama_cpp_ggml_SOURCE_DIR}/examples/server/server.cpp)
  29. target_compile_definitions(llama_cpp_cublas PRIVATE -DLLAMA_STATIC=ON -DLLAMA_CUBLAS=ON)
  30. target_compile_options(llama_cpp_cublas PRIVATE -DLLAMA_CUBLAS=ON -DLLAMA_STATIC=ON)
  31. target_compile_features(llama_cpp_cublas PRIVATE cxx_std_11)
  32. target_link_libraries(llama_cpp_cublas PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
  33. endif()