Update CMake configuration and README for build type defaults

This commit is contained in:
2026-05-05 00:03:34 +08:00
parent 56f8fbb701
commit dfd999e665
3 changed files with 19 additions and 6 deletions
+5
View File
@@ -14,6 +14,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the build type." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel)
endif()
if(MSVC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.29)
message(FATAL_ERROR "bitserial requires C++20 support: MSVC 19.29 or newer is required.")
endif()
+7 -3
View File
@@ -112,11 +112,15 @@ benchmarks/baq_bulk_benchmarks.cpp Catch2 BAQ 批量 benchmark
```bash
cmake -S . -B build -DBITSERIAL_BUILD_TESTS=ON -DBITSERIAL_BUILD_BENCHMARKS=ON
cmake --build build --config Release
ctest --test-dir build -C Release --output-on-failure
cmake --build build --config Release --target run_bitserial_benchmarks
cmake --build build
ctest --test-dir build --output-on-failure
cmake --build build --target run_bitserial_benchmarks
```
普通 Ninja / MinGW Makefiles 这类单配置生成器默认使用 Release;Visual Studio /
Ninja Multi-Config 这类多配置生成器需要在 build 和 ctest 时额外传 `--config Release`
或 `-C Release`。
测试和 benchmark 都由 Catch2 组织。benchmark 使用 `[!benchmark]` 标签,因此普通 CTest 不会误跑性能测试。
## 错误处理
+7 -3
View File
@@ -113,11 +113,15 @@ benchmarks/baq_bulk_benchmarks.cpp Catch2 BAQ bulk benchmarks
```bash
cmake -S . -B build -DBITSERIAL_BUILD_TESTS=ON -DBITSERIAL_BUILD_BENCHMARKS=ON
cmake --build build --config Release
ctest --test-dir build -C Release --output-on-failure
cmake --build build --config Release --target run_bitserial_benchmarks
cmake --build build
ctest --test-dir build --output-on-failure
cmake --build build --target run_bitserial_benchmarks
```
Single-config generators such as Ninja and MinGW Makefiles default to Release.
Multi-config generators such as Visual Studio and Ninja Multi-Config need
`--config Release` for build commands and `-C Release` for CTest.
Both tests and benchmarks are organized through Catch2. The benchmark executable
uses the `[!benchmark]` tag, so benchmarks do not run during normal CTest runs.