Skip to content

Compile bug: tools/tuning hardcodes ${CMAKE_SOURCE_DIR}, breaks FetchContent consumers (ggml-metal-tuning.h not found) #28114

Description

@thypon

Git commit

d222767 (b10630)
Still present on master as of 2026-08-31 (target_include_directories(${TARGET} PRIVATE ${CMAKE_SOURCE_DIR}/ggml/src/ggml-metal) in tools/tuning/CMakeLists.txt).

Operating systems

  • Linux
  • Mac
  • Windows
  • BSD
  • Other? (Please let us know in description)

(Only tested on Mac, but the root cause is platform-independent: any FetchContent/add_subdirectory consumer.)

GGML backends

  • BLAS
  • CPU
  • Metal

(Minimal reproducer below only sets -DGGML_METAL=ON; CPU and Accelerate/BLAS defaults apply on macOS. The failure is in the tools/tuning executable target itself, not in a backend.)

Problem description & steps to reproduce

tools/tuning/CMakeLists.txt (added in #26570) resolves its include directory relative to the outermost CMake project:

target_include_directories(${TARGET} PRIVATE ${CMAKE_SOURCE_DIR}/ggml/src/ggml-metal)
  • Standalone llama.cpp build: CMAKE_SOURCE_DIR == llama.cpp repo root → works.
  • FetchContent consumer: CMAKE_SOURCE_DIR == the consumer's top-level source dir → the include path does not exist → fa-vec.cpp fails with fatal error: 'ggml-metal-tuning.h' file not found (the header itself is checked in at ggml/src/ggml-metal/, so only the include path is wrong).

Minimal reproducer (llama.cpp b10630, macOS):

mkdir repro && cd repro
cat > CMakeLists.txt <<'CMAKE'
cmake_minimum_required(VERSION 3.16)
project(consumer C CXX)

include(FetchContent)

set(LLAMA_BUILD_COMMON   ON  CACHE BOOL "" FORCE)
set(LLAMA_BUILD_TOOLS    ON  CACHE BOOL "" FORCE)
set(LLAMA_BUILD_SERVER   OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_TESTS    OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

FetchContent_Declare(llama_cpp
  GIT_REPOSITORY https://github.com/ggml-org/llama.cpp.git
  GIT_TAG        d222767c7a6516559a3f49e7721b6c6b1acc87b4)

FetchContent_MakeAvailable(llama_cpp)
CMAKE

cmake -S . -B build -DGGML_METAL=ON
cmake --build build -j

Notes:

  • All three conditions are required: FetchContent (subproject) context, LLAMA_BUILD_TOOLS=ON, GGML_METAL=ON. FetchContent sets LLAMA_STANDALONE=OFF, so tools must be forced on, and tools/CMakeLists.txt only adds the target via if (GGML_METAL) add_subdirectory(tuning) — consumers that fetch llama.cpp with Metal disabled don't hit this.
  • LLAMA_BUILD_TOOLS=OFF is not a workaround for consumers that need llama.cpp's tools targets (ollama installs llama.cpp's llama-server/llama-quantize).
  • Observed in the wild with ollama v0.33.2; the Homebrew core formula for ollama had to ship an inreplace for this: ollama 0.33.2 Homebrew/homebrew-core#301407

Suggested fix (one line):

--- a/tools/tuning/CMakeLists.txt
+++ b/tools/tuning/CMakeLists.txt
@@ -3,7 +3,7 @@ set(TARGET ggml-metal-tuning)
 add_executable(${TARGET} main.cpp bench.cpp fa-vec.cpp)
 target_link_libraries(${TARGET} PRIVATE ggml ${CMAKE_THREAD_LIBS_INIT})
 target_compile_features(${TARGET} PRIVATE cxx_std_17)
-target_include_directories(${TARGET} PRIVATE ${CMAKE_SOURCE_DIR}/ggml/src/ggml-metal)
+target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../ggml/src/ggml-metal)

Verified locally with this patch applied:

  • Minimal reproducer above: builds, ggml-metal-tuning target links.
  • ollama v0.33.2 llama/server (FetchContent, --preset darwin) against the patched tree: configure, build and cmake --install --component llama-server all pass; llama-server --version reports build 10630, commit d222767c7.

First Bad Commit

f280b26#26570 (only commit touching tools/tuning/CMakeLists.txt)

Compile command

Minimal reproducer (see above):

cmake -S . -B build -DGGML_METAL=ON
cmake --build build -j

Consumer variant (ollama v0.33.2 llama/server preset):

cmake -S llama/server -B llama-server --preset darwin -DFETCHCONTENT_SOURCE_DIR_LLAMA_CPP=/path/to/llama.cpp
cmake --build llama-server

Relevant log output

/private/tmp/.../llama.cpp/tools/tuning/fa-vec.cpp:5:10: fatal error: 'ggml-metal-tuning.h' file not found
    5 | #include "ggml-metal-tuning.h"
      |          ^~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [_deps/llama_cpp-build/tools/tuning/CMakeFiles/ggml-metal-tuning.dir/fa-vec.cpp.o] Error 1
make[1]: *** [_deps/llama_cpp-build/tools/tuning/CMakeFiles/ggml-metal-tuning.dir/all] Error 2
make: *** [all] Error 2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions