1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#
# OPTIONS
#
option(JJML_FORCE_BUILD_TP "Force build of reference third-party submodules even if they are available on the system")
option(JJML_DO_NOT_BUILD_TP "Fail if third-party libraries are not found, instead of building them from the reference submodules")
option(JJML_JDK_TP "Use third-party environment provided by a ggml-instrumented JDK (useful for Windows)")
#
# THIRD PARTY DETECTION
#
#set(CMAKE_FIND_DEBUG_MODE ON)
if(NOT JJML_FORCE_BUILD_TP)
if(NOT MSVC)
# Debian official until libraries are stable
set(CMAKE_PREFIX_PATH
/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/ggml/cmake-private
/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/llama/cmake-private
)
endif()
if(JJML_JDK_TP) # Use environment provided by a ggml-instrumented JDK
set(CMAKE_LIBRARY_PATH ${JAVA_HOME}/bin ${JAVA_HOME}/lib)
include_directories(${JAVA_HOME}/include SYSTEM)
endif()
# look for llama.cpp via CMake configs (preferred)
find_package(llama QUIET)
if(llama_FOUND)
message(STATUS "Found llama.cpp and ggml packages: ${llama_LIBRARY} ${GGML_LIBRARY} ${GGML_BASE_LIBRARY}")
else()
# look for llama.cpp via simple library search
find_library(llama_LIBRARY llama)
# look for ggml via CMake configs (preferred)
find_package(ggml QUIET)
if(ggml_FOUND)
message(STATUS "Found ggml package: ${GGML_LIBRARY} ${GGML_BASE_LIBRARY}")
else()
# look for ggml via simple library search
find_library(GGML_LIBRARY ggml)
find_library(GGML_BASE_LIBRARY ggml-base)
endif()
endif()
endif() # JJML_FORCE_BUILD_TP
if(EXISTS ${GGML_LIBRARY}) # ggml as external libraries
if(NOT ggml_FOUND) # not CMake configured
add_library(ggml SHARED IMPORTED GLOBAL)
if(MSVC)
set_target_properties(ggml PROPERTIES IMPORTED_IMPLIB ${GGML_LIBRARY})
else()
set_target_properties(ggml PROPERTIES IMPORTED_LOCATION ${GGML_LIBRARY})
endif()
add_library(ggml-base SHARED IMPORTED GLOBAL)
if(MSVC)
set_target_properties(ggml-base PROPERTIES IMPORTED_IMPLIB ${GGML_BASE_LIBRARY})
else()
set_target_properties(ggml-base PROPERTIES IMPORTED_LOCATION ${GGML_BASE_LIBRARY})
endif()
message(STATUS "Found ggml libraries: ${GGML_LIBRARY} ${GGML_BASE_LIBRARY}")
endif()
if(NOT DEFINED GGML_BACKEND_DL)
message(STATUS "## CHECK ###")
include(CheckIncludeFileCXX)
check_include_file_cxx(ggml-backend.h JJML_BACKEND_INCLUDE_FOUND)
if(JJML_BACKEND_INCLUDE_FOUND)
set(GGML_BACKEND_DL ON)
message(STATUS "Found ggml-backend.h, enabling GGML_BACKEND_DL")
endif()
endif()
endif()
if(EXISTS "${llama_LIBRARY}") # llama.cpp as external library
if(NOT llama_FOUND) # not CMake configured
add_library(llama SHARED IMPORTED GLOBAL)
if(MSVC)
set_target_properties(llama PROPERTIES IMPORTED_IMPLIB ${llama_LIBRARY})
else()
set_target_properties(llama PROPERTIES IMPORTED_LOCATION ${llama_LIBRARY})
endif()
target_link_libraries(llama INTERFACE ${GGML_LIBRARY})
message(STATUS "Found LLAMA library: ${llama_LIBRARY}")
endif()
endif()
if(NOT JJML_DO_NOT_BUILD_TP)
# Build reference third-party submodules if needed
add_subdirectory(tp)
endif()
message(STATUS "GGML_BUILD_NUMBER=${GGML_BUILD_NUMBER} LLAMA_BUILD_NUMBER=${LLAMA_BUILD_NUMBER}")
message(STATUS "GGML_VERSION=${GGML_VERSION} LLAMA_VERSION=${LLAMA_VERSION}")
#
# JJML NATIVE BUILD
#
if(GGML_BACKEND_DL)
message(STATUS "Build JNI libraries with support for dynamic ggml backends")
endif()
# Force ISO C++
if (MSVC)
add_compile_options(/permissive-)
else()
add_compile_options(-pedantic-errors)
endif()
# JNI shared libraries
add_subdirectory(org_argeo_jjml_ggml)
add_subdirectory(org_argeo_jjml_llm)
|