{
  "id": "cmake/missing-override-policy-visibility-inline",
  "signature": "CMake Error: Policy CMP0091 is not set: MSVC runtime library flags are selected by the CMAKE_MSVC_RUNTIME_LIBRARY variable.",
  "signature_zh": "CMake 错误：未设置策略 CMP0091：MSVC 运行时库标志由 CMAKE_MSVC_RUNTIME_LIBRARY 变量选择。",
  "regex": "Policy CMP0091 is not set: MSVC runtime library flags are selected by the CMAKE_MSVC_RUNTIME_LIBRARY variable",
  "domain": "cmake",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "CMake 3.15+ introduces CMP0091 to control MSVC runtime library selection via CMAKE_MSVC_RUNTIME_LIBRARY, but the policy is not explicitly set, causing silent fallback to older behavior that may mismatch with project expectations.",
  "root_cause_type": "generic",
  "root_cause_zh": "CMake 3.15+ 引入了 CMP0091 策略，通过 CMAKE_MSVC_RUNTIME_LIBRARY 变量控制 MSVC 运行时库的选择，但未显式设置该策略，导致静默回退到旧行为，可能与项目预期不匹配。",
  "versions": [
    {
      "version": "CMake 3.15",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "CMake 3.16",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "CMake 3.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Visual Studio 2019",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Visual Studio 2022",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Setting CMAKE_MSVC_RUNTIME_LIBRARY directly without cmake_policy(SET CMP0091 NEW)",
      "why_fails": "Manually setting CMAKE_MSVC_RUNTIME_LIBRARY without setting the policy may still produce the warning or error, as the policy governs whether the variable is honored.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Hardcoding MSVC runtime flags in CMAKE_CXX_FLAGS",
      "why_fails": "Adding /MD or /MT flags manually via CMAKE_CXX_FLAGS can conflict with CMake's runtime library selection, causing linker errors or undefined behavior.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Suppressing the warning with cmake_policy(SET CMP0091 OLD)",
      "why_fails": "Ignoring the warning may allow the build to proceed, but the resulting binaries may link against mismatched runtime libraries, leading to crashes.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add `cmake_policy(SET CMP0091 NEW)` before any project() call in the top-level CMakeLists.txt, then set CMAKE_MSVC_RUNTIME_LIBRARY to the desired value (e.g., MultiThreadedDLL).",
      "success_rate": 0.9,
      "how": "Add `cmake_policy(SET CMP0091 NEW)` before any project() call in the top-level CMakeLists.txt, then set CMAKE_MSVC_RUNTIME_LIBRARY to the desired value (e.g., MultiThreadedDLL).",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `set(CMAKE_MSVC_RUNTIME_LIBRARY \"MultiThreadedDLL\")` and `cmake_policy(SET CMP0091 NEW)` inside a toolchain file for cross-platform builds.",
      "success_rate": 0.85,
      "how": "Use `set(CMAKE_MSVC_RUNTIME_LIBRARY \"MultiThreadedDLL\")` and `cmake_policy(SET CMP0091 NEW)` inside a toolchain file for cross-platform builds.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using CMake 3.14 or older, upgrade to 3.15+ and adopt the new policy; otherwise, avoid using CMAKE_MSVC_RUNTIME_LIBRARY and rely on manual flag management.",
      "success_rate": 0.75,
      "how": "If using CMake 3.14 or older, upgrade to 3.15+ and adopt the new policy; otherwise, avoid using CMAKE_MSVC_RUNTIME_LIBRARY and rely on manual flag management.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在顶层 CMakeLists.txt 中的任何 project() 调用之前添加 `cmake_policy(SET CMP0091 NEW)`，然后将 CMAKE_MSVC_RUNTIME_LIBRARY 设置为所需值（例如 MultiThreadedDLL）。",
    "在工具链文件中使用 `set(CMAKE_MSVC_RUNTIME_LIBRARY \"MultiThreadedDLL\")` 和 `cmake_policy(SET CMP0091 NEW)` 进行跨平台构建。",
    "如果使用 CMake 3.14 或更早版本，升级到 3.15+ 并采用新策略；否则，避免使用 CMAKE_MSVC_RUNTIME_LIBRARY，依赖手动标志管理。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://cmake.org/cmake/help/latest/policy/CMP0091.html",
  "official_doc_section": null,
  "error_code": "CMP0091",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-08-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}