diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 1006df1..b3f2d2c 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,18 +1,23 @@ include(CheckCXXCompilerFlag) -set(OPTIONS "") - 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) - set(OPTIONS ${OPTIONS} -std=c++17) + set(OPTIONS -Wall -Wextra -pedantic-errors -Werror -std=c++17) elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - set(OPTIONS /W4 /WX) - check_cxx_compiler_flag(/permissive HAS_PERMISSIVE_FLAG) + 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) if(HAS_PERMISSIVE_FLAG) set(OPTIONS ${OPTIONS} /permissive-) endif() - set(OPTIONS ${OPTIONS} /std:c++17) endif() add_executable(example diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0072d15..a3cca5f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,8 +2,6 @@ set(SOURCES test.cpp) -set(OPTIONS "") - if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") set(OPTIONS /W4 /WX) check_cxx_compiler_flag(/permissive HAS_PERMISSIVE_FLAG) @@ -22,7 +20,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") check_cxx_compiler_flag(-std=c++20 HAS_CPP20_FLAG) endif() -function(make_target target std) +function(make_test target std) add_executable(${target} ${SOURCES}) target_compile_options(${target} PRIVATE ${OPTIONS}) target_include_directories(${target} PRIVATE 3rdparty/Catch2) @@ -34,14 +32,13 @@ function(make_target target std) target_compile_options(${target} PRIVATE -std=${std}) endif() endif() + add_test(NAME ${target} COMMAND ${target}) endfunction() if(HAS_CPP17_FLAG) - make_target(${CMAKE_PROJECT_NAME}-cpp17.t c++17) - add_test(NAME ${CMAKE_PROJECT_NAME}-cpp17.t COMMAND ${CMAKE_PROJECT_NAME}-cpp17.t) + make_test(${CMAKE_PROJECT_NAME}-cpp17.t c++17) endif() if(HAS_CPPLATEST_FLAG) - make_target(${CMAKE_PROJECT_NAME}-cpplatest.t c++latest) - add_test(NAME ${CMAKE_PROJECT_NAME}-cpplatest.t COMMAND ${CMAKE_PROJECT_NAME}-cpplatest.t) + make_test(${CMAKE_PROJECT_NAME}-cpplatest.t c++latest) endif()