mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-11-03 09:22:01 +00:00 
			
		
		
		
	cmake : add relocatable Llama package (#2960)
* Keep static libs and headers with install * Add logic to generate Config package * Use proper build info * Add llama as import library * Prefix target with package name * Add example project using CMake package * Update README * Update README * Remove trailing whitespace
This commit is contained in:
		
							
								
								
									
										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)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user