diff --git a/CMakeLists.txt b/CMakeLists.txt index caea48c5060..a3ef4474ad1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,13 @@ cmake_minimum_required(VERSION 3.14...3.28) # for add_link_options and implicit target directories. -project("llama.cpp" C CXX) + +# Only call project() when llama.cpp is the top-level build. When consumed as +# a subdirectory, a second project() would re-run toolchain detection and can +# override parent-project settings. See: +# https://github.com/ggml-org/llama.cpp/issues/20415 +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + project("llama.cpp" C CXX) +endif() + include(CheckIncludeFileCXX) #set(CMAKE_WARN_DEPRECATED YES) diff --git a/ggml/CMakeLists.txt b/ggml/CMakeLists.txt index 8454eecde6e..41d568c59d6 100644 --- a/ggml/CMakeLists.txt +++ b/ggml/CMakeLists.txt @@ -6,7 +6,16 @@ cmake_minimum_required(VERSION 3.14...3.28) # for add_link_options and implicit if (POLICY CMP0194) cmake_policy(SET CMP0194 NEW) endif() -project("ggml" C CXX ASM) + +# Only call project() when ggml is the top-level build. When consumed as a +# subdirectory (FetchContent, CPM, etc.), a second project() would re-run +# toolchain detection and can clobber parent-project settings such as +# CMAKE_OSX_ARCHITECTURES, CMAKE_OSX_SYSROOT or CMAKE_ASM_COMPILER during +# cross-compilation (iOS, Android NDK, arm64/x86_64 hosts). +# See: https://github.com/ggml-org/llama.cpp/issues/20415 +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + project("ggml" C CXX ASM) +endif() ### GGML Version set(GGML_VERSION_MAJOR 0)