[Bug]: Abseil ignores user-specified CMAKE_MSVC_RUNTIME_LIBRARY
- Ngôn ngữ chính
- C++
- Star
- 18.1k
- Fork
- 3.2k
- Merge trung bình
- 20 giờ 36 phút
- Pull request đã merge (30 ngày)
- 1
Mô tả
### 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_
Hướng dẫn đóng góp
Hướng nghiên cứu
The issue is in CMakeLists.txt lines 61-68. First, understand how CMake cache variables work and the precedence of FORCE. Look at the existing logic around ABSL_MSVC_STATIC_RUNTIME. The fix likely involves checking if CMAKE_MSVC_RUNTIME_LIBRARY is already set before setting it, or changing the set() to a cache variable. Test by configuring with the provided command and verifying the runtime library flag in the generated build files.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- cmake, cpp
- Lĩnh vực
- build-system
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 65/100