Repository: ollama/ollama (language: go)

Issue:
Intel libggml-cpu-alderlake.so and so on are built on arm64 architecture
### What is the issue?

Currently (on v0.5.11) Intel microarchitecture libs are built on arm64 too.
But this does not seem useful.
```
[00:00:07] -- CMAKE_SYSTEM_PROCESSOR: aarch64
[00:00:07] -- Including CPU backend
[00:00:07] -- ARM detected
[00:00:07] -- Performing Test GGML_COMPILER_SUPPORTS_FP16_FORMAT_I3E
[00:00:07] -- Performing Test GGML_COMPILER_SUPPORTS_FP16_FORMAT_I3E - Failed
[00:00:07] -- ARM feature FMA enabled
[00:00:07] -- Adding CPU backend variant ggml-cpu-sandybridge:  
[00:00:07] -- ARM detected
[00:00:07] -- ARM feature FMA enabled
[00:00:07] -- Adding CPU backend variant ggml-cpu-haswell:  
[00:00:07] -- ARM detected
[00:00:07] -- ARM feature FMA enabled
[00:00:07] -- Adding CPU backend variant ggml-cpu-skylakex:  
[00:00:07] -- ARM detected
[00:00:07] -- ARM feature FMA enabled
[00:00:07] -- Adding CPU backend variant ggml-cpu-icelake:  
[00:00:07] -- ARM detected
[00:00:07] -- ARM feature FMA enabled
[00:00:07] -- Adding CPU backend variant ggml-cpu-alderlake:  
[00:00:07] -- ARM detected
[00:00:07] -- ARM feature FMA enabled
[00:00:07] -- Adding CPU backend variant ggml-cpu-sapphirerapids:  
[00:00:07] -- Looking for a CUDA compiler
[00:00:07] -- Looking for a CUDA compiler - NOTFOUND
[00:00:07] -- Looking for a HIP compiler
[00:00:07] -- Looking for a HIP compiler - NOTFOUND
[00:00:07] -- Configuring done (1.3s)
```
I thought maybe this is my mistake but you build the same way too:
```
host-189:~$ wget https://github.com/ollama/ollama/releases/download/v0.5.11/ollama-linux-arm64.tgz
host-189:~$ less ollama-linux-arm64.tgz
...
-rwxr-xr-x runner/runner     594128 2025-02-14 06:57 lib/ollama/libggml-base.so
-rwxr-xr-x runner/runner     397056 2025-02-14 06:57 lib/ollama/libggml-cpu-alderlake.so
-rwxr-xr-x runner/runner     397056 2025-02-14 06:57 lib/ollama/libggml-cpu-haswell.so
-rwxr-xr-x runner/runner     397056 2025-02-14 06:57 lib/ollama/libggml-cpu-icelake.so
-rwxr-xr-x runner/runner     397056 2025-02-14 06:57 lib/ollama/libggml-cpu-sandybridge.so
-rwxr-xr-x runner/runner     397056 2025-02-14 06:57 lib/ollama/libggml-cpu-sapphirerapids.so
-rwxr-xr-x runner/runner     397056 2025-02-14 06:57 lib/ollama/libggml-cpu-skylakex.so
```


### Relevant log output

```shell

```

### OS

Linux

### GPU

Other

### CPU

ARM64

### Ollama version

v0.5.11


Discussion / hints:
I think the problem is in this statement:
```cmake
if((NOT CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
    OR (NOT CMAKE_OSX_ARCHITECTURES AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64|ARM64|ARMv[0-9]+"))
    set(GGML_CPU_ALL_VARIANTS ON)
endif()
```
If `CMAKE_OSX_ARCHITECTURES` is undefined (perhaps when this is not OSX) due to `NOT` and `OR` this immediately results in `TRUE` and `GGML_CPU_ALL_VARIANTS` is enabled. (Negative logic is sometimes hard to follow and error prone.)

Fix patch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 081d48bc1ee..63b804582e5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,7 +24,7 @@ set(GGML_LLAMAFILE ON)
 set(GGML_CUDA_PEER_MAX_BATCH_SIZE 128)
 set(GGML_CUDA_GRAPHS ON)
 
-if((NOT CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
+if((CMAKE_OSX_ARCHITECTURES AND NOT CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
     OR (NOT CMAKE_OSX_ARCHITECTURES AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64|ARM64|ARMv[0-9]+"))
     set(GGML_CPU_ALL_VARIANTS ON)
 endif()


Test patch: