Skip to content

Commit 93d37ec

Browse files
committed
Refactor CMakeLists.txt to streamline C++20 support checks for MSVC and improve readability
1 parent ff34f68 commit 93d37ec

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

test/CMakeLists.txt

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,24 @@ target_link_libraries(httplib-test PRIVATE httplib GTest::gtest_main CURL::libcu
3232
gtest_discover_tests(httplib-test)
3333

3434
# C++20 streaming API tests
35-
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang|MSVC")
36-
# Check for C++20 support using CMake's compile features
37-
# This is more reliable than checking compiler flags
38-
if(MSVC)
39-
# MSVC 19.29+ (VS 2019 16.10+) supports C++20 coroutines
40-
if(MSVC_VERSION GREATER_EQUAL 1929)
41-
set(COMPILER_SUPPORTS_CXX20 TRUE)
42-
else()
43-
set(COMPILER_SUPPORTS_CXX20 FALSE)
44-
endif()
45-
else()
46-
include(CheckCXXCompilerFlag)
47-
check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20)
35+
if(MSVC)
36+
# MSVC 19.29+ (VS 2019 16.10+) supports C++20 coroutines
37+
if(MSVC_VERSION GREATER_EQUAL 1929)
38+
set(COMPILER_SUPPORTS_CXX20 TRUE)
4839
endif()
40+
else()
41+
include(CheckCXXCompilerFlag)
42+
check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20)
43+
endif()
4944

50-
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}, MSVC_VERSION: ${MSVC_VERSION}")
51-
message(STATUS "C++20 support: ${COMPILER_SUPPORTS_CXX20}")
52-
53-
if(COMPILER_SUPPORTS_CXX20)
54-
add_executable(httplib-test-stream test-stream.cc)
55-
target_compile_features(httplib-test-stream PRIVATE cxx_std_20)
56-
target_compile_options(httplib-test-stream PRIVATE
57-
"$<$<CXX_COMPILER_ID:MSVC>:/utf-8;/bigobj>"
58-
)
59-
target_link_libraries(httplib-test-stream PRIVATE httplib GTest::gtest_main)
60-
gtest_discover_tests(httplib-test-stream DISCOVERY_TIMEOUT 60)
61-
message(STATUS "Building httplib-test-stream (C++20 streaming tests)")
62-
else()
63-
message(STATUS "C++20 not supported, skipping test-stream")
64-
endif()
45+
if(COMPILER_SUPPORTS_CXX20)
46+
add_executable(httplib-test-stream test-stream.cc)
47+
target_compile_features(httplib-test-stream PRIVATE cxx_std_20)
48+
target_compile_options(httplib-test-stream PRIVATE
49+
"$<$<CXX_COMPILER_ID:MSVC>:/utf-8;/bigobj>"
50+
)
51+
target_link_libraries(httplib-test-stream PRIVATE httplib GTest::gtest_main)
52+
gtest_discover_tests(httplib-test-stream)
6553
endif()
6654

6755
file(

0 commit comments

Comments
 (0)