From 48d8e302a2795944eedf30f441f5ff7ee5eb2c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=8A=E5=B0=91?= Date: Mon, 22 Apr 2024 23:26:40 +0800 Subject: [PATCH 1/2] Fix example and test compiled warnings and error in MSVC. --- src/CMakeLists.txt | 4 +++- test/CMakeLists.txt | 2 ++ test/options.cpp | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3b222e42..2894e13f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,4 +21,6 @@ add_executable(example example.cpp) target_link_libraries(example cxxopts) -set_property(TARGET example PROPERTY CXX_STANDARD 17) +target_compile_features(example PRIVATE cxx_std_17) +target_compile_options(example PRIVATE + "$<$:/utf-8;>") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index db09bca1..1bb8b0d1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,6 +20,7 @@ add_executable(options_test main.cpp options.cpp) target_link_libraries(options_test cxxopts) +target_compile_features(options_test PRIVATE cxx_std_17) add_test(options options_test) # test if the targets are findable from the build directory @@ -51,6 +52,7 @@ add_test(add-subdirectory-test ${CMAKE_CTEST_COMMAND} add_executable(link_test link_a.cpp link_b.cpp) target_link_libraries(link_test cxxopts) +target_compile_features(link_test PRIVATE cxx_std_17) if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") AND ("${CMAKE_SYSTEM}" MATCHES "Linux")) add_executable(fuzzer fuzz.cpp) diff --git a/test/options.cpp b/test/options.cpp index bb90f825..647934c5 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -848,11 +848,11 @@ TEST_CASE("Optional value", "[optional]") CHECK(result.as_optional("int")); CHECK(result.as_optional("float")); - CHECK(result.as_optional("string")); + CHECK(result.as_optional("string")); CHECK(*result.as_optional("int") == 42); CHECK(*result.as_optional("float") == 3.141); - CHECK(*result.as_optional("string") == "Hello"); + CHECK(*result.as_optional("string") == "Hello"); } SECTION("Unavailable") { @@ -866,7 +866,7 @@ TEST_CASE("Optional value", "[optional]") CHECK(!result.as_optional("int")); CHECK(!result.as_optional("float")); - CHECK(!result.as_optional("string")); + CHECK(!result.as_optional("string")); } } From 983df15f34a7edea16b4a74519af3e90101da5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=8A=E5=B0=91?= Date: Fri, 26 Apr 2024 23:36:50 +0800 Subject: [PATCH 2/2] Remove two tests cxx_std_17 compile features. --- test/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1bb8b0d1..db09bca1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,7 +20,6 @@ add_executable(options_test main.cpp options.cpp) target_link_libraries(options_test cxxopts) -target_compile_features(options_test PRIVATE cxx_std_17) add_test(options options_test) # test if the targets are findable from the build directory @@ -52,7 +51,6 @@ add_test(add-subdirectory-test ${CMAKE_CTEST_COMMAND} add_executable(link_test link_a.cpp link_b.cpp) target_link_libraries(link_test cxxopts) -target_compile_features(link_test PRIVATE cxx_std_17) if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") AND ("${CMAKE_SYSTEM}" MATCHES "Linux")) add_executable(fuzzer fuzz.cpp)