{
  "id": "cmake/target-sources-glob-missing",
  "signature": "CMake Error: Cannot find source file: /path/to/src/main.cpp. Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .f08.",
  "signature_zh": "CMake 错误：找不到源文件：/path/to/src/main.cpp。尝试了扩展名 .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .f08。",
  "regex": "Cannot find source file: .* Tried extensions",
  "domain": "cmake",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "A source file listed in target_sources() or add_executable() does not exist at the specified path, often due to a typo, missing file, or incorrect use of generator expressions that resolve to an empty string.",
  "root_cause_type": "generic",
  "root_cause_zh": "target_sources() 或 add_executable() 中列出的源文件在指定路径不存在，通常是由于拼写错误、文件丢失或生成器表达式解析为空字符串。",
  "versions": [
    {
      "version": "CMake 3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "CMake 3.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "CMake 3.25",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Creating an empty source file at the missing path",
      "why_fails": "Adding the missing file as an empty file may bypass the error but will cause compilation failures due to missing code.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Commenting out the target_sources() call",
      "why_fails": "Removing the source file entry from target_sources() may allow the build to proceed but will exclude the file from compilation, leading to undefined symbols.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "Replacing explicit source list with file(GLOB)",
      "why_fails": "Using file(GLOB) to automatically collect sources may mask the issue and lead to unpredictable builds if files are added or removed.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Correct the file path in the CMakeLists.txt, e.g., change `target_sources(mylib PRIVATE src/main.cpp)` to the actual path: `target_sources(mylib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)`.",
      "success_rate": 0.95,
      "how": "Correct the file path in the CMakeLists.txt, e.g., change `target_sources(mylib PRIVATE src/main.cpp)` to the actual path: `target_sources(mylib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the file is generated by a custom command, ensure the generation target runs before the compile step by adding `add_dependencies(mylib generator_target)`.",
      "success_rate": 0.85,
      "how": "If the file is generated by a custom command, ensure the generation target runs before the compile step by adding `add_dependencies(mylib generator_target)`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `configure_file()` to generate the missing source from a template if it is meant to be created at configure time.",
      "success_rate": 0.8,
      "how": "Use `configure_file()` to generate the missing source from a template if it is meant to be created at configure time.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在 CMakeLists.txt 中更正文件路径，例如将 `target_sources(mylib PRIVATE src/main.cpp)` 改为实际路径：`target_sources(mylib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)`。",
    "如果文件由自定义命令生成，通过添加 `add_dependencies(mylib generator_target)` 确保生成目标在编译步骤之前运行。",
    "如果文件本应在配置时创建，使用 `configure_file()` 从模板生成缺失的源文件。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://cmake.org/cmake/help/latest/command/target_sources.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-06-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}