# CMake Error: In-source builds are not allowed. Please remove the CMakeCache.txt file from the source directory.

- **ID:** `cmake/in-source-build-forbidden`
- **Domain:** cmake
- **Category:** build_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

CMake is configured to forbid building directly in the source tree, but the build directory is the same as the source directory.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.13 | active | — | — |
| 3.18 | active | — | — |
| 3.20 | active | — | — |
| 3.25 | active | — | — |
| 3.27 | active | — | — |

## Workarounds

1. **Create a separate build directory and run cmake from there: mkdir build && cd build && cmake .. && make** (95% success)
   ```
   Create a separate build directory and run cmake from there: mkdir build && cd build && cmake .. && make
   ```
2. **If you must build in-source, set the policy in CMakeLists.txt: cmake_policy(SET CMP0011 OLD) at the top of the file, but this is discouraged for production.** (70% success)
   ```
   If you must build in-source, set the policy in CMakeLists.txt: cmake_policy(SET CMP0011 OLD) at the top of the file, but this is discouraged for production.
   ```
3. **Use cmake -B <build-dir> -S <source-dir> to explicitly separate directories: cmake -B build -S . && cmake --build build** (90% success)
   ```
   Use cmake -B <build-dir> -S <source-dir> to explicitly separate directories: cmake -B build -S . && cmake --build build
   ```

## Dead Ends

- **Deleting CMakeCache.txt and re-running cmake . in the source directory** — Deleting the cache file alone does not change the build directory location; the next cmake invocation still uses the source directory as the build directory, triggering the same error. (90% fail)
- **Setting CMAKE_DISABLE_IN_SOURCE_BUILD to OFF via command line** — This policy is typically enforced by the project's CMakeLists.txt via cmake_policy(SET CMP0011 NEW) or a project-specific guard, so overriding it externally does not work. (85% fail)
- **Adding a CMakeLists.txt in the build directory** — The build directory is not supposed to contain a CMakeLists.txt; CMake expects to find it in the source directory. This approach confuses the build system and leads to other errors. (95% fail)
