[Bug]: Abseil ignores user-specified CMAKE_MSVC_RUNTIME_LIBRARY
- 主要语言
- C++
- 星标
- 18.1k
- 派生
- 3.2k
- 平均合并
- 20 小时 36 分钟
- 30 天内合并 PR
- 1
描述
### Describe the issue
When providing `CMAKE_MSVC_RUNTIME_LIBRARY` either on the CLI or as a cache variable before adding Abseil as a sub project, it has no effect.
This is because Abseil forcibly sets the value of these variables here:
https://github.com/abseil/abseil-cpp/blob/cb9a36d737ceaca2bdb1bc62a20b43ed42ec0ae2/CMakeLists.txt#L61-L68
These should either be changed to cache variables (which always cede to an existing cache variable if one is present, unless using `FORCE` or `INTERNAL`), or the logic should be switched to not run if `CMAKE_MSVC_RUNTIME_LIBRARY` is already defined.
This is semi-mitigated by `ABSL_MSVC_STATIC_RUNTIME` but only if the user intends to use one of Abseil's permutations derived from that variable, so it isn't as flexible.
### Steps to reproduce the problem
Configure abseil via `cmake -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_BUILD_TYPE=Debug -GNinja`.
Observe that any created object files expect to be linked against the debug msvc runtime library, ignoring the user-provided value.
### What version of Abseil are you using?
cb9a36d737ceaca2bdb1bc62a20b43ed42ec0ae2
### What operating system and version are you using?
Windows 11
### What compiler and version are you using?
MSVC 17.14
### What build system are you using?
CMake 3.31
### Additional context
_No response_
贡献指南
调研方向
问题位于 CMakeLists.txt 的第 61-68 行。首先,了解 CMake 缓存变量的工作方式以及 FORCE 的优先级。查看 ABSL_MSVC_STATIC_RUNTIME 周围现有的逻辑。修复可能需要在设置 CMAKE_MSVC_RUNTIME_LIBRARY 之前检查它是否已经设置,或者将 set() 改为缓存变量。使用提供的命令进行配置,并验证生成的构建文件中的运行时库标志,以进行测试。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- cmake, cpp
- 领域
- build-system
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 65/100