diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2bf07dd..d1a56a3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,12 +4,25 @@ enable_testing() include(CheckCXXSourceCompiles) +# report an updated value for recent C++ language standards support. By +# default, Visual Studio always returns the value "199711L" for the +# __cplusplus preprocessor macro. +if(MSVC) + string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus") +endif() + set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") -set(CMAKE_REQUIRED_FLAGS -std=c++17) +if(MSVC) + set(CMAKE_REQUIRED_FLAGS /std:c++17) +else() + set(CMAKE_REQUIRED_FLAGS -std=c++17) +endif() + check_cxx_source_compiles(" #include #include int main() { return std::is_same_v; }" CAN_COMPILE_17) + set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}") if (EXISTS ${CMAKE_BINARY_DIR}/conan_paths.cmake) @@ -22,7 +35,7 @@ find_package(Catch2 REQUIRED) if (CAN_COMPILE_17) add_executable(wise_enum_test test_main.cpp cxx17.cpp) target_compile_features(wise_enum_test PRIVATE cxx_std_17) - target_include_directories(wise_enum_test PRIVATE ..) + target_include_directories(wise_enum_test PRIVATE ${CMAKE_CURRENT_LIST_DIR}/..) else () add_executable(wise_enum_test test_main.cpp) endif () @@ -31,7 +44,7 @@ target_link_libraries(wise_enum_test PRIVATE Catch2::Catch2) add_executable(wise_enum_test14 test_main.cpp cxx14.cpp) target_compile_features(wise_enum_test14 PRIVATE cxx_std_14) target_link_libraries(wise_enum_test14 PRIVATE Catch2::Catch2) -target_include_directories(wise_enum_test14 PRIVATE ..) +target_include_directories(wise_enum_test14 PRIVATE ${CMAKE_CURRENT_LIST_DIR}/..) add_test(NAME wise_enum.unit_tests COMMAND wise_enum_test) add_test(NAME wise_enum.unit_tests14 COMMAND wise_enum_test14)