feat: Fix Cmakelist to allow building on Darwin platform

This commit is contained in:
Hugo Larcher 2024-11-29 00:01:33 +01:00
parent 6c5a75b593
commit d4e65bfe7b
No known key found for this signature in database
GPG Key ID: 3DAF63124699CA2B
2 changed files with 24 additions and 1 deletions

View File

@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.24)
project(tgi-llama-cpp-backend VERSION 1.0.0) project(tgi-llama-cpp-backend VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent) include(FetchContent)
@ -10,13 +11,18 @@ set(LLAMA_CPP_TARGET_CUDA_ARCHS "75-real;80-real;86-real;89-real;90-real" CACHE
option(LLAMA_CPP_BUILD_OFFLINE_RUNNER "Flag to build the standalone c++ backend runner") option(LLAMA_CPP_BUILD_OFFLINE_RUNNER "Flag to build the standalone c++ backend runner")
option(LLAMA_CPP_BUILD_CUDA "Flag to build CUDA enabled inference through llama.cpp") option(LLAMA_CPP_BUILD_CUDA "Flag to build CUDA enabled inference through llama.cpp")
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" AND (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin"))
message(STATUS "Targeting libc++") message(STATUS "Targeting libc++")
set(CMAKE_CXX_FLAGS -stdlib=libc++ ${CMAKE_CXX_FLAGS}) set(CMAKE_CXX_FLAGS -stdlib=libc++ ${CMAKE_CXX_FLAGS})
else () else ()
message(STATUS "Not using libc++ ${CMAKE_CXX_COMPILER_ID} ${CMAKE_SYSTEM_NAME}") message(STATUS "Not using libc++ ${CMAKE_CXX_COMPILER_ID} ${CMAKE_SYSTEM_NAME}")
endif () endif ()
# add linker options for Darwin
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L$HOMEBREW_PREFIX/opt/llvm/lib/c++ -L$HOMEBREW_PREFIX/opt/llvm/lib/unwind -lunwind")
endif ()
# Add dependencies # Add dependencies
include(cmake/numa.cmake) include(cmake/numa.cmake)
include(cmake/spdlog.cmake) include(cmake/spdlog.cmake)

View File

@ -0,0 +1,17 @@
## Compiling with MacOS
To compile the Llama.cpp backend on MacOS, you need to install `clang` and `cmake` via Homebrew:
```bash
brew install llvm cmake
```
You then need to configure CMakelists.txt to use the newly installed clang compiler.
You can do this by configuring your IDE or adding the following lines to the top of the file:
```cmake
set(CMAKE_C_COMPILER /opt/homebrew/opt/llvm/bin/clang)
set(CMAKE_CXX_COMPILER /opt/homebrew/opt/llvm/bin/clang++)
```
CMakelist.txt assumes that Homebrew installs libc++ in `$HOMEBREW_PREFIX/opt/llvm/lib/c++`.