Skip to content

Commit 42847d8

Browse files
committed
[优化日志输出并升级至C++20标准]: 引入C++20格式化库并优化构建配置
- 在Glog示例代码中使用`std::format`增强日志信息可读性 - 升级CMake配置至C++20标准并添加编译器版本兼容性检查 - 设置`CMAKE_CXX_STANDARD 20`及`CMAKE_CXX_EXTENSIONS OFF` - 添加GCC/Clang/MSVC最低版本限制确保C++20支持 - 更新vcpkg基线至`3de032f`以保持依赖项同步 - 为`Glog/main.cc`添加`<format>`标准库头文件引用
1 parent ee4419b commit 42847d8

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

Glog/main.cc

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <glog/logging.h>
22

33
#include <filesystem>
4+
#include <format>
45

56
auto main(int argc, char **argv) -> int
67
{
@@ -23,15 +24,15 @@ auto main(int argc, char **argv) -> int
2324

2425
std::string message("Hello World");
2526

26-
LOG(INFO) << message;
27-
LOG(WARNING) << message;
28-
LOG(ERROR) << message;
29-
// LOG(FATAL) << message;
27+
LOG(INFO) << std::format("{}, This is a info message", message);
28+
LOG(WARNING) << std::format("{}, This is a warning message", message);
29+
LOG(ERROR) << std::format("{}, This is a error message", message);
30+
// LOG(FATAL) << std::format("{}, This is a fatal message", message);
3031

31-
DLOG(INFO) << message;
32-
DLOG(WARNING) << message;
33-
DLOG(ERROR) << message;
34-
// DLOG(FATAL) << message;
32+
DLOG(INFO) << std::format("{}, This is a debug info message", message);
33+
DLOG(WARNING) << std::format("{}, This is a debug warning message", message);
34+
DLOG(ERROR) << std::format("{}, This is a debug error message", message);
35+
// DLOG(FATAL) << std::format("{}, This is a debug fatal message", message);
3536

3637
google::ShutdownGoogleLogging();
3738
return 0;

cmake/common.cmake

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@ if(CMAKE_HOST_APPLE)
44
CACHE STRING "Minimum OS X version")
55
endif()
66

7-
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_CXX_STANDARD 20)
88
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
910
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1011

12+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION
13+
VERSION_LESS 8)
14+
message(FATAL_ERROR "GCC版本需要至少8.0以支持C++20。")
15+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION
16+
VERSION_LESS 10)
17+
message(FATAL_ERROR "Clang版本需要至少10.0以支持C++20。")
18+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND CMAKE_CXX_COMPILER_VERSION
19+
VERSION_LESS 19.28)
20+
message(FATAL_ERROR "MSVC版本需要至少2019 16.10以支持C++20。")
21+
endif()
22+
1123
set(CMAKE_INCLUDE_CURRENT_DIR ON)
1224
set(CMAKE_DEBUG_POSTFIX d)
1325

vcpkg.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
]
2828
}
2929
],
30-
"builtin-baseline": "b545373a9a536dc559dac8583467a21497a0e897"
31-
}
30+
"builtin-baseline": "3de032f834a9b28a455e35600b03e9d365ce3b85"
31+
}

0 commit comments

Comments
 (0)