diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index b3f2d2c..3c2a934 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,27 +1,16 @@ include(CheckCXXCompilerFlag) if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) - check_cxx_compiler_flag(-std=c++17 HAS_CPP17_FLAG) - if(!HAS_CPP17_FLAG) - MESSAGE(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support.") - endif() - - set(CMAKE_VERBOSE_MAKEFILE ON) - set(OPTIONS -Wall -Wextra -pedantic-errors -Werror -std=c++17) + set(OPTIONS -Wall -Wextra -pedantic-errors -Werror) elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - check_cxx_compiler_flag(/std:c++17 HAS_CPP17_FLAG) - if(!HAS_CPP17_FLAG) - MESSAGE(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support.") - endif() - - set(OPTIONS /W4 /WX /std:c++17) + set(OPTIONS /W4 /WX) if(HAS_PERMISSIVE_FLAG) set(OPTIONS ${OPTIONS} /permissive-) endif() endif() -add_executable(example - example.cpp - ${CMAKE_SOURCE_DIR}/include/${CMAKE_PROJECT_NAME}.hpp) +add_executable(example example.cpp) +set_target_properties(example PROPERTIES CXX_EXTENSIONS OFF) +target_compile_features(example PRIVATE cxx_std_17) target_compile_options(example PRIVATE ${OPTIONS}) target_link_libraries(example PRIVATE ${CMAKE_PROJECT_NAME}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a3cca5f..8be3ef8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,14 +9,12 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") set(OPTIONS ${OPTIONS} /permissive-) endif() - check_cxx_compiler_flag(/std:c++17 HAS_CPP17_FLAG) check_cxx_compiler_flag(/std:c++20 HAS_CPP20_FLAG) check_cxx_compiler_flag(/std:c++latest HAS_CPPLATEST_FLAG) elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") set(CMAKE_VERBOSE_MAKEFILE ON) set(OPTIONS -Wall -Wextra -pedantic-errors -Werror) - check_cxx_compiler_flag(-std=c++17 HAS_CPP17_FLAG) check_cxx_compiler_flag(-std=c++20 HAS_CPP20_FLAG) endif() @@ -25,6 +23,7 @@ function(make_test target std) target_compile_options(${target} PRIVATE ${OPTIONS}) target_include_directories(${target} PRIVATE 3rdparty/Catch2) target_link_libraries(${target} PRIVATE ${CMAKE_PROJECT_NAME}) + set_target_properties(${target} PROPERTIES CXX_EXTENSIONS OFF) if(std) if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") target_compile_options(${target} PRIVATE /std:${std}) @@ -35,8 +34,10 @@ function(make_test target std) add_test(NAME ${target} COMMAND ${target}) endfunction() -if(HAS_CPP17_FLAG) - make_test(${CMAKE_PROJECT_NAME}-cpp17.t c++17) +make_test(${CMAKE_PROJECT_NAME}-cpp17.t c++17) + +if(HAS_CPP20_FLAG) + make_test(${CMAKE_PROJECT_NAME}-cpp20.t c++20) endif() if(HAS_CPPLATEST_FLAG)