{
  "id": "cmake/exported-target-policy-scope-mismatch",
  "signature": "CMake Error: Target \"mylib\" has policy scope mismatch when exporting. Policy CMP0074 is not set.",
  "signature_zh": "CMake 错误：导出目标 \"mylib\" 时策略范围不匹配。未设置策略 CMP0074。",
  "regex": "Target \".*\" has policy scope mismatch when exporting. Policy CMP0074 is not set",
  "domain": "cmake",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "When exporting a target via install(EXPORT) or export(), the target's directory-level policy settings differ from the importing project's policy scope, causing CMake to reject the export to prevent inconsistent behavior.",
  "root_cause_type": "generic",
  "root_cause_zh": "通过 install(EXPORT) 或 export() 导出目标时，目标目录级别的策略设置与导入项目的策略范围不同，导致 CMake 拒绝导出以防止行为不一致。",
  "versions": [
    {
      "version": "CMake 3.12",
      "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.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using cmake_policy(SET CMP0074 OLD) to force old behavior",
      "why_fails": "Setting cmake_policy(SET CMP0074 OLD) in the exporting project may suppress the error but can lead to subtle build failures in the importing project.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    },
    {
      "action": "Removing export() or install(EXPORT) from CMakeLists.txt",
      "why_fails": "Removing the export() call entirely avoids the error but breaks the intended package distribution.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Manually duplicating target definition in importing project",
      "why_fails": "Copying the target's CMakeLists.txt into the importing project manually may resolve the immediate error but creates maintenance burden and duplicates code.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure that the policy CMP0074 is set to NEW in both the exporting and importing projects by adding `cmake_policy(SET CMP0074 NEW)` in the top-level CMakeLists.txt before any target creation.",
      "success_rate": 0.85,
      "how": "Ensure that the policy CMP0074 is set to NEW in both the exporting and importing projects by adding `cmake_policy(SET CMP0074 NEW)` in the top-level CMakeLists.txt before any target creation.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `cmake_policy(PUSH)` and `cmake_policy(POP)` around the target definition to isolate policy settings, ensuring the export sees the same scope as the importing project.",
      "success_rate": 0.8,
      "how": "Use `cmake_policy(PUSH)` and `cmake_policy(POP)` around the target definition to isolate policy settings, ensuring the export sees the same scope as the importing project.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Regenerate the exported configuration file using `export(TARGETS mylib FILE \"${CMAKE_BINARY_DIR}/MyLibConfig.cmake\")` with a consistent policy set before calling export().",
      "success_rate": 0.75,
      "how": "Regenerate the exported configuration file using `export(TARGETS mylib FILE \"${CMAKE_BINARY_DIR}/MyLibConfig.cmake\")` with a consistent policy set before calling export().",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "通过在导出和导入项目的顶层 CMakeLists.txt 中在任何目标创建之前添加 `cmake_policy(SET CMP0074 NEW)`，确保两个项目中策略 CMP0074 都设置为 NEW。",
    "在目标定义周围使用 `cmake_policy(PUSH)` 和 `cmake_policy(POP)` 隔离策略设置，确保导出看到与导入项目相同的作用域。",
    "使用 `export(TARGETS mylib FILE \"${CMAKE_BINARY_DIR}/MyLibConfig.cmake\")` 重新生成导出配置文件，在调用 export() 之前设置一致的策略。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://cmake.org/cmake/help/latest/policy/CMP0074.html",
  "official_doc_section": null,
  "error_code": "CMP0074",
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}