diff --git a/ggml/CMakeLists.txt b/ggml/CMakeLists.txt index 5a265cead..a6aa97d9d 100644 --- a/ggml/CMakeLists.txt +++ b/ggml/CMakeLists.txt @@ -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") diff --git a/ggml/cmake/ggml-config.cmake.in b/ggml/cmake/ggml-config.cmake.in index 91ae42540..9bbd1fa25 100644 --- a/ggml/cmake/ggml-config.cmake.in +++ b/ggml/cmake/ggml-config.cmake.in @@ -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} diff --git a/ggml/src/CMakeLists.txt b/ggml/src/CMakeLists.txt index ae1cd2337..d4f383c55 100644 --- a/ggml/src/CMakeLists.txt +++ b/ggml/src/CMakeLists.txt @@ -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)