Add example project using CMake package
This commit is contained in:
parent
9df3427151
commit
443b93f48e
4 changed files with 93 additions and 4 deletions
51
examples/main-cmake-pkg/.gitignore
vendored
Normal file
51
examples/main-cmake-pkg/.gitignore
vendored
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
# Prerequisites
|
||||||
|
*.d
|
||||||
|
|
||||||
|
# Compiled Object files
|
||||||
|
*.slo
|
||||||
|
*.lo
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Compiled Dynamic libraries
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
*.dll
|
||||||
|
|
||||||
|
# Fortran module files
|
||||||
|
*.mod
|
||||||
|
*.smod
|
||||||
|
|
||||||
|
# Compiled Static libraries
|
||||||
|
*.lai
|
||||||
|
*.la
|
||||||
|
*.a
|
||||||
|
*.lib
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
|
||||||
|
*.gguf
|
||||||
|
|
||||||
|
*.log
|
||||||
|
.DS_Store
|
||||||
|
.build/
|
||||||
|
.cache/
|
||||||
|
.direnv/
|
||||||
|
.envrc
|
||||||
|
.swiftpm
|
||||||
|
.venv
|
||||||
|
.clang-tidy
|
||||||
|
.vs/
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
build*/
|
||||||
|
out/
|
||||||
|
tmp/
|
||||||
|
|
36
examples/main-cmake-pkg/CMakeLists.txt
Normal file
36
examples/main-cmake-pkg/CMakeLists.txt
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
cmake_minimum_required(VERSION 3.12)
|
||||||
|
project("main-cmake-pkg" C CXX)
|
||||||
|
set(TARGET main-cmake-pkg)
|
||||||
|
|
||||||
|
find_package(Llama 0.0.1 REQUIRED)
|
||||||
|
|
||||||
|
# Bake common functionality in with target. Because applications
|
||||||
|
# using the relocatable Llama package should be outside of the
|
||||||
|
# source tree, main-cmake-pkg pretends the dependencies are built-in.
|
||||||
|
|
||||||
|
set(_common_path "${CMAKE_CURRENT_LIST_DIR}/../../common")
|
||||||
|
add_library(common OBJECT
|
||||||
|
${_common_path}/common.h
|
||||||
|
${_common_path}/common.cpp
|
||||||
|
${_common_path}/console.h
|
||||||
|
${_common_path}/console.cpp
|
||||||
|
${_common_path}/grammar-parser.h
|
||||||
|
${_common_path}/grammar-parser.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# WARNING: because build-info.h is auto-generated, it will only
|
||||||
|
# be available after the user has built the llama.cpp sources.
|
||||||
|
#
|
||||||
|
configure_file(${_common_path}/../build-info.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/build-info.h
|
||||||
|
COPYONLY)
|
||||||
|
|
||||||
|
target_include_directories(common PUBLIC ${LLAMA_INCLUDE_DIR}
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
|
add_executable(${TARGET} ${CMAKE_CURRENT_LIST_DIR}/../main/main.cpp)
|
||||||
|
target_include_directories(${TARGET} PRIVATE ${_common_path})
|
||||||
|
install(TARGETS ${TARGET} RUNTIME)
|
||||||
|
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
target_compile_features(${TARGET} PRIVATE cxx_std_11)
|
||||||
|
|
4
examples/main-cmake-pkg/README.md
Normal file
4
examples/main-cmake-pkg/README.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# llama.cpp/example/main-cmake-pkg
|
||||||
|
|
||||||
|
This program builds the [main](../main) application using a relocatable CMake package. It serves as an example of using the `find_package()` CMake command to conveniently include [llama.cpp](https://github.com/ggerganov/llama.cpp) in projects which live outside of the source tree.
|
||||||
|
|
|
@ -55,11 +55,9 @@ find_library(llama_LIBRARY llama
|
||||||
REQUIRED
|
REQUIRED
|
||||||
HINTS ${LLAMA_LIB_DIR})
|
HINTS ${LLAMA_LIB_DIR})
|
||||||
|
|
||||||
select_library_configurations(llama)
|
|
||||||
|
|
||||||
set(_llama_link_deps "Threads::Threads" "@LLAMA_EXTRA_LIBS@")
|
set(_llama_link_deps "Threads::Threads" "@LLAMA_EXTRA_LIBS@")
|
||||||
add_library(Llama::llama $<IF:$<BOOL:${LLAMA_SHARED_LIB}>,SHARED,STATIC> IMPORTED)
|
add_library(llama UNKNOWN IMPORTED)
|
||||||
set_target_properties(Llama::llama
|
set_target_properties(llama
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
INTERFACE_INCLUDE_DIRECTORIES "${LLAMA_INCLUDE_DIR}"
|
INTERFACE_INCLUDE_DIRECTORIES "${LLAMA_INCLUDE_DIR}"
|
||||||
INTERFACE_LINK_LIBRARIES "${_llama_link_deps}"
|
INTERFACE_LINK_LIBRARIES "${_llama_link_deps}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue