Expand variables with GGML_ prefix

This commit is contained in:
Mason M 2025-01-23 08:48:44 -04:00
parent 5b4c12e92e
commit 314f26cc8b
3 changed files with 33 additions and 4 deletions

View File

@ -269,8 +269,7 @@ endif()
# Create CMake package
#
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# * Generate version info based on git commit.
find_program(GIT_EXE NAMES git git.exe REQUIRED NO_CMAKE_FIND_ROOT_PATH)
execute_process(COMMAND ${GIT_EXE} rev-list --count HEAD
@ -290,8 +289,31 @@ execute_process(COMMAND ${GIT_EXE} rev-parse --short HEAD
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(GGML_INSTALL_VERSION 0.0.${GGML_BUILD_NUMBER})
# * Capture variables prefixed with GGML_.
set(variable_set_statements
"
####### Expanded from @GGML_VARIABLES_EXPANED@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run #######
")
get_cmake_property(all_variables VARIABLES)
foreach(variable_name IN LISTS all_variables)
if(variable_name MATCHES "^GGML_")
string(REPLACE ";" "\\;"
variable_value "${${variable_name}}")
set(variable_set_statements
"${variable_set_statements}set(${variable_name} \"${variable_value}\")\n")
endif()
endforeach()
set(GGML_VARIABLES_EXPANDED ${variable_set_statements})
# * Create the CMake package and set install location.
set(GGML_INSTALL_VERSION 0.0.${GGML_BUILD_NUMBER})
set(GGML_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Location of header files")
set(GGML_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Location of library files")
set(GGML_BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Location of binary files")

View File

@ -84,7 +84,7 @@ if (NOT GGML_SHARED_LIB)
endif()
set(_ggml_all_targets "")
foreach(_ggml_backend @GGML_BACKENDS@)
foreach(_ggml_backend ${GGML_AVAILABLE_BACKENDS})
string(replace "-" "_" _ggml_backend_pfx "${_ggml_backend}")
find_library(${_ggml_backend_pfx}_LIBRARY ${_ggml_backend}

View File

@ -250,6 +250,13 @@ function(ggml_add_backend_library backend)
target_compile_definitions(${backend} PRIVATE GGML_BACKEND_BUILD)
target_compile_definitions(${backend} PUBLIC GGML_BACKEND_SHARED)
endif()
if(NOT GGML_AVAILABLE_BACKENDS)
set(GGML_AVAILABLE_BACKENDS "${backend}" CACHE INTERNAL "List of backends for cmake package")
else()
set(GGML_AVAILABLE_BACKENDS "${GGML_AVAILABLE_BACKENDS};${backend}"
CACHE INTERNAL "List of backends for cmake package")
endif()
endfunction()
function(ggml_add_backend backend)