# CMake Error: Policy CMP0091 is not set: MSVC runtime library flags are selected by the CMAKE_MSVC_RUNTIME_LIBRARY variable.

- **ID:** `cmake/missing-override-policy-visibility-inline`
- **Domain:** cmake
- **Category:** config_error
- **Error Code:** `CMP0091`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| CMake 3.15 | active | — | — |
| CMake 3.16 | active | — | — |
| CMake 3.20 | active | — | — |
| Visual Studio 2019 | active | — | — |
| Visual Studio 2022 | active | — | — |

## Workarounds

1. **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).** (90% success)
   ```
   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).
   ```
2. **Use `set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")` and `cmake_policy(SET CMP0091 NEW)` inside a toolchain file for cross-platform builds.** (85% success)
   ```
   Use `set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")` and `cmake_policy(SET CMP0091 NEW)` inside a toolchain file for cross-platform builds.
   ```
3. **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.** (75% success)
   ```
   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.
   ```

## Dead Ends

- **Setting CMAKE_MSVC_RUNTIME_LIBRARY directly without cmake_policy(SET CMP0091 NEW)** — 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. (70% fail)
- **Hardcoding MSVC runtime flags in CMAKE_CXX_FLAGS** — Adding /MD or /MT flags manually via CMAKE_CXX_FLAGS can conflict with CMake's runtime library selection, causing linker errors or undefined behavior. (85% fail)
- **Suppressing the warning with cmake_policy(SET CMP0091 OLD)** — Ignoring the warning may allow the build to proceed, but the resulting binaries may link against mismatched runtime libraries, leading to crashes. (60% fail)
