From dfd999e665cf4d11f6713d98c7dd89509ec35cba Mon Sep 17 00:00:00 2001 From: DawnMagnet Date: Tue, 5 May 2026 00:03:34 +0800 Subject: [PATCH] Update CMake configuration and README for build type defaults --- CMakeLists.txt | 5 +++++ README.cn.md | 10 +++++++--- README.md | 10 +++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d7b1f05..fc8a45a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/README.cn.md b/README.cn.md index 0204923..56eb907 100644 --- a/README.cn.md +++ b/README.cn.md @@ -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 不会误跑性能测试。 ## 错误处理 diff --git a/README.md b/README.md index a3edd89..db8a207 100644 --- a/README.md +++ b/README.md @@ -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.