char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
38521ec33
char/aliceai-t5-moe
1set ( TARGET cpp-httplib ) 2license_add_file ( "cpp-httplib" "LICENSE" ) 3 4find_package ( Threads REQUIRED ) 5 6llama_add_compile_flags () 7 8set ( CMAKE_POSITION_INDEPENDENT_CODE ON ) 9 10add_library ( $ { TARGET } STATIC httplib.cpp httplib.h ) 11 12add_library ( vendor::cpp-httplib ALIAS ${ TARGET }) 13 14# disable warnings in 3rd party code 15if ( CMAKE_CXX_COMPILER_IDSTREQUAL "MSVC" ) 16target_compile_options ( $ { TARGET } PRIVATE /w ) 17else () 18target_compile_options ( $ { TARGET } PRIVATE -w ) 19endif () 20 21target_link_libraries ( $ { TARGET } PRIVATE Threads::Threads ) 22 23if ( WIN32AND NOT MSVC) 24target_link_libraries ( $ { TARGET } PUBLIC ws2_32 ) 25endif () 26 27target_compile_features ( $ { TARGET } PRIVATE cxx_std_17 ) 28 29target_compile_definitions ( $ { TARGET } PRIVATE 30# increase max payload length to allow use of larger context size 31CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH=1048576 32# increase backlog size to avoid connection resets for >> 1 slots 33CPPHTTPLIB_LISTEN_BACKLOG=512 34# increase max URI length to handle longer prompts in query string 35CPPHTTPLIB_REQUEST_URI_MAX_LENGTH=32768 36# disable Nagle's algorithm 37CPPHTTPLIB_TCP_NODELAY=1 38) 39 40set ( OPENSSL_NO_ASM ON CACHE BOOL "Disable OpenSSL ASM code when building BoringSSL or LibreSSL" ) 41 42if ( LLAMA_BUILD_BORINGSSL) 43set ( FIPS OFF CACHE BOOL "Enable FIPS (BoringSSL)" ) 44 45set ( BORINGSSL_GIT "https://boringssl.googlesource.com/boringssl" CACHE STRING "BoringSSL git repository" ) 46set ( BORINGSSL_VERSION "0.20260903.0" CACHE STRING "BoringSSL version" ) 47 48message ( STATUS "Fetching BoringSSL version ${ BORINGSSL_VERSION } " ) 49 50set ( BORINGSSL_ARGS 51GIT_REPOSITORY ${ BORINGSSL_GIT } 52GIT_TAG ${ BORINGSSL_VERSION } 53) 54if ( CMAKE_VERSIONVERSION_GREATER_EQUAL 3.28) 55list ( APPEND BORINGSSL_ARGS EXCLUDE_FROM_ALL ) 56endif () 57 58include ( FetchContent ) 59FetchContent_Declare ( boringssl ${ BORINGSSL_ARGS }) 60 61set ( SAVED_BUILD_SHARED_LIBS ${ BUILD_SHARED_LIBS }) 62set ( SAVED_BUILD_TESTING ${ BUILD_TESTING }) 63 64set ( BUILD_SHARED_LIBS OFF ) 65set ( BUILD_TESTING OFF ) 66 67if ( CMAKE_VERSIONVERSION_GREATER_EQUAL 3.28) 68FetchContent_MakeAvailable ( boringssl ) 69else () 70FetchContent_GetProperties ( boringssl ) 71if ( NOT boringssl_POPULATED) 72FetchContent_Populate ( boringssl ) 73add_subdirectory ( $ { boringssl_SOURCE_DIR } ${ boringssl_BINARY_DIR } EXCLUDE_FROM_ALL ) 74endif () 75endif () 76 77set ( BUILD_SHARED_LIBS ${ SAVED_BUILD_SHARED_LIBS }) 78set ( BUILD_TESTING ${ SAVED_BUILD_TESTING }) 79 80license_add_file ( "BoringSSL" " ${ boringssl_SOURCE_DIR } /LICENSE" ) 81 82set ( CPPHTTPLIB_OPENSSL_SUPPORT TRUE ) 83target_link_libraries ( $ { TARGET } PUBLIC ssl crypto ) 84 85elseif ( LLAMA_BUILD_LIBRESSL) 86set ( LIBRESSL_VERSION "4.3.2" CACHE STRING "LibreSSL version" ) 87 88message ( STATUS "Fetching LibreSSL version ${ LIBRESSL_VERSION } " ) 89 90set ( LIBRESSL_ARGS 91URL "https://cdn.openbsd.org/pub/OpenBSD/LibreSSL/libressl- ${ LIBRESSL_VERSION } .tar.gz" 92) 93if ( CMAKE_VERSIONVERSION_GREATER_EQUAL 3.24) 94list ( APPEND LIBRESSL_ARGS DOWNLOAD_EXTRACT_TIMESTAMP TRUE ) 95endif () 96 97if ( CMAKE_VERSIONVERSION_GREATER_EQUAL 3.28) 98list ( APPEND LIBRESSL_ARGS EXCLUDE_FROM_ALL ) 99endif () 100 101include ( FetchContent ) 102FetchContent_Declare ( libressl ${ LIBRESSL_ARGS }) 103 104set ( SAVED_BUILD_SHARED_LIBS ${ BUILD_SHARED_LIBS }) 105set ( SAVED_BUILD_TESTING ${ BUILD_TESTING }) 106 107set ( BUILD_SHARED_LIBS OFF ) 108set ( BUILD_TESTING OFF ) 109 110if ( CMAKE_VERSIONVERSION_GREATER_EQUAL 3.28) 111FetchContent_MakeAvailable ( libressl ) 112else () 113FetchContent_GetProperties ( libressl ) 114if ( NOT libressl_POPULATED) 115FetchContent_Populate ( libressl ) 116add_subdirectory ( $ { libressl_SOURCE_DIR } ${ libressl_BINARY_DIR } EXCLUDE_FROM_ALL ) 117endif () 118endif () 119 120set ( BUILD_SHARED_LIBS ${ SAVED_BUILD_SHARED_LIBS }) 121set ( BUILD_TESTING ${ SAVED_BUILD_TESTING }) 122 123license_add_file ( "LibreSSL" " ${ libressl_SOURCE_DIR } /COPYING" ) 124 125set ( CPPHTTPLIB_OPENSSL_SUPPORT TRUE ) 126target_link_libraries ( $ { TARGET } PUBLIC ssl crypto ) 127 128elseif ( LLAMA_OPENSSL) 129find_package ( OpenSSL ) 130if ( OpenSSL_FOUND) 131include ( CheckCSourceCompiles ) 132set ( SAVED_CMAKE_REQUIRED_INCLUDES ${ CMAKE_REQUIRED_INCLUDES }) 133set ( CMAKE_REQUIRED_INCLUDES ${ OPENSSL_INCLUDE_DIR }) 134check_c_source_compiles ( " 135#include <openssl/opensslv.h> 136#if defined(OPENSSL_IS_BORINGSSL) || defined(LIBRESSL_VERSION_NUMBER) 137# if OPENSSL_VERSION_NUMBER < 0x1010107f 138# error bad version 139# endif 140#else 141# if OPENSSL_VERSION_NUMBER < 0x30000000L 142# error bad version 143# endif 144#endif 145int main() { return 0; } 146" OPENSSL_VERSION_SUPPORTED ) 147set ( CMAKE_REQUIRED_INCLUDES ${ SAVED_CMAKE_REQUIRED_INCLUDES }) 148if ( OPENSSL_VERSION_SUPPORTED) 149message ( STATUS "OpenSSL found: ${ OPENSSL_VERSION } " ) 150set ( CPPHTTPLIB_OPENSSL_SUPPORT TRUE ) 151target_link_libraries ( $ { TARGET } PUBLIC OpenSSL::SSL OpenSSL::Crypto ) 152endif () 153else () 154message ( WARNING "OpenSSL not found, HTTPS support disabled" ) 155endif () 156endif () 157 158# disable warnings in 3rd party code 159if ( LLAMA_BUILD_BORINGSSLOR LLAMA_BUILD_LIBRESSL) 160if ( CMAKE_CXX_COMPILER_IDSTREQUAL "MSVC" ) 161target_compile_options ( ssl PRIVATE /w ) 162target_compile_options ( crypto PRIVATE /w ) 163if ( LLAMA_BUILD_BORINGSSL) 164target_compile_options ( fipsmodule PRIVATE /w ) 165endif () 166if ( LLAMA_BUILD_LIBRESSL) 167target_compile_options ( ssl_obj PRIVATE /w ) 168target_compile_options ( bs_obj PRIVATE /w ) 169target_compile_options ( compat_obj PRIVATE /w ) 170target_compile_options ( crypto_obj PRIVATE /w ) 171endif () 172else () 173target_compile_options ( ssl PRIVATE -w ) 174target_compile_options ( crypto PRIVATE -w ) 175if ( LLAMA_BUILD_BORINGSSL) 176target_compile_options ( fipsmodule PRIVATE -w ) 177endif () 178if ( LLAMA_BUILD_LIBRESSL) 179target_compile_options ( ssl_obj PRIVATE -w ) 180target_compile_options ( bs_obj PRIVATE -w ) 181target_compile_options ( compat_obj PRIVATE -w ) 182target_compile_options ( crypto_obj PRIVATE -w ) 183endif () 184endif () 185endif () 186 187if ( CPPHTTPLIB_OPENSSL_SUPPORT) 188target_compile_definitions ( $ { TARGET } PUBLIC CPPHTTPLIB_OPENSSL_SUPPORT ) # used in server.cpp 189if ( APPLEAND CMAKE_SYSTEM_NAMESTREQUAL "Darwin" ) 190find_library ( CORE_FOUNDATION_FRAMEWORK CoreFoundation REQUIRED ) 191find_library ( SECURITY_FRAMEWORK Security REQUIRED ) 192target_link_libraries ( $ { TARGET } PUBLIC ${ CORE_FOUNDATION_FRAMEWORK } ${ SECURITY_FRAMEWORK }) 193endif () 194if ( WIN32AND NOT MSVC) 195target_link_libraries ( $ { TARGET } PUBLIC crypt32 ) 196endif () 197endif ()