# CMake Error: FetchContent: Content for 'googletest' has already been populated. Use FETCHCONTENT_FULLY_DISCONNECTED or clear the population directory.

- **ID:** `cmake/fetchcontent-already-populated`
- **Domain:** cmake
- **Category:** build_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

FetchContent is called multiple times for the same dependency (e.g., in different subdirectories) without proper guards, or a previous configure left stale population state.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| CMake 3.14+ | active | — | — |
| googletest 1.12.0 | active | — | — |

## Workarounds

1. **In CMakeLists.txt, guard FetchContent calls: if(NOT googletest_POPULATED) FetchContent_Declare(googletest ...) FetchContent_MakeAvailable(googletest) endif().** (95% success)
   ```
   In CMakeLists.txt, guard FetchContent calls: if(NOT googletest_POPULATED) FetchContent_Declare(googletest ...) FetchContent_MakeAvailable(googletest) endif().
   ```
2. **Clean the FetchContent population directory: rm -rf _deps/googletest* in the build directory, then reconfigure.** (85% success)
   ```
   Clean the FetchContent population directory: rm -rf _deps/googletest* in the build directory, then reconfigure.
   ```
3. **Use OVERRIDE_FIND_PACKAGE option in FetchContent_Declare to let find_package handle it: FetchContent_Declare(googletest GIT_REPOSITORY ... OVERRIDE_FIND_PACKAGE).** (80% success)
   ```
   Use OVERRIDE_FIND_PACKAGE option in FetchContent_Declare to let find_package handle it: FetchContent_Declare(googletest GIT_REPOSITORY ... OVERRIDE_FIND_PACKAGE).
   ```

## Dead Ends

- **Delete the build directory and reconfigure from scratch** — Temporary fix; if the root cause (duplicate FetchContent calls) isn't fixed, it will happen again on next clean configure. (80% fail)
- **Add set(FETCHCONTENT_FULLY_DISCONNECTED ON) globally** — This prevents any new downloads but may cause stale content if the dependency version changes. (50% fail)
- **Wrap each FetchContent_Declare in if(NOT <name>_POPULATED) but forget to call FetchContent_MakeAvailable** — Missing MakeAvailable means the content isn't populated; the error persists. (90% fail)
