# CMake Error: Target "mylib" has policy scope mismatch when exporting. Policy CMP0074 is not set.

- **ID:** `cmake/exported-target-policy-scope-mismatch`
- **Domain:** cmake
- **Category:** build_error
- **Error Code:** `CMP0074`
- **Verification:** ai_generated
- **Fix Rate:** 80%

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

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| CMake 3.12 | active | — | — |
| CMake 3.18 | active | — | — |
| CMake 3.22 | active | — | — |

## Workarounds

1. **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.** (85% success)
   ```
   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.
   ```
2. **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.** (80% success)
   ```
   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.
   ```
3. **Regenerate the exported configuration file using `export(TARGETS mylib FILE "${CMAKE_BINARY_DIR}/MyLibConfig.cmake")` with a consistent policy set before calling export().** (75% success)
   ```
   Regenerate the exported configuration file using `export(TARGETS mylib FILE "${CMAKE_BINARY_DIR}/MyLibConfig.cmake")` with a consistent policy set before calling export().
   ```

## Dead Ends

- **Using cmake_policy(SET CMP0074 OLD) to force old behavior** — 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. (65% fail)
- **Removing export() or install(EXPORT) from CMakeLists.txt** — Removing the export() call entirely avoids the error but breaks the intended package distribution. (90% fail)
- **Manually duplicating target definition in importing project** — Copying the target's CMakeLists.txt into the importing project manually may resolve the immediate error but creates maintenance burden and duplicates code. (80% fail)
