{
  "id": "cmake/in-source-build-forbidden",
  "signature": "CMake Error: In-source builds are not allowed. Please remove the CMakeCache.txt file from the source directory.",
  "signature_zh": "CMake 错误：不允许源内构建。请从源目录中删除 CMakeCache.txt 文件。",
  "regex": "CMake Error: In-source builds are not allowed\\. Please remove the CMakeCache\\.txt file from the source directory\\.",
  "domain": "cmake",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "CMake is configured to forbid building directly in the source tree, but the build directory is the same as the source directory.",
  "root_cause_type": "generic",
  "root_cause_zh": "CMake 配置为禁止在源码目录内直接构建，但构建目录与源码目录相同。",
  "versions": [
    {
      "version": "3.13",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.25",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.27",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Deleting CMakeCache.txt and re-running cmake . in the source directory",
      "why_fails": "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.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting CMAKE_DISABLE_IN_SOURCE_BUILD to OFF via command line",
      "why_fails": "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.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding a CMakeLists.txt in the build directory",
      "why_fails": "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.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Create a separate build directory and run cmake from there: mkdir build && cd build && cmake .. && make",
      "success_rate": 0.95,
      "how": "Create a separate build directory and run cmake from there: mkdir build && cd build && cmake .. && make",
      "condition": "",
      "sources": []
    },
    {
      "action": "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.",
      "success_rate": 0.7,
      "how": "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.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use cmake -B <build-dir> -S <source-dir> to explicitly separate directories: cmake -B build -S . && cmake --build build",
      "success_rate": 0.9,
      "how": "Use cmake -B <build-dir> -S <source-dir> to explicitly separate directories: cmake -B build -S . && cmake --build build",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "创建一个单独的构建目录并从那里运行 cmake：mkdir build && cd build && cmake .. && make",
    "如果必须进行源内构建，请在 CMakeLists.txt 开头设置策略：cmake_policy(SET CMP0011 OLD)，但不建议用于生产环境。",
    "使用 cmake -B <构建目录> -S <源码目录> 明确分离目录：cmake -B build -S . && cmake --build build"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://cmake.org/cmake/help/latest/policy/CMP0011.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-02-14",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}