char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
f3a184b15
char/aliceai-t5-moe
1find_package ( Threads REQUIRED ) 2 3llama_add_compile_flags () 4 5# 6# llama-common-base 7# 8 9# Build info header 10 11if ( EXISTS " ${ PROJECT_SOURCE_DIR } /.git" ) 12set ( GIT_DIR " ${ PROJECT_SOURCE_DIR } /.git" ) 13 14# Is git submodule 15if ( NOT IS_DIRECTORY " ${ GIT_DIR } " ) 16file ( READ ${ GIT_DIR } REAL_GIT_DIR_LINK ) 17string ( REGEX REPLACE "gitdir: (.*)\n $ " "\\1" REAL_GIT_DIR ${ REAL_GIT_DIR_LINK }) 18string ( FIND " ${ REAL_GIT_DIR } " "/" SLASH_POS ) 19if ( SLASH_POSEQUAL 0 ) 20set ( GIT_DIR " ${ REAL_GIT_DIR } " ) 21else () 22set ( GIT_DIR " ${ PROJECT_SOURCE_DIR } / ${ REAL_GIT_DIR } " ) 23endif () 24endif () 25 26if ( EXISTS " ${ GIT_DIR } /index" ) 27# For build-info.cpp below 28set_property ( DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS " ${ GIT_DIR } /index" ) 29else () 30message ( WARNING "Git index not found in git repository." ) 31endif () 32else () 33message ( WARNING "Git repository not found; to enable automatic generation of build info, make sure Git is installed and the project is a Git repository." ) 34endif () 35 36set ( TEMPLATE_FILE " ${ CMAKE_CURRENT_SOURCE_DIR } /build-info.cpp.in" ) 37set ( OUTPUT_FILE " ${ CMAKE_CURRENT_BINARY_DIR } /build-info.cpp" ) 38 39configure_file ( $ { TEMPLATE_FILE } ${ OUTPUT_FILE }) 40 41set ( TARGET llama-common-base ) 42add_library ( $ { TARGET } STATIC ${ OUTPUT_FILE }) 43 44target_include_directories ( $ { TARGET } PUBLIC . ) 45 46if ( BUILD_SHARED_LIBS) 47set_target_properties ( $ { TARGET } PROPERTIES POSITION_INDEPENDENT_CODE ON ) 48endif () 49 50# 51# llama-common 52# 53 54set ( TARGET llama-common ) 55 56include ( parsers/sources.cmake ) 57 58add_library ( $ { TARGET } 59${ LLAMA_CHAT_PARSERS_SOURCES } 60arg.cpp 61arg.h 62base64.hpp 63chat-auto-parser-generator.cpp 64chat-auto-parser-helpers.cpp 65chat-auto-parser.h 66chat-diff-analyzer.cpp 67chat-peg-parser.cpp 68chat-peg-parser.h 69chat.cpp 70chat.h 71common.cpp 72common.h 73console.cpp 74console.h 75debug.cpp 76debug.h 77download.cpp 78download.h 79fit.cpp 80fit.h 81hf-cache.cpp 82hf-cache.h 83http.h 84imatrix-loader.cpp 85imatrix-loader.h 86json-schema-to-grammar.cpp 87json-schema.cpp 88json-schema.h 89json.cpp 90json.h 91llguidance.cpp 92log.cpp 93log.h 94ngram-cache.cpp 95ngram-cache.h 96ngram-map.cpp 97ngram-map.h 98ngram-mod.cpp 99ngram-mod.h 100peg-parser.cpp 101peg-parser.h 102preset.cpp 103preset.h 104reasoning-budget.cpp 105reasoning-budget.h 106sampling.cpp 107sampling.h 108speculative.cpp 109speculative.h 110subproc.cpp 111subproc.h 112trie.cpp 113trie.h 114unicode.cpp 115unicode.h 116jinja/lexer.cpp 117jinja/lexer.h 118jinja/parser.cpp 119jinja/parser.h 120jinja/runtime.cpp 121jinja/runtime.h 122jinja/value.cpp 123jinja/value.h 124jinja/string.cpp 125jinja/string.h 126jinja/caps.cpp 127jinja/caps.h 128) 129 130set_target_properties ( $ { TARGET } PROPERTIES 131VERSION ${ LLAMA_VERSION_BASE } 132SOVERSION ${ LLAMA_VERSION_MAJOR } 133MACHO_CURRENT_VERSION 0 # keep macOS linker from seeing oversized version number 134) 135 136target_include_directories ( $ { TARGET } PUBLIC . ) 137target_link_libraries ( $ { TARGET } PUBLIC vendor::nlohmann vendor::sheredom ) 138target_compile_features ( $ { TARGET } PUBLIC cxx_std_17 ) 139 140if ( LLAMA_SUBPROCESS) 141target_compile_definitions ( $ { TARGET } PUBLIC LLAMA_SUBPROCESS ) 142endif () 143 144if ( BUILD_SHARED_LIBS) 145set_target_properties ( $ { TARGET } PROPERTIES POSITION_INDEPENDENT_CODE ON ) 146 147# TODO: make fine-grained exports in the future 148set_target_properties ( $ { TARGET } PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) 149endif () 150 151target_link_libraries ( $ { TARGET } PUBLIC llama-common-base ) 152target_link_libraries ( $ { TARGET } PRIVATE cpp-httplib ) 153 154if ( LLAMA_LLGUIDANCE) 155include ( ExternalProject ) 156set ( LLGUIDANCE_SRC ${ CMAKE_BINARY_DIR } /llguidance/source ) 157set ( LLGUIDANCE_PATH ${ LLGUIDANCE_SRC } /target/release ) 158set ( LLGUIDANCE_LIB_NAME " ${ CMAKE_STATIC_LIBRARY_PREFIX } llguidance ${ CMAKE_STATIC_LIBRARY_SUFFIX } " ) 159 160ExternalProject_Add ( llguidance_ext 161GIT_REPOSITORY https://github.com/guidance-ai/llguidance 162# v1.0.1: 163GIT_TAG d795912fedc7d393de740177ea9ea761e7905774 164PREFIX ${ CMAKE_BINARY_DIR } /llguidance 165SOURCE_DIR ${ LLGUIDANCE_SRC } 166BUILD_IN_SOURCE TRUE 167CONFIGURE_COMMAND "" 168BUILD_COMMAND cargo build --release --package llguidance 169INSTALL_COMMAND "" 170BUILD_BYPRODUCTS ${ LLGUIDANCE_PATH } / ${ LLGUIDANCE_LIB_NAME } ${ LLGUIDANCE_PATH } /llguidance.h 171UPDATE_COMMAND "" 172) 173target_compile_definitions ( $ { TARGET } PUBLIC LLAMA_USE_LLGUIDANCE ) 174 175add_library ( llguidance STATIC IMPORTED ) 176set_target_properties ( llguidance PROPERTIES IMPORTED_LOCATION ${ LLGUIDANCE_PATH } / ${ LLGUIDANCE_LIB_NAME }) 177add_dependencies ( llguidance llguidance_ext ) 178 179target_include_directories ( $ { TARGET } PRIVATE ${ LLGUIDANCE_PATH }) 180target_link_libraries ( $ { TARGET } PRIVATE llguidance ) 181if ( WIN32) 182target_link_libraries ( $ { TARGET } PRIVATE ws2_32 userenv ntdll bcrypt ) 183endif () 184endif () 185 186target_link_libraries ( $ { TARGET } PUBLIC llama Threads::Threads )