# CMake Error: CMAKE_CROSSCOMPILING is TRUE but CMAKE_SYSTEM_NAME is not set.

- **ID:** `cmake/cross-compiling-toolchain-cmake-variable-not-set`
- **Domain:** cmake
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

When cross-compiling, CMake requires CMAKE_SYSTEM_NAME to be set in the toolchain file or command line; otherwise, it defaults to the host system, causing a mismatch.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| cmake 3.22 | active | — | — |
| cmake 3.25 | active | — | — |
| cmake 3.28 | active | — | — |

## Workarounds

1. **Define CMAKE_SYSTEM_NAME in your toolchain file, e.g., set(CMAKE_SYSTEM_NAME Linux). Then pass the toolchain file via -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake.** (85% success)
   ```
   Define CMAKE_SYSTEM_NAME in your toolchain file, e.g., set(CMAKE_SYSTEM_NAME Linux). Then pass the toolchain file via -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake.
   ```
2. **Alternatively, set CMAKE_SYSTEM_NAME on the command line: cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc ..** (80% success)
   ```
   Alternatively, set CMAKE_SYSTEM_NAME on the command line: cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc ..
   ```

## Dead Ends

- **Setting CMAKE_CROSSCOMPILING to FALSE manually in CMakeLists.txt** — Overriding CMAKE_CROSSCOMPILING is a read-only variable; CMake ignores user attempts to set it. (95% fail)
- **Adding set(CMAKE_SYSTEM_NAME Linux) in CMakeLists.txt instead of toolchain file** — CMAKE_SYSTEM_NAME must be set before the project() call; CMakeLists.txt executes after, so it has no effect. (90% fail)
