* cmake : add config version support (wip) [no ci] This commit adds support for find_package using a version, for example: ``` find_package(ggml 0.19.0 REQUIRED) ``` examples/test-cmake has been updated to use this and build scripts have been added to verify this manually. This is still a work in progress and I'm not sure about the scripts and if we can find better ways to test this but it might be useful to have for verification of changes to the cmake build. * cmake : add semver to ggml backends [no ci] This commit adds a semver to the ggml backend modules files. The motivation for this is that the backends are currently loaded just a file extension, for example .so on linux. With the introduction of semantic versioning installing a new version should just work but since these files don't have a version they would get overwritten. Adding the semver to the library names allows multiple version to be supported and the correct one will be loaded by the code. I've only tested this on linux and need to test on mac and win. * Revert "cmake : add semver to ggml backends [no ci]" This reverts commit 53a6c58a07591951324c891b9986b2cffe5c7972. * examples : update build-install.sh and set GGML_BACKEND_DIR
207 lines
7.5 KiB
CMake
207 lines
7.5 KiB
CMake
@PACKAGE_INIT@
|
|
|
|
@GGML_VARIABLES_EXPANDED@
|
|
|
|
# Find all dependencies before creating any target.
|
|
include(CMakeFindDependencyMacro)
|
|
find_dependency(Threads)
|
|
if (NOT GGML_SHARED_LIB)
|
|
set(GGML_BASE_INTERFACE_LINK_LIBRARIES "")
|
|
set(GGML_CPU_INTERFACE_LINK_LIBRARIES "")
|
|
set(GGML_CPU_INTERFACE_LINK_OPTIONS "")
|
|
|
|
if (APPLE AND GGML_ACCELERATE)
|
|
find_library(ACCELERATE_FRAMEWORK Accelerate)
|
|
if(NOT ACCELERATE_FRAMEWORK)
|
|
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND 0)
|
|
return()
|
|
endif()
|
|
list(APPEND GGML_CPU_INTERFACE_LINK_LIBRARIES ${ACCELERATE_FRAMEWORK})
|
|
endif()
|
|
|
|
if (GGML_OPENMP_ENABLED)
|
|
find_dependency(OpenMP)
|
|
set(GGML_OPENMP_INTERFACE_LINK_LIBRARIES "")
|
|
if (TARGET OpenMP::OpenMP_C)
|
|
list(APPEND GGML_OPENMP_INTERFACE_LINK_LIBRARIES OpenMP::OpenMP_C)
|
|
endif()
|
|
if (TARGET OpenMP::OpenMP_CXX)
|
|
list(APPEND GGML_OPENMP_INTERFACE_LINK_LIBRARIES OpenMP::OpenMP_CXX)
|
|
endif()
|
|
list(APPEND GGML_BASE_INTERFACE_LINK_LIBRARIES ${GGML_OPENMP_INTERFACE_LINK_LIBRARIES})
|
|
list(APPEND GGML_CPU_INTERFACE_LINK_LIBRARIES ${GGML_OPENMP_INTERFACE_LINK_LIBRARIES})
|
|
endif()
|
|
|
|
if (GGML_CPU_HBM)
|
|
find_library(memkind memkind)
|
|
if(NOT memkind)
|
|
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND 0)
|
|
return()
|
|
endif()
|
|
list(APPEND GGML_CPU_INTERFACE_LINK_LIBRARIES memkind)
|
|
endif()
|
|
|
|
if (GGML_BLAS)
|
|
find_dependency(BLAS)
|
|
list(APPEND GGML_BLAS_INTERFACE_LINK_LIBRARIES ${BLAS_LIBRARIES})
|
|
list(APPEND GGML_BLAS_INTERFACE_LINK_OPTIONS ${BLAS_LINKER_FLAGS})
|
|
endif()
|
|
|
|
if (GGML_CUDA)
|
|
set(GGML_CUDA_INTERFACE_LINK_LIBRARIES "")
|
|
find_dependency(CUDAToolkit)
|
|
if (GGML_STATIC)
|
|
list(APPEND GGML_CUDA_INTERFACE_LINK_LIBRARIES $<LINK_ONLY:CUDA::cudart_static>)
|
|
if (WIN32)
|
|
list(APPEND GGML_CUDA_INTERFACE_LINK_LIBRARIES $<LINK_ONLY:CUDA::cublas> $<LINK_ONLY:CUDA::cublasLt>)
|
|
else()
|
|
list(APPEND GGML_CUDA_INTERFACE_LINK_LIBRARIES $<LINK_ONLY:CUDA::cublas_static> $<LINK_ONLY:CUDA::cublasLt_static>)
|
|
endif()
|
|
endif()
|
|
if (NOT GGML_CUDA_NO_VMM)
|
|
list(APPEND GGML_CUDA_INTERFACE_LINK_LIBRARIES $<LINK_ONLY:CUDA::cuda_driver>)
|
|
endif()
|
|
endif()
|
|
|
|
if (GGML_METAL)
|
|
find_library(FOUNDATION_LIBRARY Foundation)
|
|
find_library(METAL_FRAMEWORK Metal)
|
|
find_library(METALKIT_FRAMEWORK MetalKit)
|
|
if(NOT FOUNDATION_LIBRARY OR NOT METAL_FRAMEWORK OR NOT METALKIT_FRAMEWORK)
|
|
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND 0)
|
|
return()
|
|
endif()
|
|
set(GGML_METAL_INTERFACE_LINK_LIBRARIES
|
|
${FOUNDATION_LIBRARY} ${METAL_FRAMEWORK} ${METALKIT_FRAMEWORK})
|
|
endif()
|
|
|
|
if (GGML_OPENCL)
|
|
find_dependency(OpenCL)
|
|
set(GGML_OPENCL_INTERFACE_LINK_LIBRARIES $<LINK_ONLY:OpenCL::OpenCL>)
|
|
endif()
|
|
|
|
if (GGML_VULKAN)
|
|
find_dependency(Vulkan)
|
|
set(GGML_VULKAN_INTERFACE_LINK_LIBRARIES $<LINK_ONLY:Vulkan::Vulkan>)
|
|
endif()
|
|
|
|
if (GGML_HIP)
|
|
find_dependency(hip)
|
|
find_dependency(hipblas)
|
|
find_dependency(rocblas)
|
|
set(GGML_HIP_INTERFACE_LINK_LIBRARIES hip::host roc::rocblas roc::hipblas)
|
|
endif()
|
|
|
|
if (GGML_SYCL)
|
|
set(GGML_SYCL_INTERFACE_LINK_LIBRARIES "")
|
|
find_package(DNNL)
|
|
if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL")
|
|
list(APPEND GGML_SYCL_INTERFACE_LINK_LIBRARIES DNNL::dnnl)
|
|
endif()
|
|
if (WIN32)
|
|
find_dependency(IntelSYCL)
|
|
find_dependency(MKL)
|
|
list(APPEND GGML_SYCL_INTERFACE_LINK_LIBRARIES IntelSYCL::SYCL_CXX MKL::MKL MKL::MKL_SYCL)
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
set_and_check(GGML_INCLUDE_DIR "@PACKAGE_GGML_INCLUDE_INSTALL_DIR@")
|
|
set_and_check(GGML_LIB_DIR "@PACKAGE_GGML_LIB_INSTALL_DIR@")
|
|
#set_and_check(GGML_BIN_DIR "@PACKAGE_GGML_BIN_INSTALL_DIR@")
|
|
|
|
if(NOT TARGET ggml::ggml)
|
|
find_package(Threads REQUIRED)
|
|
|
|
unset(GGML_LIBRARY CACHE)
|
|
find_library(GGML_LIBRARY ggml
|
|
REQUIRED
|
|
HINTS ${GGML_LIB_DIR}
|
|
NO_CMAKE_FIND_ROOT_PATH)
|
|
|
|
add_library(ggml::ggml UNKNOWN IMPORTED)
|
|
set_target_properties(ggml::ggml
|
|
PROPERTIES
|
|
IMPORTED_LOCATION "${GGML_LIBRARY}"
|
|
INTERFACE_INCLUDE_DIRECTORIES "${GGML_INCLUDE_DIR}")
|
|
|
|
unset(GGML_BASE_LIBRARY CACHE)
|
|
find_library(GGML_BASE_LIBRARY ggml-base
|
|
REQUIRED
|
|
HINTS ${GGML_LIB_DIR}
|
|
NO_CMAKE_FIND_ROOT_PATH)
|
|
|
|
add_library(ggml::ggml-base UNKNOWN IMPORTED)
|
|
set_target_properties(ggml::ggml-base
|
|
PROPERTIES
|
|
IMPORTED_LOCATION "${GGML_BASE_LIBRARY}"
|
|
INTERFACE_INCLUDE_DIRECTORIES "${GGML_INCLUDE_DIR}"
|
|
INTERFACE_LINK_LIBRARIES "${GGML_BASE_INTERFACE_LINK_LIBRARIES}")
|
|
|
|
set(_ggml_all_targets "")
|
|
if (NOT GGML_BACKEND_DL)
|
|
foreach(_ggml_backend ${GGML_AVAILABLE_BACKENDS})
|
|
string(REPLACE "-" "_" _ggml_backend_pfx "${_ggml_backend}")
|
|
string(TOUPPER "${_ggml_backend_pfx}" _ggml_backend_pfx)
|
|
|
|
unset(${_ggml_backend_pfx}_LIBRARY CACHE)
|
|
find_library(${_ggml_backend_pfx}_LIBRARY ${_ggml_backend}
|
|
REQUIRED
|
|
HINTS ${GGML_LIB_DIR}
|
|
NO_CMAKE_FIND_ROOT_PATH)
|
|
|
|
message(STATUS "Found ${${_ggml_backend_pfx}_LIBRARY}")
|
|
|
|
add_library(ggml::${_ggml_backend} UNKNOWN IMPORTED)
|
|
set_target_properties(ggml::${_ggml_backend}
|
|
PROPERTIES
|
|
INTERFACE_INCLUDE_DIRECTORIES "${GGML_INCLUDE_DIR}"
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
|
|
IMPORTED_LOCATION "${${_ggml_backend_pfx}_LIBRARY}"
|
|
INTERFACE_COMPILE_FEATURES c_std_90
|
|
POSITION_INDEPENDENT_CODE ON)
|
|
|
|
string(REGEX MATCH "^ggml-cpu" is_cpu_variant "${_ggml_backend}")
|
|
if(is_cpu_variant)
|
|
list(APPEND GGML_CPU_INTERFACE_LINK_LIBRARIES "ggml::ggml-base")
|
|
set_target_properties(ggml::${_ggml_backend}
|
|
PROPERTIES
|
|
INTERFACE_LINK_LIBRARIES "${GGML_CPU_INTERFACE_LINK_LIBRARIES}")
|
|
|
|
if(GGML_CPU_INTERFACE_LINK_OPTIONS)
|
|
set_target_properties(ggml::${_ggml_backend}
|
|
PROPERTIES
|
|
INTERFACE_LINK_OPTIONS "${GGML_CPU_INTERFACE_LINK_OPTIONS}")
|
|
endif()
|
|
|
|
else()
|
|
list(APPEND ${_ggml_backend_pfx}_INTERFACE_LINK_LIBRARIES "ggml::ggml-base")
|
|
set_target_properties(ggml::${_ggml_backend}
|
|
PROPERTIES
|
|
INTERFACE_LINK_LIBRARIES "${${_ggml_backend_pfx}_INTERFACE_LINK_LIBRARIES}")
|
|
|
|
if(${_ggml_backend_pfx}_INTERFACE_LINK_OPTIONS)
|
|
set_target_properties(ggml::${_ggml_backend}
|
|
PROPERTIES
|
|
INTERFACE_LINK_OPTIONS "${${_ggml_backend_pfx}_INTERFACE_LINK_OPTIONS}")
|
|
endif()
|
|
endif()
|
|
|
|
list(APPEND _ggml_all_targets ggml::${_ggml_backend})
|
|
endforeach()
|
|
endif()
|
|
|
|
list(APPEND GGML_INTERFACE_LINK_LIBRARIES ggml::ggml-base "${_ggml_all_targets}")
|
|
set_target_properties(ggml::ggml
|
|
PROPERTIES
|
|
INTERFACE_LINK_LIBRARIES "${GGML_INTERFACE_LINK_LIBRARIES}")
|
|
|
|
add_library(ggml::all INTERFACE IMPORTED)
|
|
set_target_properties(ggml::all
|
|
PROPERTIES
|
|
INTERFACE_LINK_LIBRARIES "${_ggml_all_targets}")
|
|
|
|
endif()
|
|
|
|
check_required_components(ggml)
|