llama.cpp/examples/main-cmake-pkg
andrijdavid 82d6eab224
main-cmake-pkg : fix build issue (#4665)
* Fix main-cmake-pkg compilation

* Use glob to load common files

* cmake : fix trailing whitespace

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
2023-12-29 16:18:20 +02:00
..
.gitignore cmake : add relocatable Llama package (#2960) 2023-09-14 20:04:40 +03:00
CMakeLists.txt main-cmake-pkg : fix build issue (#4665) 2023-12-29 16:18:20 +02:00
README.md cmake : add relocatable Llama package (#2960) 2023-09-14 20:04:40 +03:00

llama.cpp/example/main-cmake-pkg

This program builds the main application using a relocatable CMake package. It serves as an example of using the find_package() CMake command to conveniently include llama.cpp in projects which live outside of the source tree.

Building

Because this example is "outside of the source tree", it is important to first build/install llama.cpp using CMake. An example is provided here, but please see the llama.cpp build instructions for more detailed build instructions.

Considerations

When hardware acceleration libraries are used (e.g. CUBlas, Metal, CLBlast, etc.), CMake must be able to locate the associated CMake package. In the example below, when building main-cmake-pkg notice the CMAKE_PREFIX_PATH includes the Llama CMake package location in addition to the CLBlast package—which was used when compiling llama.cpp.

Build llama.cpp and install to C:\LlamaCPP directory

In this case, CLBlast was already installed so the CMake package is referenced in CMAKE_PREFIX_PATH.

git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
mkdir build
cd build
cmake .. -DBUILD_SHARED_LIBS=OFF -DLLAMA_CLBLAST=ON -DCMAKE_PREFIX_PATH=C:/CLBlast/lib/cmake/CLBlast -G "Visual Studio 17 2022" -A x64
cmake --build . --config Release
cmake --install . --prefix C:/LlamaCPP

Build main-cmake-pkg

cd ..\examples\main-cmake-pkg
mkdir build
cd build
cmake .. -DBUILD_SHARED_LIBS=OFF -DCMAKE_PREFIX_PATH="C:/CLBlast/lib/cmake/CLBlast;C:/LlamaCPP/lib/cmake/Llama" -G "Visual Studio 17 2022" -A x64
cmake --build . --config Release
cmake --install . --prefix C:/MyLlamaApp