# CMake 错误：INTERFACE_LIBRARY 目标只能包含 INTERFACE 属性。目标 "mylib" 的 SOURCES 属性不是 INTERFACE 类型。

- **ID:** `cmake/interface-library-sources-property`
- **领域:** cmake
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

INTERFACE 库目标被错误地通过 set_target_properties 或 add_library 赋予源文件参数，这是不允许的，因为 INTERFACE 库是仅头文件的，没有构建产物。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CMake 3.10+ | active | — | — |
| CMake 3.20+ | active | — | — |
| CMake 3.28+ | active | — | — |

## 解决方案

1. ```
   Remove source files from add_library call and use target_sources with INTERFACE scope if needed, or convert to a STATIC library if sources are required.
   ```
2. ```
   Define the target as an OBJECT library if you need to collect object files, then link with other targets.
   ```
3. ```
   Use target_include_directories with INTERFACE scope to propagate headers without sources.
   ```

## 无效尝试

- **Adding SOURCES property via set_property with INTERFACE scope** — The SOURCES property is inherently non-INTERFACE; even setting it as INTERFACE fails because CMake rejects it for INTERFACE libraries. (95% 失败率)
- **Changing library type to STATIC and linking sources** — This changes the library's purpose and may break header-only design, causing unnecessary compilation and link errors. (70% 失败率)
- **Ignoring the error and using add_library with sources anyway** — CMake will abort the configuration; the build cannot proceed without fixing the target definition. (100% 失败率)
